fix: preserve deep link when redirecting to login (#7876)

This commit is contained in:
Henri Cook
2026-07-17 19:21:19 +01:00
committed by GitHub
parent ae5aa5a0b8
commit 16a0ba2e21
6 changed files with 44 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
import axios from "axios";
import { alert } from "~/composables/use-toast";
import { getTokenCookieOptions } from "~/composables/use-token-cookie";
import { isSafeRedirectTarget } from "~/lib/validators/redirect";
declare module "axios" {
interface AxiosRequestConfig {
@@ -49,7 +50,10 @@ export default defineNuxtPlugin(() => {
// Disable beforeunload warnings to prevent "Are you sure you want to leave?" popups
window.onbeforeunload = null;
window.location.href = "/login";
const target = window.location.pathname + window.location.search;
const redirect = isSafeRedirectTarget(target) && target !== "/login" ? `?redirect=${encodeURIComponent(target)}` : "";
window.location.href = `/login${redirect}`;
}
}