fix(workbench): complete profile and channel flows

This commit is contained in:
2026-07-24 14:46:38 +08:00
parent d7eb20a85f
commit f430566976
21 changed files with 563 additions and 151 deletions

View File

@@ -3,6 +3,11 @@ export type ApiSession = {
token: string
}
export type CurrentUser = {
email: string
displayName: string
}
type RequestOptions = {
method?: string
body?: unknown
@@ -40,12 +45,19 @@ export function getApiBaseUrl() {
return configuredBaseUrl
}
export async function login(email: string, password: string): Promise<ApiSession> {
const response = await apiRequest<{ token: string }>('/api/v1/auth/login', {
export async function login(email: string, password: string): Promise<ApiSession & { user: CurrentUser }> {
const response = await apiRequest<{ token: string; user: CurrentUser }>('/api/v1/auth/login', {
method: 'POST',
body: { email, password },
})
return { baseUrl: configuredBaseUrl, token: response.token }
return { baseUrl: configuredBaseUrl, token: response.token, user: response.user }
}
export function updateCurrentUser(
session: ApiSession,
input: { displayName: string; currentPassword?: string; newPassword?: string },
) {
return apiRequest<CurrentUser>('/api/v1/auth/me', { method: 'PATCH', token: session.token, body: input })
}
export async function apiRequest<T>(path: string, options: RequestOptions = {}): Promise<T> {