Skip to content

Commit d2ec2ba

Browse files
committed
fix: added ?return_to for ensureLoggedIn middleware
1 parent 057f0e4 commit d2ec2ba

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,14 @@ class Policies {
189189
}
190190
}
191191

192-
const redirectTo =
192+
let redirectTo =
193193
typeof ctx.state.l === 'function'
194194
? ctx.state.l(this.config.loginRoute)
195195
: this.config.loginRoute;
196196

197+
if (ctx.url && ctx.url !== '/')
198+
redirectTo += `?return_to=${encodeURIComponent(ctx.url)}`;
199+
197200
if (ctx.accepts('html')) ctx.redirect(redirectTo);
198201
else ctx.body = { message, redirectTo };
199202

0 commit comments

Comments
 (0)