fix(workbench): complete profile and channel flows
This commit is contained in:
@@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user