简体   繁体   中英

How do I redirect to different pages with Auth0 and Lock in Angular 1?

I'm using Auth0 and Lock 10 and I'm having a lot of trouble figuring out how to customise lock correctly.

In angular's config phase, lockProvider.init provides the "redirectUrl" parameter, as per the quickstart guide here .

The problem is that I would like to redirect users to one route (I'm using ui-router) if they have signed up, and another route if they have previously signed up, and they are now signing in.

I don't think I can change lockProvider.init variables after the function is run, and the redirectTo variable isn't in the list of options that can be changed when invoking show() to bring up the lock modal.

Any help would be greatly appreciated... I feel like there must be something I'm missing in my understanding of lock since I don't see how it can be used for anything more than a simple login window.

Assuming you're using the implicit grant flow to request the issuing of an ID Token, the outcome of the authentication process initiated by Lock will be the triggering of the authenticated event that signals that you received the requested ID Token. This will be delivered on the redirect URL you configured.

After receiving and validating this token you can then redirect the authenticated user to any route within your own application.

If you need to distinguish between users that performed login for the first time versus recurring users you can do that by either:

  • include information within the ID Token that informs you if the users is a first time user (you can look into using Auth0 rules to achieve this).
  • track first-time users within your own application back-end and upon receiving the ID Token make a request to your back-end to know if this is a first time user or not.

The received ID Token will contain a sub claim containing a unique and stable user identifier that you can use to keep track of user related information within your own back-end.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM