mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-11-11 14:32:36 +00:00
fix(profile): stabilize binding compatibility and frontend checks
This commit is contained in:
1 parent
1aab084ecb
commit
ca4e38aa01
30 files changed
+1072
-97
No files matched your search
@@ -456,7 +456,14 @@ function resolvePendingAccountAction(
|
||||
if (raw === 'email_required' || raw === 'create_account_required' || raw === 'create_account') {
|
||||
return 'create_account'
|
||||
}
|
||||
if (raw === 'bind_login_required' || raw === 'bind_login') {
|
||||
if (
|
||||
raw === 'bind_login_required' ||
|
||||
raw === 'bind_login' ||
|
||||
raw === 'existing_account' ||
|
||||
raw === 'existing_account_required' ||
|
||||
raw === 'existing_account_binding_required' ||
|
||||
raw === 'adopt_existing_user_by_email'
|
||||
) {
|
||||
return 'bind_login'
|
||||
}
|
||||
return 'none'
|
||||
|
||||
@@ -613,8 +613,12 @@ async function handleBindCurrentAccount() {
|
||||
return
|
||||
}
|
||||
|
||||
await prepareOAuthBindAccessTokenCookie()
|
||||
window.location.href = startURL
|
||||
try {
|
||||
await prepareOAuthBindAccessTokenCookie()
|
||||
window.location.href = startURL
|
||||
} catch (e: unknown) {
|
||||
errorMessage.value = getRequestErrorMessage(e, t('auth.loginFailed'))
|
||||
}
|
||||
}
|
||||
|
||||
async function handleExistingAccountBinding() {
|
||||
|
||||
@@ -336,6 +336,33 @@ describe('LinuxDoCallbackView', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('keeps rendering bind-login UI for legacy pending bind responses instead of treating them as success', async () => {
|
||||
exchangePendingOAuthCompletion.mockResolvedValue({
|
||||
error: 'adopt_existing_user_by_email',
|
||||
redirect: '/profile/security',
|
||||
email: 'existing@example.com'
|
||||
})
|
||||
|
||||
const wrapper = mount(LinuxDoCallbackView, {
|
||||
global: {
|
||||
stubs: {
|
||||
AuthLayout: { template: '<div><slot /></div>' },
|
||||
Icon: true,
|
||||
RouterLink: { template: '<a><slot /></a>' },
|
||||
transition: false
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
await flushPromises()
|
||||
|
||||
expect(showSuccess).not.toHaveBeenCalled()
|
||||
expect(replace).not.toHaveBeenCalled()
|
||||
expect((wrapper.get('[data-testid="linuxdo-bind-login-email"]').element as HTMLInputElement).value).toBe(
|
||||
'existing@example.com'
|
||||
)
|
||||
})
|
||||
|
||||
it('persists a pending auth session when the oauth flow still needs account creation', async () => {
|
||||
exchangePendingOAuthCompletion.mockResolvedValue({
|
||||
error: 'email_required',
|
||||
|
||||
@@ -621,6 +621,34 @@ describe('WechatCallbackView', () => {
|
||||
expect(locationState.current.href).toContain('mode=open')
|
||||
})
|
||||
|
||||
it('shows an error and stays on the page when preparing bind-token for the current account fails', async () => {
|
||||
exchangePendingOAuthCompletionMock.mockResolvedValue({
|
||||
error: 'invitation_required',
|
||||
redirect: '/usage',
|
||||
})
|
||||
getAuthTokenMock.mockReturnValue('current-auth-token')
|
||||
prepareOAuthBindAccessTokenCookieMock.mockRejectedValue(new Error('bind token failed'))
|
||||
|
||||
const wrapper = mount(WechatCallbackView, {
|
||||
global: {
|
||||
stubs: {
|
||||
AuthLayout: { template: '<div><slot /></div>' },
|
||||
Icon: true,
|
||||
RouterLink: { template: '<a><slot /></a>' },
|
||||
transition: false,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
await flushPromises()
|
||||
|
||||
await wrapper.get('[data-testid="existing-account-submit"]').trigger('click').catch(() => undefined)
|
||||
await flushPromises()
|
||||
|
||||
expect(showErrorMock).toHaveBeenCalledWith('bind token failed')
|
||||
expect(locationState.current.href).toBe('http://localhost/auth/wechat/callback')
|
||||
})
|
||||
|
||||
it('collects email, password, and verify code for pending oauth account creation and submits adoption decisions', async () => {
|
||||
getPublicSettingsMock.mockResolvedValue({
|
||||
invitation_code_enabled: true,
|
||||
|
||||
Reference in new issue
Block a user