Access user token while inside redirect within rules

Hello,

I am trying to implement an onboarding process for users registering to my react application. So far I managed to add a hasOnboarded prop to the app_metadata via hooks and a rule to redirect a user when hasOnboarded is false. Now I want the user to fill a form and complete the registration. But as far as I can see I have no access to user data yet. But I need the token to communicate with my backend. Is there a way to access the token?

Hey there!

Maybe that can help. Inside rules you have the Context object that has accessToken property. Here’s more on that:

Yes I already looked at it and when I pass context.accessToken via query param for example, the redirect doesnt work anymore… in the docs it says its an object representing options. What does it mean? Isnt it supposed to be a string? When I console.log the context.sessionToken its undefined…

I also tried the Force password change example from Redirect Users and I get a JWT token in the query of my url but if I use that one to make an API call, my backend says the token is not valid.

Edit: I was missing the audience but its still not working… When I compare the token when I login normaly and when I use the rule they look different, thats probably why. If only it would work to get a valid token over the context object… I guess I have too look for another solution!