florianheinemann / passwordless

node.js/express module to authenticate users without password
MIT License
1.95k stars 129 forks source link

Append 'returnUrl' to generated token/uid URL which is sent to user's email #87

Open wenboSky opened 8 years ago

wenboSky commented 8 years ago

@florianheinemann , Hi guy, I want to append a 'returnUrl' into generated token/uid URL which is sent to user's email, so that client route can switch back to last visited url which was visited before 'SignIn' and requestToken. any idea? Thanks.

florianheinemann commented 8 years ago

Does this answer your question? https://passwordless.net/deepdive#successful-login-and-redirect-to-origin

wenboSky commented 8 years ago

I don't think so. the successRedirect of acceptToken is a 'fixed' path, but my case need redirect to a 'dynamic' path. My use case like this:

  1. User visit a specific 'Last visited URL'
  2. If user is not authenticated, the client will redirect to 'Login' page(I understand this step can be done by Restricted middleware) 3 then user input email and post 'sendToken' to server, passwordless will requestToken, user will receive a mail
  3. User open URL with token/uid in email, passwordless will acceptToken, if anthorized successfully, I hope redirect to 'Last visited URL' in step 1.

The question is how acceptToken middleware to get this 'Last visited UrL' as its options.successDirection in step4?

florianheinemann commented 8 years ago

Hey, That's exactly what enableOriginRedirect is supposed to do. It overwrites successRedirect with the last visited URL Cheers