Skip to content

Commit

Permalink
fix: added ?return_to for ensureLoggedIn middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism committed Dec 19, 2024
1 parent 057f0e4 commit d2ec2ba
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,14 @@ class Policies {
}
}

const redirectTo =
let redirectTo =
typeof ctx.state.l === 'function'
? ctx.state.l(this.config.loginRoute)
: this.config.loginRoute;

if (ctx.url && ctx.url !== '/')
redirectTo += `?return_to=${encodeURIComponent(ctx.url)}`;

if (ctx.accepts('html')) ctx.redirect(redirectTo);
else ctx.body = { message, redirectTo };

Expand Down

0 comments on commit d2ec2ba

Please sign in to comment.