Files
Genarrative/packages/shared/src/contracts/auth.ts
T
k88936 44748b7846
Project CI / Frontend tests (push) Successful in 34s
Project CI / Backend tests (push) Failing after 39s
Project CI / Repository checks (push) Successful in 52s
Project CI / Native shell tests (push) Successful in 2m4s
fix:前后端校验手机号区域码 (#104)
来自今早群友反映
before:
![shotmd-1784692399.jpg](/attachments/3ab36252-78f4-44e2-bb51-fca84badc79e)
and failed
after:
![shotmd-1784702966.jpg](/attachments/3eea7ec9-8aca-43f6-a675-1316162619d4)
![shotmd-1784702843.jpg](/attachments/29182a41-26cf-4954-be16-de060d844d9c)
![shotmd-1784787134.jpg](/attachments/c04a1981-c6bf-4a26-b5ad-d2af51d74a29)

* https://developers.weixin.qq.com/miniprogram/dev/server/API/user-info/phone-number/api_getphonenumber.html#Res-phone-info-Object-Payload 参考微信这个文档修改了微信返回的struct 手机号 区域码字段不应是Optional

* 登录注册改密码改绑定等 api 把单一 phone字段改成 country_code(可选,缺省为86) + pure_phone_number 分别进行了前后端校验

Reviewed-on: https://git.genarrative.world/git/GenarrativeAI/Genarrative/pulls/104
Co-authored-by: 王德宇 <kvtodev@outlook.com>
Co-committed-by: 王德宇 <kvtodev@outlook.com>
2026-07-23 14:52:57 +08:00

235 lines
4.6 KiB
TypeScript

export type AuthBindingStatus = 'active' | 'pending_bind_phone';
export type AuthLoginMethod = 'password' | 'phone' | 'wechat';
export type AuthUser = {
id: string;
publicUserCode: string;
displayName: string;
avatarUrl: string | null;
phoneNumber?: string | null;
phoneNumberMasked: string | null;
loginMethod: AuthLoginMethod;
bindingStatus: AuthBindingStatus;
wechatBound: boolean;
wechatDisplayName?: string | null;
wechatAccount?: string | null;
};
export type PublicUserSummary = {
id: string;
publicUserCode: string;
username: string;
displayName: string;
avatarUrl: string | null;
};
export type PublicUserSearchResponse = {
user: PublicUserSummary;
};
export type AuthPhoneNumberInput = {
countryCode?: string;
purePhoneNumber: string;
};
export type AuthEntryRequest = AuthPhoneNumberInput & {
password: string;
};
export type AuthEntryResponse = {
token: string;
user: AuthUser;
};
export type AuthPasswordChangeRequest = {
currentPassword?: string;
newPassword: string;
};
export type AuthPasswordChangeResponse = {
user: AuthUser;
};
export type AuthProfileUpdateRequest = {
displayName?: string;
avatarDataUrl?: string;
};
export type AuthProfileUpdateResponse = {
user: AuthUser;
};
export type AuthPasswordResetRequest = AuthPhoneNumberInput & {
code: string;
newPassword: string;
};
export type AuthPasswordResetResponse = {
token: string;
user: AuthUser;
};
export type AuthPhoneSendCodeRequest = AuthPhoneNumberInput & {
scene?: 'login' | 'bind_phone' | 'change_phone' | 'reset_password';
captchaChallengeId?: string;
captchaAnswer?: string;
};
export type AuthPhoneSendCodeResponse = {
ok: true;
cooldownSeconds: number;
expiresInSeconds: number;
providerRequestId: string | null;
};
export type AuthPhoneLoginRequest = AuthPhoneNumberInput & {
code: string;
inviteCode?: string;
};
export type AuthPhoneLoginResponse = {
token: string;
user: AuthUser;
created: boolean;
referral: AuthPhoneLoginReferral | null;
};
export type AuthPhoneLoginReferral = {
ok: boolean;
message: string | null;
inviteeRewardGranted: boolean;
inviterRewardGranted: boolean;
inviteeBalanceAfter: number | null;
inviterBalanceAfter: number | null;
};
export type AuthMeResponse = {
user: AuthUser | null;
availableLoginMethods: AuthLoginMethod[];
};
export type AuthLoginOptionsResponse = {
availableLoginMethods: AuthLoginMethod[];
};
export type AuthWechatStartResponse = {
authorizationUrl: string;
};
export type AuthWechatBindPhoneRequest = {
countryCode?: string;
purePhoneNumber?: string;
code?: string;
wechatPhoneCode?: string;
displayName?: string;
};
export type AuthWechatBindPhoneResponse = {
token: string;
user: AuthUser;
};
export type AuthWechatMiniProgramLoginRequest = {
code: string;
displayName?: string;
};
export type AuthWechatMiniProgramLoginResponse = {
token: string;
bindingStatus: AuthBindingStatus;
user: AuthUser;
created: boolean;
};
export type AuthPhoneChangeRequest = AuthPhoneNumberInput & {
code: string;
};
export type AuthPhoneChangeResponse = {
user: AuthUser;
};
export type AuthRefreshResponse = {
token: string;
};
export type AuthSessionSummary = {
sessionId: string;
sessionIds: string[];
sessionCount: number;
clientLabel: string;
ipMasked: string | null;
isCurrent: boolean;
createdAt: string;
lastSeenAt: string;
expiresAt: string;
};
export type AuthSessionsResponse = {
sessions: AuthSessionSummary[];
};
export type AuthLogoutAllResponse = {
ok: true;
};
export type AuthRevokeSessionResponse = {
ok: true;
};
export type AuthAuditLogEventType =
| 'password_login'
| 'phone_login'
| 'wechat_login'
| 'wechat_bind_phone'
| 'change_phone'
| 'captcha_required'
| 'logout'
| 'logout_all'
| 'revoke_session'
| 'risk_block_phone'
| 'risk_block_ip'
| 'risk_unblock_phone'
| 'risk_unblock_ip';
export type AuthAuditLogEntry = {
id: string;
eventType: AuthAuditLogEventType;
title: string;
detail: string;
ipMasked: string | null;
userAgent: string | null;
createdAt: string;
};
export type AuthAuditLogsResponse = {
logs: AuthAuditLogEntry[];
};
export type AuthCaptchaChallenge = {
challengeId: string;
promptText: string;
imageDataUrl: string;
expiresInSeconds: number;
};
export type AuthRiskBlockSummary = {
scopeType: 'phone' | 'ip';
title: string;
detail: string;
expiresAt: string;
remainingSeconds: number;
};
export type AuthRiskBlocksResponse = {
blocks: AuthRiskBlockSummary[];
};
export type AuthLiftRiskBlockResponse = {
ok: true;
};
export type LogoutResponse = {
ok: true;
};