GenieFramework / GenieAuthentication.jl

Authentication plugin for Genie framework
MIT License
20 stars 11 forks source link

redirect to originally requested page upon login #9

Open dms449 opened 2 years ago

dms449 commented 2 years ago

One way (suggested by @essenciary here) would be to include the original URL as an optional param like redirect("login?original_page=/users/10/delete") or redirect(:show_login; extra_query = Dict("original_page" => "/users/10/delete")

I also wondered if it could be stored in the session object? I'm not really a web designer so maybe this is stupid for some reason, I don't know.

I'm just not sure how to get the last requested URL.

dms449 commented 2 years ago

I have almost finished one approach to dealing with this. Let me know what you think.

I have changed the implementation and usage of @authenticated! macro from

route("/", named=:home) do @authenticated!
  HomeController.index
end

to

@authenticated! route("/", HomeController.index, named=:home)

The macro now wraps the provided function (in this case HomeController.index) to temporarily store the originally requested route in the session before calling the function HomeController.index. Then, inside AuthenticationController, the sucess function reroutes to this temporarily stored path.

Thoughts, @essenciary ?

essenciary commented 1 year ago

@dms449 Sorry, missed this. It's a great approach but would require some changes of logic in latest version as we replaced the @authenticated! macro with the authenticated!() function (the macro was causing some bugs).

However, it can easily be added to the authenticated!() function: 1/ we can get the current route from Router.params 2/ we can store it on the session 3/ in the success page (after login) we can check the session and redirect