feat: add AccountPage for user account management and API token handling; update AppRoutes to include new route

This commit is contained in:
JSC
2025-08-09 23:43:30 +02:00
parent 936d48fbb9
commit f2772c392c
5 changed files with 733 additions and 1 deletions

View File

@@ -29,6 +29,8 @@ export const API_CONFIG = {
OAUTH_AUTHORIZE: (provider: string) => `/api/v1/auth/${provider}/authorize`,
OAUTH_CALLBACK: (provider: string) => `/api/v1/auth/${provider}/callback`,
EXCHANGE_OAUTH_TOKEN: '/api/v1/auth/exchange-oauth-token',
API_TOKEN: '/api/v1/auth/api-token',
API_TOKEN_STATUS: '/api/v1/auth/api-token/status',
},
},
} as const

View File

@@ -36,6 +36,36 @@ export interface ExchangeOAuthTokenResponse {
user_id: string
}
export interface ApiTokenRequest {
expires_days?: number
}
export interface ApiTokenResponse {
api_token: string
expires_at?: string
}
export interface ApiTokenStatusResponse {
has_token: boolean
expires_at?: string
is_expired: boolean
}
export interface UpdateProfileRequest {
name?: string
}
export interface ChangePasswordRequest {
current_password?: string
new_password: string
}
export interface UserProvider {
provider: string
display_name: string
connected_at?: string
}
export class AuthService {
/**
* Authenticate user with email and password
@@ -150,6 +180,48 @@ export class AuthService {
throw new Error('Token refresh failed')
}
}
/**
* Update user profile information
*/
async updateProfile(data: UpdateProfileRequest): Promise<User> {
return apiClient.patch<User>(API_CONFIG.ENDPOINTS.AUTH.ME, data)
}
/**
* Change user password
*/
async changePassword(data: ChangePasswordRequest): Promise<void> {
return apiClient.post<void>('/api/v1/auth/change-password', data)
}
/**
* Generate a new API token
*/
async generateApiToken(request: ApiTokenRequest = {}): Promise<ApiTokenResponse> {
return apiClient.post<ApiTokenResponse>(API_CONFIG.ENDPOINTS.AUTH.API_TOKEN, request)
}
/**
* Get API token status
*/
async getApiTokenStatus(): Promise<ApiTokenStatusResponse> {
return apiClient.get<ApiTokenStatusResponse>(API_CONFIG.ENDPOINTS.AUTH.API_TOKEN_STATUS)
}
/**
* Delete API token
*/
async deleteApiToken(): Promise<void> {
return apiClient.delete<void>(API_CONFIG.ENDPOINTS.AUTH.API_TOKEN)
}
/**
* Get user's connected authentication providers
*/
async getUserProviders(): Promise<UserProvider[]> {
return apiClient.get<UserProvider[]>('/api/v1/auth/user-providers')
}
}
export const authService = new AuthService()