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;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										6
									
								
								package-lock.json
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								package-lock.json
									
									
									
										generated
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
{
 | 
			
		||||
  "name": "connect",
 | 
			
		||||
  "lockfileVersion": 3,
 | 
			
		||||
  "requires": true,
 | 
			
		||||
  "packages": {}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										1
									
								
								package.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								package.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
			
		||||
{}
 | 
			
		||||
		Reference in New Issue
	
	Block a user