add refresh tokens on client
All checks were successful
Build and Deploy Frontend / build-and-deploy (push) Successful in 7s
All checks were successful
Build and Deploy Frontend / build-and-deploy (push) Successful in 7s
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// service to interact with the api/auth endpoints
|
||||
// handles user registration, user logins, tokens, password reset, etc.
|
||||
|
||||
import api from "./axios.ts"
|
||||
import { api, authStorage } from "./axios.ts"
|
||||
import type { User, RegisterDto, LoginDto } from "../models/User.ts";
|
||||
|
||||
const API_URL: string = "/auth";
|
||||
@@ -10,9 +10,8 @@ const API_URL: string = "/auth";
|
||||
export const register = async (user: RegisterDto) => {
|
||||
|
||||
try {
|
||||
console.log(user);
|
||||
|
||||
// TODO: if valid
|
||||
const response = await api.post(`${API_URL}/register`, user);
|
||||
|
||||
return true;
|
||||
|
||||
@@ -28,9 +27,7 @@ export const login = async (user: LoginDto ) => {
|
||||
|
||||
try {
|
||||
const response = await api.post(`${API_URL}/login`, user);
|
||||
const token = response.data.token;
|
||||
|
||||
localStorage.setItem("token", token);
|
||||
localStorage.setTokens(response.data);
|
||||
|
||||
return true;
|
||||
|
||||
@@ -41,9 +38,9 @@ export const login = async (user: LoginDto ) => {
|
||||
}
|
||||
|
||||
export const logout = () => {
|
||||
localStorage.removeItem("token");
|
||||
authStorage.clear();
|
||||
}
|
||||
|
||||
export const getToken = () => {
|
||||
return localStorage.getItem("token");
|
||||
authStorage.getAccessToken();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user