# onRedirectCallback based on info from user object

**URL:** <https://community.auth0.com/t/onredirectcallback-based-on-info-from-user-object/55297>\
**Category:** Get Help\
**Tags:** react, login\
**Created:** [December 23, 2020, 2:33pm UTC](https://community.auth0.com/t/onredirectcallback-based-on-info-from-user-object/55297 "2020-12-23T14:33:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![linus1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/linus1/32/12931_2.png) [@linus1](https://community.auth0.com/u/linus1)\
**Post date:** [December 23, 2020, 2:33pm UTC](https://community.auth0.com/t/onredirectcallback-based-on-info-from-user-object/55297/1 "2020-12-23T14:33:28Z")

</div>

Hi,

I’m trying to handle a redirect based on information retrieved from the user object in my React App. So I have created a rule that defines if a users is a first-time login or not. Based on the information I want to redirect users to different pages.

My problem is that the user object hasn’t been defined once the onRedirectCallback is running, hence I can’t determine if it’s a first-time user or not.

Is there any other way I can approach this?

---

<div class="post-metadata">

**Author:** ![Saltuk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/saltuk/32/14364_2.png) [@Saltuk](https://community.auth0.com/u/Saltuk)\
**Post date:** [December 23, 2020, 11:45pm UTC](https://community.auth0.com/t/onredirectcallback-based-on-info-from-user-object/55297/2 "2020-12-23T23:45:30Z")

</div>

In the rule, you may insert a custom claim in the ID Token if the user is logging in for the first time. On the redirect callback handler of your app, you may check the ID Token for this claim, and based on this, the app may redirect the user to a different page.

You may find a sample for how to insert a custom claim on [this link](https://auth0.com/docs/scopes/sample-use-cases-scopes-and-claims#add-custom-claims-to-a-token).

---

<div class="post-metadata">

**Author:** ![linus1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/linus1/32/12931_2.png) [@linus1](https://community.auth0.com/u/linus1)\
**Post date:** [January 3, 2021, 12:39pm UTC](https://community.auth0.com/t/onredirectcallback-based-on-info-from-user-object/55297/3 "2021-01-03T12:39:49Z")

</div>

> [@Saltuk](#):
>
> edirect callback handler of your app

I don’t get this solution since the redirect callback handler is set on the login event hence before the user is authenticated? So I can’t check the ID Token on the callback since I’m not logged in?

---

<div class="post-metadata">

**Author:** ![linus1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/linus1/32/12931_2.png) [@linus1](https://community.auth0.com/u/linus1)\
**Post date:** [January 4, 2021, 9:24am UTC](https://community.auth0.com/t/onredirectcallback-based-on-info-from-user-object/55297/4 "2021-01-04T09:24:30Z")

</div>

As of I understand I could be able to handle the redirect on useEffect or similar. However, since the loginWithRedirect is redirecting me to either what is set in the onRedirectCallback or redirectUri I’m not able to set this.

I forgot to mentioned earlier that I’m using @auth0/auth0-react

---

<div class="post-metadata">

**Author:** ![Saltuk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/saltuk/32/14364_2.png) [@Saltuk](https://community.auth0.com/u/Saltuk)\
**Post date:** [January 5, 2021, 1:11pm UTC](https://community.auth0.com/t/onredirectcallback-based-on-info-from-user-object/55297/5 "2021-01-05T13:11:11Z")

</div>

Hi, @linus1 on your react application login handler URL will be the same both for the first time login as well as the consecutive logins. However, once the authentication is completed, on the callback handler you may decode the ID Token and find the custom claim inserted in the rule.

If the claim is available, meaning that it is the first time login for the user, the app may initiate a second redirect to the endpoint where you handle the first time login use case.

Let me know if you have any questions.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [January 22, 2021, 8:33am UTC](https://community.auth0.com/t/onredirectcallback-based-on-info-from-user-object/55297/7 "2021-01-22T08:33:16Z")

</div>

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