test: add client services
This commit is contained in:
22
client/src/services/auth.ts
Normal file
22
client/src/services/auth.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import api from '../api/api';
|
||||
import { useUserStore } from '../store/user';
|
||||
import { Auth } from '../types/auth';
|
||||
|
||||
export class AuthService {
|
||||
static async login(auth: Auth) {
|
||||
const token = await api.login(auth);
|
||||
console.log(token)
|
||||
localStorage.setItem('accessToken', token.accessToken);
|
||||
}
|
||||
|
||||
static async logout() {
|
||||
useUserStore.getState().removeUser();
|
||||
localStorage.removeItem('userInfo');
|
||||
localStorage.removeItem('accessToken');
|
||||
}
|
||||
|
||||
static async refresh() {
|
||||
const token = await api.refreshToken();
|
||||
localStorage.setItem('accessToken', token.accessToken);
|
||||
}
|
||||
}
|
10
client/src/services/user.ts
Normal file
10
client/src/services/user.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import api from '../api/api';
|
||||
import { User } from '../types/user';
|
||||
|
||||
export class UserService {
|
||||
static async getProfile(): Promise<User> {
|
||||
const user = api.getProfile();
|
||||
|
||||
return user;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user