add login refer
All checks were successful
Validate / Validate (push) Successful in 9s

This commit is contained in:
SimonFJ20 2024-09-26 00:45:26 +02:00
parent 95b0e099ae
commit fca54b30dd
2 changed files with 8 additions and 2 deletions

View File

@ -149,7 +149,8 @@ function authMiddleware(): oak.Middleware {
return async (ctx, next) => {
const token = await ctx.cookies.get("Authorization");
if (!token || !await db.sessionWhereToken(token)) {
ctx.response.redirect("/login.html");
const path = encodeURIComponent(ctx.request.url.pathname);
ctx.response.redirect(`/login.html?refer=${path}`);
return;
}
await next();

View File

@ -18,6 +18,11 @@ document.querySelector("#login").onsubmit = async (event) => {
loginErrorSpan.hidden = false;
return;
}
const params = new URLSearchParams(window.location.search);
if (!params.has("refer")) {
window.location.pathname = "/";
return;
}
window.location.pathname = decodeURIComponent(params.get("refer"));
};