okta / okta-react

Okta OIDC SDK for React
https://github.com/okta/okta-react
Other
113 stars 79 forks source link

Redirect callback component receives authState null #273

Closed amoljain closed 5 months ago

amoljain commented 7 months ago

Describe the bug

After logging in, I get a redirect to login/callback, but the authState that I get from const { authState, oktaAuth } = useOktaAuth(); is always null.

Reproduction Steps?

Using following versions:

   "@okta/okta-auth-js": "6.0",
    "@okta/okta-react": "6.4",

I have Routes setup as:

<Route path={'/login/callback'} element={<OktaLoginCallback />} />
 <Route path={'/login'} element={<LoginPage />} />
is properly setup: `` From my login screen I call: `oktaAuth.signInWithRedirect();` With the following config: ``` export const oktaConfig = { issuer: .../oauth2/default', clientId: '.....', redirectUri: window.location.origin + '/login/callback', scopes: ['openid', 'profile', 'email'], }; ``` I am able to get to Okta, login and get a redirect to a URL like: `http://localhost/login/callback?code=blahblah&state=blahbvlah` Which launches my callback component, but the authState is always null here. ``` const OktaLoginCallback: React.FC = () => { const { authState, oktaAuth } = useOktaAuth(); useEffect(() => { console.log("component dididdiididididiididi amunt") }, []) useEffect(() => { console.log("Auth State is null here >>", authState) if (!authState || !authState.isAuthenticated) return; // Assuming the tokens are in authState, adjust according to your setup const { idToken, accessToken } = authState; api.post('/okta/login', { idToken, accessToken }) .then(response => { const auth = getAuth(); // Use the Firebase SDK to authenticate with the custom token signInWithCustomToken(auth, response.data.firebaseToken); }) .catch(error => { console.error('Error exchanging tokens:', error); }); }, [authState]); return

Handling response...

; }; ```` ### SDK Versions System: OS: macOS 13.0 CPU: (8) arm64 Apple M2 Memory: 90.05 MB / 24.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 20.10.0 - /usr/local/bin/node Yarn: 1.22.4 - /usr/local/bin/yarn npm: 10.2.3 - /usr/local/bin/npm Watchman: 2023.08.14.00 - /usr/local/bin/watchman Browsers: Chrome: 121.0.6167.160 Safari: 16.1 npmPackages: @okta/okta-auth-js: 6.0 => 6.0.0 @okta/okta-react: 6.4 => 6.4.3 react: ^18.2.0 => 18.2.0 react-bootstrap: ^2.7.4 => 2.7.4 react-bootstrap-table-next: ^4.0.3 => 4.0.3 react-copy-to-clipboard: ^5.1.0 => 5.1.0 react-currency-input-field: ^3.6.10 => 3.6.10 react-d3-speedometer: ^1.1.0 => 1.1.0 react-dates: ^21.8.0 => 21.8.0 react-day-picker: ^8.8.0 => 8.8.0 react-dom: ^18.2.0 => 18.2.0 react-dropdown: ^1.11.0 => 1.11.0 react-dropzone: ^14.2.3 => 14.2.3 react-error-boundary: ^4.0.11 => 4.0.11 react-hook-form: ^8.0.0-alpha.4 => 8.0.0-alpha.4 react-icons: ^4.9.0 => 4.9.0 react-infinite-scroll-hook: ^4.1.1 => 4.1.1 react-input-mask: ^2.0.4 => 2.0.4 react-loading-skeleton: ^3.3.1 => 3.3.1 react-places-autocomplete: ^7.3.0 => 7.3.0 react-redux: ^8.0.7 => 8.0.7 react-refresh: ^0.14.0 => 0.14.0 react-router: ^6.17.0 => 6.17.0 react-router-dom: ^6.17.0 => 6.17.0 react-select: ^5.7.7 => 5.7.7 react-select-event: ^5.5.1 => 5.5.1 react-stack-grid: ^0.7.1 => 0.7.1 react-table: ^7.8.0 => 7.8.0 react-test-renderer: ^18.2.0 => 18.2.0 react-textarea-autosize: ^8.5.3 => 8.5.3 react-timeago: ^7.2.0 => 7.2.0 react-to-print: ^2.14.13 => 2.14.13 react-toastify: ^9.1.3 => 9.1.3 react-use-intercom: ^5.1.4 => 5.1.4 react-virtualized: ^9.22.5 => 9.22.5 ### Additional Information _No response_
amoljain commented 7 months ago

Issue persists even when I have the latest versions: "@okta/okta-auth-js": "^7.5.1", "@okta/okta-react": "^6.7.0",

jaredperreault-okta commented 7 months ago

Are you using the LoginCallback component provided by the SDK (docs) or the Component in the snippet you provided?

jaredperreault-okta commented 5 months ago

@wparam same question

Are you using the LoginCallback component provided by the SDK (docs) or the Component in the snippet you provided?

wparam commented 5 months ago

@wparam same question

Are you using the LoginCallback component provided by the SDK (docs) or the Component in the snippet you provided?

False alarm, it works well, thanks for the reply.