🐛 Fix guard generate redirect uri ignore query strings

This commit is contained in:
LittleSheep 2024-02-01 21:42:47 +08:00
parent ae915babe6
commit e5641b8068
2 changed files with 5 additions and 4 deletions

View File

@ -21,15 +21,16 @@ export default function RootLayout(props: any) {
}, [ready, userinfo]);
function keepGate(path: string, e?: BeforeLeaveEventArgs) {
const pathname = path.split("?")[0];
const whitelist = ["/auth/login", "/auth/register", "/users/me/confirm"];
if (!userinfo?.isLoggedIn && !whitelist.includes(path)) {
if (!userinfo?.isLoggedIn && !whitelist.includes(pathname)) {
if (!e?.defaultPrevented) e?.preventDefault();
navigate(`/auth/login?redirect_uri=${path}`);
navigate(`/auth/login?redirect_uri=${encodeURIComponent(path)}`);
}
}
useBeforeLeave((e: BeforeLeaveEventArgs) => keepGate(e.to.toString().split("?")[0], e));
useBeforeLeave((e: BeforeLeaveEventArgs) => keepGate(e.to.toString(), e));
return (
<Show when={ready()} fallback={

View File

@ -89,7 +89,7 @@ export default function LoginPage() {
if (data["is_finished"]) {
await grantToken(data["session"]["grant_token"]);
await readProfiles();
navigate(searchParams["redirect_uri"] ?? "/");
navigate(searchParams["redirect_uri"] ? decodeURIComponent(searchParams["redirect_uri"]) : "/");
} else {
setError(null);
setStage("choosing");