文件
hyb-oa/client/src/api/auth.ts
T
wangsli 410d8cd71b
ci-e2e / e2e (push) Canceled after 0s
ci-minimal / check-minimal (push) Canceled after 0s
实现企微原生材料预览(07-27-yang-jun-reimbursement-readiness)
2026-07-31 18:57:34 +08:00

136 行
3.7 KiB
TypeScript

import { apiRequestData } from "./http";
import { getDeviceFingerprint } from "../auth/deviceFingerprint";
import type { LoginResponse } from "./types";
const JSON_HEADERS = {
"content-type": "application/json",
};
export async function changePassword(payload: { oldPassword: string; newPassword: string }) {
return apiRequestData<LoginResponse>("/api/auth/change-password", {
method: "POST",
headers: {
...JSON_HEADERS,
"x-device-fingerprint": getDeviceFingerprint(),
},
body: JSON.stringify(payload),
});
}
export async function forgotPassword(payload: { email: string }) {
return apiRequestData<Record<string, never>>("/api/auth/forgot-password", {
method: "POST",
auth: false,
headers: JSON_HEADERS,
body: JSON.stringify(payload),
});
}
export async function resetPassword(payload: { email: string; code: string; newPassword: string }) {
return apiRequestData<Record<string, never>>("/api/auth/reset-password", {
method: "POST",
auth: false,
headers: JSON_HEADERS,
body: JSON.stringify(payload),
});
}
export async function requestEmailLoginCode(payload: { email: string }) {
return apiRequestData<Record<string, never>>("/api/auth/email-login/code", {
method: "POST",
auth: false,
headers: JSON_HEADERS,
body: JSON.stringify(payload),
});
}
export async function verifyEmailLoginCode(payload: { email: string; code: string }) {
return apiRequestData<LoginResponse>("/api/auth/email-login/verify", {
method: "POST",
auth: false,
retryOn401: false,
headers: {
...JSON_HEADERS,
"x-device-fingerprint": getDeviceFingerprint(),
},
body: JSON.stringify(payload),
});
}
export type AuthCapabilities = {
emailDelivery: {
ready: boolean;
statusReasons: string[];
};
emailLoginCode: {
enabled: boolean;
};
passwordReset: {
enabled: boolean;
};
};
export type SsoProviderInfo = { id: "oidc"; label: string; enabled: boolean; loginUrl: string };
export type WecomEntryConfig = {
enabled: boolean;
entryEnabled: boolean;
oauthEnabled: boolean;
corpId: string;
agentId: string;
loginUrl: string | null;
pcWebLoginEnabled: boolean;
pcLoginUrl: string | null;
bindEnabled: boolean;
defaultReturnTo: string;
status: "ready" | "disabled" | "misconfigured";
statusReasons: string[];
};
export async function fetchSsoProviders() {
return apiRequestData<SsoProviderInfo[]>("/api/auth/sso/providers", { auth: false });
}
export async function fetchAuthCapabilities() {
return apiRequestData<AuthCapabilities>("/api/auth/capabilities", { auth: false });
}
export async function fetchWecomConfig() {
return apiRequestData<WecomEntryConfig>("/api/auth/wecom/config", { auth: false });
}
export type WecomJsSdkSignature = {
corpId: string;
timestamp: number;
nonceStr: string;
signature: string;
};
export async function fetchWecomJsSdkSignature(url: string) {
return apiRequestData<WecomJsSdkSignature>("/api/auth/wecom/js-sdk-signature", {
method: "POST",
body: JSON.stringify({ url }),
});
}
export async function startWecomBind(returnTo = "/settings/profile") {
return apiRequestData<{ loginUrl: string }>("/api/auth/wecom/bind", {
method: "POST",
body: JSON.stringify({ returnTo }),
});
}
export async function unbindWecom() {
return apiRequestData<{ ok: boolean }>("/api/auth/wecom/unbind", {
method: "POST",
body: JSON.stringify({}),
});
}
export async function updateNotificationPreferences(payload: { notificationPushEnabled: boolean }) {
return apiRequestData<{ notificationPushEnabled: boolean }>("/api/me/notification-preferences", {
method: "PATCH",
body: JSON.stringify(payload),
});
}