After authenticating by logging into okta or reloading the page from previous session, I want to be able to store the User’s email/claim in redux before rendering the component inside the SecureRoute. Is there a way to do this?
A first step is to ensure the email scope is part of your request, it should be as OktaAuth.scopes property defaults to ['openid', 'email'] .
When your callback is triggered after login, you can call this.oktaAuth.token.getUserInfo() and save the user.email claim.
this.oktaAuth.token.getUserInfo()
.then(function(user) {
// user has details about the user
})
.catch(function(err) {
// handle OAuthError or AuthSdkError (AuthSdkError will be thrown if app is in OAuthCallback state)
});
Thank you for the reply. I’m familiar with that, but that’s not quite what I’m looking for.
I want the following:
Step 1) When they arrive at the website’s SecureRoute, check if they are authenticated. If they are, then load info into redux. If they aren’t redirect to okta for login, and then store info in redux after proper login.
Step 2) Display SecureRoute’s component
It seems to me I would have to attach that getUserInfo check inside every 's component at the start, which I would like to avoid. I was hoping there would be one spot where I can inject a function where it would be called upon validating that the user is authenticated.
You probably want to save the claim only for the component loaded after user sign-in, so only one function call. There is also an Okta blog post that may help: