fix(frontend): restore pending auth session flow
This commit is contained in:
@@ -211,6 +211,78 @@ describe('useAuthStore', () => {
|
||||
|
||||
expect(store.isAuthenticated).toBe(true)
|
||||
})
|
||||
|
||||
it('恢复持久化 pending auth session', () => {
|
||||
localStorage.setItem(
|
||||
'pending_auth_session',
|
||||
JSON.stringify({
|
||||
token: 'pending-token',
|
||||
token_field: 'pending_auth_token',
|
||||
provider: 'wechat',
|
||||
redirect: '/profile',
|
||||
})
|
||||
)
|
||||
|
||||
const store = useAuthStore()
|
||||
store.checkAuth()
|
||||
|
||||
expect(store.hasPendingAuthSession).toBe(true)
|
||||
expect(store.pendingAuthSession).toEqual({
|
||||
token: 'pending-token',
|
||||
token_field: 'pending_auth_token',
|
||||
provider: 'wechat',
|
||||
redirect: '/profile',
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('pending auth session', () => {
|
||||
it('persists and clears pending auth session state', () => {
|
||||
const store = useAuthStore()
|
||||
|
||||
store.setPendingAuthSession({
|
||||
token: 'pending-token',
|
||||
token_field: 'pending_auth_token',
|
||||
provider: 'wechat',
|
||||
redirect: '/profile',
|
||||
})
|
||||
|
||||
expect(store.hasPendingAuthSession).toBe(true)
|
||||
expect(JSON.parse(localStorage.getItem('pending_auth_session') || 'null')).toEqual({
|
||||
token: 'pending-token',
|
||||
token_field: 'pending_auth_token',
|
||||
provider: 'wechat',
|
||||
redirect: '/profile',
|
||||
})
|
||||
|
||||
store.clearPendingAuthSession()
|
||||
|
||||
expect(store.hasPendingAuthSession).toBe(false)
|
||||
expect(localStorage.getItem('pending_auth_session')).toBeNull()
|
||||
})
|
||||
|
||||
it('preserves pending auth session when registration fails', async () => {
|
||||
const store = useAuthStore()
|
||||
store.setPendingAuthSession({
|
||||
token: 'pending-token',
|
||||
token_field: 'pending_auth_token',
|
||||
provider: 'oidc',
|
||||
redirect: '/register',
|
||||
})
|
||||
mockRegister.mockRejectedValue(new Error('Register failed'))
|
||||
|
||||
await expect(
|
||||
store.register({ email: 'user@example.com', password: 'secret-123' })
|
||||
).rejects.toThrow('Register failed')
|
||||
|
||||
expect(store.hasPendingAuthSession).toBe(true)
|
||||
expect(store.pendingAuthSession).toEqual({
|
||||
token: 'pending-token',
|
||||
token_field: 'pending_auth_token',
|
||||
provider: 'oidc',
|
||||
redirect: '/register',
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
// --- isAdmin ---
|
||||
|
||||
Reference in New Issue
Block a user