Jakub Kaniecki 12c76e3e5a init
2025-05-18 16:23:03 +02:00

38 lines
947 B
TypeScript

import axios from 'axios';
const API_URL = 'http://localhost:8000/api/users';
export interface RegisterData {
username: string;
password: string;
password2: string;
email: string;
first_name: string;
last_name: string;
role?: 'admin' | 'user' | 'moderator';
}
export interface LoginData {
username: string;
password: string;
}
export interface AuthResponse {
access: string;
refresh: string;
}
export const register = async (data: RegisterData): Promise<{ message: string }> => {
const response = await axios.post(`${API_URL}/register/`, data);
return response.data;
};
export const login = async (data: LoginData): Promise<AuthResponse> => {
const response = await axios.post(`${API_URL}/login/`, data);
return response.data;
};
export const refreshToken = async (refresh: string): Promise<AuthResponse> => {
const response = await axios.post(`${API_URL}/refresh/`, { refresh });
return response.data;
};