Files
agologum/client/src/api/AuthApi.ts
Blitblank f271ff59f8
All checks were successful
Build and Deploy Frontend / build-and-deploy (push) Successful in 7s
Build and Deploy API / build-and-deploy (push) Successful in 10s
added userDtos
2026-03-28 00:01:45 -05:00

47 lines
825 B
TypeScript

// service to interact with the api/auth endpoints
// handles user registration, user logins, tokens, password reset, etc.
import { api, authStorage } from "./axios.ts"
import type { UserDto, RegisterDto, LoginDto } from "../models/User.ts";
const API_URL: string = "/auth";
export const register = async (user: RegisterDto) => {
try {
const response = await api.post(`${API_URL}/register`, user);
return true;
// else return false
} catch (err) {
return false;
}
}
export const login = async (user: LoginDto ) => {
try {
const response = await api.post(`${API_URL}/login`, user);
authStorage.setTokens(response.data);
return true;
} catch (err) {
return false;
}
}
export const logout = () => {
authStorage.clear();
}
export const getToken = () => {
authStorage.getAccessToken();
}