diff --git a/main.ts b/main.ts index 5d27d7d..16fe1a7 100644 --- a/main.ts +++ b/main.ts @@ -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(); diff --git a/public/login.js b/public/login.js index e4474f2..5840bd2 100644 --- a/public/login.js +++ b/public/login.js @@ -18,6 +18,11 @@ document.querySelector("#login").onsubmit = async (event) => { loginErrorSpan.hidden = false; return; } - window.location.pathname = "/"; + const params = new URLSearchParams(window.location.search); + if (!params.has("refer")) { + window.location.pathname = "/"; + return; + } + window.location.pathname = decodeURIComponent(params.get("refer")); };