mikker / passwordless

🗝 Authentication for your Rails app without the icky-ness of passwords
MIT License
1.28k stars 88 forks source link

destination_path param not respected #115

Closed jordanful closed 1 year ago

jordanful commented 2 years ago

Hi gang, this is a great library. Many many thanks.

I'm attempting to pass a url parameter for destination_path with the goal of redirecting a user from the magic link to a specific page in my application (I'm using this param because it's a "one-off" flow and don't want this path used every time a user signs up or signs in).

My question is: how and to where is this parameter added? I've tried passing it to sessions#create in the email form as a hidden field. The parameter gets passed on submit, but the redirect doesn't happen. I've even tried manually appending the parameter to the magic link from the mail (literally copying the magic link, pasting it into my browser bar, adding the destination_path parameter and value, and hitting enter — but it's not recognized and I'm simply directed to root.)

Any help is appreciated. Thanks again. 🙂

jordanful commented 2 years ago

I think I found the main issue, which is my parameter value had encoded quotes around it (%22). When I removed those surrounding quotes, I get redirected properly. 🤦🏻‍♂️

Still, I'm manually adding this param to the magic link URL from the email as described above, for testing purposes. Passing it via a hidden field isn't adding the param when the magic link gets generated. Where's the right place to pass the parameter?

nickhammond commented 2 years ago

@jordanful It might be simpler to flip a flag on a user and then redirect post sign in to the appropriate place. The other idea that comes to mind is if you're able to manually set the session redirect location similar to https://github.com/mikker/passwordless/blob/master/lib/passwordless/controller_helpers.rb#L124. Or you could override after_session_save and utilize your own method that overrides that overrides the final magic URL.