fix(client): 修复登录会话自动续期

This commit is contained in:
2026-09-03 18:11:07 +08:00
parent 39e1c8e6ee
commit b3649c314a
9 changed files with 128 additions and 28 deletions
+9 -2
View File
@@ -44,10 +44,14 @@ test('matches the frozen username-or-mobile login contract', () => {
assert.match(loginSource, /忘记密码/)
})
test('persists both rotating tokens according to the remember choice', () => {
test('persists rotating tokens independently and only remembers the login id by choice', () => {
assert.match(sessionSource, /ACCESS_TOKEN_KEY/)
assert.match(sessionSource, /REFRESH_TOKEN_KEY/)
assert.match(sessionSource, /remember \? localStorage : sessionStorage/)
assert.match(sessionSource, /localStorage\.setItem\(ACCESS_TOKEN_KEY, tokens\.accessToken\)/)
assert.match(sessionSource, /localStorage\.setItem\(REFRESH_TOKEN_KEY, tokens\.refreshToken\)/)
assert.match(sessionSource, /persistRememberedLoginId/)
assert.match(loginSource, /getRememberedLoginId/)
assert.match(loginSource, /记住账号/)
assert.match(sessionSource, /clearSessionTokens/)
})
@@ -93,6 +97,7 @@ test('uses real auth endpoints and single-flight refresh handling', () => {
assert.match(httpSource, /refreshPromise/)
assert.match(httpSource, /\/auth\/refresh/)
assert.match(httpSource, /persistTokenPair\(tokens\)/)
assert.match(httpSource, /token && !isPublicAuthRequest\(config\.url\)/)
assert.match(httpSource, /request\._retriedAfterRefresh = true/)
assert.match(httpSource, /return await transport\.request\(request\)/)
assert.match(httpSource, /envelope\.code !== '200'/)
@@ -102,6 +107,8 @@ test('uses real auth endpoints and single-flight refresh handling', () => {
assert.match(httpSource, /error instanceof CrossTabRefreshTimeoutError[\s\S]*window\.dispatchEvent\(new CustomEvent\('cc-client-session-expired'\)\)[\s\S]*redirectToLoginAfterSessionExpiry\(\)/)
assert.match(httpSource, /window\.location\.replace\(`\/login\?redirect=\$\{encodeURIComponent\(redirect\)\}`\)/)
assert.match(authStoreSource, /decodeMerchantToken/)
assert.match(authStoreSource, /MerchantTokenExpiredError && getRefreshToken\(\)/)
assert.match(authStoreSource, /applyToken\(await refreshAuthenticatedSession\(\)\)/)
assert.doesNotMatch(authStoreSource, /mock-client:/)
})