Is there a way to make the successRedirect dynamic? For example, if the user is not logged in but tries to access a restricted page, I'd like to redirect to the login page, and then redirect to the original intended destination page after login.
This is related to
derby-login: [question] custom redirect urls #31. The method described there seems like it's only intended for external auth providers. In my case, I followed the derby-login-example strategy of having a
separate page for login, and I'm using the local strategy only. I'm not sure how to communicate the redirect location through the login page. I tried storing it in "_session.redirect", but soon realized that the "_session" object gets changed when the user logs in. I also tried storing it in "_page.redirect", but that also didn't work.
My route for creating a document (which requires being logged in) looks something like this:
app.get("/create", function(page, model, params, next) {
if (model.get("_session.loggedIn")) {
var id = generateDocumentId(model);
model.add("documents", {
id: id,
content: ""
});
page.redirect("/" + id + "/edit");
} else {
// Here's where I'd like to set query.redirect = "/create", but don't know how.
// This does not work, as the session gets destroyed on login.
// model.set("_session.redirect", "/create", function (err){
// page.redirect("/login");
// });
// This also does not work, as the _page contexts seems to be transient.
// model.set("_page.redirect", "/create", function (err){
// page.redirect("/login");
// });
// This also does not work.
// model.set("redirect", "/create", function (err){
// page.redirect("/login");
// });
// This also does not work, as the query parameters need to go on the /auth/login route (I think).
page.redirect("/login?redirect=/create");
}
});
Any help would be greatly appreciated. I feel like it should be a simple thing and I'm just missing something. Thank you.
Regards,
Curran