Merge branch 'master' of http://82.157.175.59:3000/GenarrativeAI/Genarrative
This commit is contained in:
@@ -219,15 +219,20 @@ describe('authService', () => {
|
||||
},
|
||||
});
|
||||
|
||||
const user = await loginWithPhoneCode('13800138000', '123456');
|
||||
const response = await loginWithPhoneCode(
|
||||
'13800138000',
|
||||
'123456',
|
||||
'spring-2026',
|
||||
);
|
||||
|
||||
expect(user.username).toBe('138****8000');
|
||||
expect(response.user.username).toBe('138****8000');
|
||||
expect(apiClientMocks.requestJson).toHaveBeenCalledWith(
|
||||
'/api/auth/phone/login',
|
||||
expect.objectContaining({
|
||||
body: JSON.stringify({
|
||||
phone: '13800138000',
|
||||
code: '123456',
|
||||
inviteCode: 'SPRING2026',
|
||||
}),
|
||||
}),
|
||||
'登录失败',
|
||||
|
||||
@@ -65,6 +65,13 @@ export function normalizePhoneInput(phoneInput: string) {
|
||||
return phoneInput.replace(/[^\d+]/gu, '').trim();
|
||||
}
|
||||
|
||||
export function normalizeInviteCodeInput(inviteCode: string | undefined) {
|
||||
return (inviteCode ?? '')
|
||||
.trim()
|
||||
.replace(/[^0-9a-z]/gi, '')
|
||||
.toUpperCase();
|
||||
}
|
||||
|
||||
export function getStoredLastLoginPhone() {
|
||||
if (typeof window === 'undefined') {
|
||||
return '';
|
||||
@@ -145,7 +152,12 @@ export async function sendPhoneLoginCode(
|
||||
return response;
|
||||
}
|
||||
|
||||
export async function loginWithPhoneCode(phone: string, code: string) {
|
||||
export async function loginWithPhoneCode(
|
||||
phone: string,
|
||||
code: string,
|
||||
inviteCode?: string,
|
||||
) {
|
||||
const normalizedInviteCode = normalizeInviteCodeInput(inviteCode);
|
||||
const response = await requestJson<AuthPhoneLoginResponse>(
|
||||
'/api/auth/phone/login',
|
||||
{
|
||||
@@ -154,6 +166,7 @@ export async function loginWithPhoneCode(phone: string, code: string) {
|
||||
body: JSON.stringify({
|
||||
phone: normalizePhoneInput(phone),
|
||||
code: code.trim(),
|
||||
...(normalizedInviteCode ? { inviteCode: normalizedInviteCode } : {}),
|
||||
}),
|
||||
},
|
||||
'登录失败',
|
||||
@@ -161,7 +174,7 @@ export async function loginWithPhoneCode(phone: string, code: string) {
|
||||
);
|
||||
|
||||
setStoredAccessToken(response.token, { emit: false });
|
||||
return response.user;
|
||||
return response;
|
||||
}
|
||||
|
||||
export async function bindWechatPhone(phone: string, code: string) {
|
||||
|
||||
Reference in New Issue
Block a user