Skip to content

Commit

Permalink
fix: call auth when token is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
vinu-deriv committed Feb 21, 2025
1 parent d87fdf2 commit 34e67a3
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/javascript/_common/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,24 @@ export const requestSingleSignOn = async () => {
// if we are not in the callback route to prevent re-calling this function - !isCallbackPage
// if client.accounts in localStorage is empty - !isClientAccountsPopulated
// and if feature flag for OIDC Phase 2 is enabled - isAuthEnabled
if (isLoggedInCookie && !isCallbackPage && !isEndpointPage && !isClientAccountsPopulated && isAuthEnabled) {
// Check if any account or its linked account is missing a token
const hasMissingToken = Object.values(clientAccounts).some((account) => {
// Check if current account is missing token
if (!account?.token) {
return true; // No linked accounts and no token
}
return false;
});

const shouldRequestSignOn =
isLoggedInCookie &&
!isCallbackPage &&
!isEndpointPage &&
(!isClientAccountsPopulated || // Changed this condition since we need accounts to check tokens
hasMissingToken) &&
isAuthEnabled;

if (shouldRequestSignOn) {
const currentLanguage = Language.get();
await requestOidcAuthentication({
redirectCallbackUri: `${window.location.origin}/${currentLanguage}/callback`,
Expand Down

0 comments on commit 34e67a3

Please sign in to comment.