Phase D
This commit is contained in:
@@ -48,8 +48,23 @@ export interface CurrentUser {
|
||||
username: string;
|
||||
displayName?: string | null;
|
||||
emailVerifiedAt?: string | null;
|
||||
emailVerified?: boolean;
|
||||
roles?: string[];
|
||||
twoFactorEnabled?: boolean;
|
||||
impersonation?: {
|
||||
isImpersonation: boolean;
|
||||
label?: string;
|
||||
impersonatorLabel?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface MeResponse {
|
||||
user: CurrentUser;
|
||||
impersonation?: {
|
||||
isImpersonation: boolean;
|
||||
impersonatorLabel?: string;
|
||||
label?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface TwoFactorSetupResponse {
|
||||
@@ -149,8 +164,30 @@ export async function submitLogout(): Promise<void> {
|
||||
});
|
||||
}
|
||||
|
||||
export async function getCurrentUser(): Promise<CurrentUser> {
|
||||
return apiFetch<CurrentUser>("/me");
|
||||
export async function getCurrentUser(): Promise<CurrentUser | null> {
|
||||
try {
|
||||
const response = await apiFetch<MeResponse>("/me");
|
||||
return {
|
||||
...response.user,
|
||||
impersonation: response.impersonation
|
||||
? {
|
||||
isImpersonation: response.impersonation.isImpersonation,
|
||||
label:
|
||||
response.impersonation.label ??
|
||||
response.impersonation.impersonatorLabel,
|
||||
}
|
||||
: undefined,
|
||||
};
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function consumeSsoTicket(ticket: string): Promise<{ redirectPath: string }> {
|
||||
return apiFetch<{ redirectPath: string }>("/auth/sso/consume", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ ticket }),
|
||||
});
|
||||
}
|
||||
|
||||
export async function verifyEmail(token: string): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user