Ajoute le flux d'invitation avec activation de compte
This commit is contained in:
@@ -23,6 +23,12 @@ type PasswordResetValidationPayload = {
|
||||
error?: string;
|
||||
};
|
||||
|
||||
type AccountInviteValidationPayload = {
|
||||
email?: string;
|
||||
name?: string | null;
|
||||
error?: string;
|
||||
};
|
||||
|
||||
type JsonErrorPayload = {
|
||||
error?: string;
|
||||
};
|
||||
@@ -131,6 +137,30 @@ export function createAuthClient(options: CreateAuthClientOptions) {
|
||||
}
|
||||
},
|
||||
|
||||
async validateAccountInviteToken(token: string): Promise<{ email: string; name: string | null }> {
|
||||
const response = await request(`/api/auth/invite/validate?token=${encodeURIComponent(token)}`, {
|
||||
headers: {}
|
||||
});
|
||||
const payload = (await response.json().catch(() => null)) as AccountInviteValidationPayload | null;
|
||||
if (!response.ok || !payload?.email) {
|
||||
throw new Error(payload?.error ?? "Invalid invite link");
|
||||
}
|
||||
return {
|
||||
email: payload.email,
|
||||
name: payload.name ?? null
|
||||
};
|
||||
},
|
||||
|
||||
async acceptAccountInvite(input: { token: string; name: string; password: string }): Promise<void> {
|
||||
const response = await request("/api/auth/invite/accept", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(input)
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw await readJsonError(response, "Invalid invite link");
|
||||
}
|
||||
},
|
||||
|
||||
async logout(): Promise<void> {
|
||||
const response = await request("/api/auth/logout", {
|
||||
method: "POST"
|
||||
|
||||
Reference in New Issue
Block a user