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

@@ -2,6 +2,7 @@ import { ref } from "vue";
import { useAsyncKey } from "../use-utils";
import { usePublicExploreApi } from "~/composables/api/api-client";
import { useUserApi } from "~/composables/api";
import { isSafeRedirectTarget } from "~/lib/validators/redirect";
import type { OrderByNullPosition, Recipe } from "~/lib/api/types/recipe";
import type { RecipeSearchQuery } from "~/lib/api/user/recipes/recipe";
@@ -43,6 +44,7 @@ function getParams(
export const useLazyRecipes = function (publicGroupSlug: string | null = null) {
const router = useRouter();
const route = useRoute();
// passing the group slug switches to using the public API
const api = publicGroupSlug ? usePublicExploreApi(publicGroupSlug).explore : useUserApi();
@@ -65,7 +67,8 @@ export const useLazyRecipes = function (publicGroupSlug: string | null = null) {
);
if (error?.response?.status === 404) {
router.push("/login");
const redirect = typeof route.query.redirect === "string" ? route.query.redirect : undefined;
router.push(isSafeRedirectTarget(redirect) ? { path: "/login", query: { redirect } } : "/login");
}
return data ? data.items : [];