mirror of
https://github.com/wassname/talk.git
synced 2026-07-10 00:35:56 +08:00
[CORL-721] SSO Logout Fix (#2652)
* fix: hide logout button when jti is undefined * fix: improved local state init
This commit is contained in:
@@ -5,6 +5,7 @@ exports[`get access token from url 1`] = `
|
||||
\\"__id\\": \\"client:root.local\\",
|
||||
\\"__typename\\": \\"Local\\",
|
||||
\\"accessToken\\": \\"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIzMWIyNjU5MS00ZTlhLTQzODgtYTdmZi1lMWJkYzVkOTdjY2UifQ==\\",
|
||||
\\"accessTokenExp\\": null,
|
||||
\\"accessTokenJTI\\": \\"31b26591-4e9a-4388-a7ff-e1bdc5d97cce\\",
|
||||
\\"view\\": \\"SIGN_IN\\",
|
||||
\\"error\\": null
|
||||
|
||||
@@ -26,9 +26,22 @@ export function setAccessTokenInLocalState(
|
||||
localRecord.setValue(accessToken || "", "accessToken");
|
||||
if (accessToken) {
|
||||
const { payload } = parseJWT(accessToken);
|
||||
localRecord.setValue(payload.exp, "accessTokenExp");
|
||||
localRecord.setValue(payload.jti, "accessTokenJTI");
|
||||
|
||||
// TODO: (cvle) maybe a timer to detect when accessToken has expired?
|
||||
|
||||
// Set the exp if it's valid.
|
||||
if (typeof payload.exp === "number") {
|
||||
localRecord.setValue(payload.exp, "accessTokenExp");
|
||||
} else {
|
||||
localRecord.setValue(null, "accessTokenExp");
|
||||
}
|
||||
|
||||
// Set the jti if it's valid.
|
||||
if (typeof payload.jti === "string" && payload.jti.length > 0) {
|
||||
localRecord.setValue(payload.jti, "accessTokenJTI");
|
||||
} else {
|
||||
localRecord.setValue(null, "accessTokenJTI");
|
||||
}
|
||||
} else {
|
||||
localRecord.setValue(null, "accessTokenExp");
|
||||
localRecord.setValue(null, "accessTokenJTI");
|
||||
|
||||
Reference in New Issue
Block a user