feat: add auth API service with TypeScript interfaces
This commit is contained in:
@@ -0,0 +1,44 @@
|
|||||||
|
import request from '@/utils/request'
|
||||||
|
|
||||||
|
export interface LoginRequest {
|
||||||
|
username: string
|
||||||
|
password: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface LoginResponse {
|
||||||
|
token: string
|
||||||
|
user: UserInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UserInfo {
|
||||||
|
id: number
|
||||||
|
username: string
|
||||||
|
nickname: string
|
||||||
|
email: string
|
||||||
|
phone: string
|
||||||
|
avatar: string
|
||||||
|
roles: string[]
|
||||||
|
permissions: string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UpdatePasswordRequest {
|
||||||
|
oldPassword: string
|
||||||
|
newPassword: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export const authApi = {
|
||||||
|
login: (data: LoginRequest) =>
|
||||||
|
request.post<LoginResponse>('/auth/login', data),
|
||||||
|
|
||||||
|
logout: () =>
|
||||||
|
request.post<void>('/auth/logout'),
|
||||||
|
|
||||||
|
getCurrentUser: () =>
|
||||||
|
request.get<UserInfo>('/auth/current'),
|
||||||
|
|
||||||
|
updatePassword: (data: UpdatePasswordRequest) =>
|
||||||
|
request.put<void>('/auth/password', data),
|
||||||
|
|
||||||
|
refreshToken: () =>
|
||||||
|
request.post<LoginResponse>('/auth/refresh'),
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user