Skip to content

Samples - Catch 401 error on getUser()#164

Closed
denysoblohin-okta wants to merge 3 commits into
masterfrom
od-OKTA-421505-expired-token-when-get-user
Closed

Samples - Catch 401 error on getUser()#164
denysoblohin-okta wants to merge 3 commits into
masterfrom
od-OKTA-421505-expired-token-when-get-user

Conversation

@denysoblohin-okta
Copy link
Copy Markdown
Contributor

@denysoblohin-okta denysoblohin-okta commented Sep 10, 2021

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Adding Tests
  • Build related changes
  • CI related changes
  • Documentation changes
  • Other... Please describe:

What is the current behavior?

If access token is expired at time when user opens protected page which tries to load user info with oktaAuth.getUser(), request will be rejected (with err.xhr.status === 401). And user will see Unhandled Rejection (AuthApiError).

Issue Number:OKTA-421505

What is the new behavior?

Just catch rejection and write it to console.
TokenService will take care of renewing/removing tokens from TokenManager and updating authState which will trigger effect in react component, re-run oktaAuth.getUser() and re-render with correct user info

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Another option would be to call oktaAuth.isAuthenticated() before oktaAuth.getUser(). For okta-auth-js 5.4.3 it would autorenew/remove expired tokens and return actual isAuthenticated value. Also this approach would help to avoid unnecessary getUser() call with expired token that would return 401

Reviewers

denys.oblohin added 3 commits September 10, 2021 12:08
catch oktaAuth.getUser
This reverts commit 8f6c58d.
eng-prod-CI-bot-okta pushed a commit that referenced this pull request Sep 13, 2021
OKTA-421505
<<<Jenkins Check-In of Tested SHA: 97f0d23 for eng_productivity_ci_bot_okta@okta.com>>>
Artifact: okta-react
Files changed count: 6
PR Link: "#164"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants