Legacy Dev Forum Posts

 View Only

Sign Up

AuthProvider.getAuthCode has no window object

  • 1.  AuthProvider.getAuthCode has no window object

    Posted 06-05-2025 18:38

    Phil_Tietjen | 2024-04-11 04:16:54 UTC | #1

    We have an authenticated Web Messenger JS SDK implemented in a SPA with react.

    We have an internal authentication provider we use to retrieve the brand code that we need to load in an IFrame at the moment.

    This works for us on first page load and authenticating with our app registering our AuthProvider and the command getAuthCode.

    AuthProvider.registerCommand('getAuthCode', e => {
    
          const urlParams = new URLSearchParams(window.location.search);
    
          const code = urlParams.get('code');
    
          e.resolve({
            authCode: code,
            redirectUri: env.REACT_APP_GENESYS_REDIRECT_URI,
            codeVerifier: localStorage.getItem('genesys-oauth-code-verifier')
          });
        });
    
        /* Subscribe to Auth plugin events - optional */
    
        AuthProvider.ready();
      });

    getAuthCode has no issues referencing localStorage keys and window.location.search query params the first time on registering.

    In a scenario where we log out of our app & web messenger and log back in without any full page load, to avoid running into an error of re-registering AuthProvider, we retrieve a new brand code and call the Auth.getTokens() command but now runs into an issue where localStorage or URLSearchParams cannot be used resulting in errors like

    typeError: URLSearchParams is not a constructor
    
    or
    
    Cannot read properties of null (reading 'getItem')

    system | 2024-05-11 04:16:58 UTC | #2

    This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.


    This post was migrated from the old Developer Forum.

    ref: 25663