feat: persist customer product and shop favorites through the live API
Replace mall fixture favorites with customer-scoped endpoints, and send signed-out shoppers back to the page they left after sign-in. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
94a64ec712
commit
6c1357ec4d
@@ -1,10 +1,15 @@
|
||||
export default defineNuxtRouteMiddleware(async () => {
|
||||
import { signInPath } from "~/utils/auth";
|
||||
|
||||
export default defineNuxtRouteMiddleware(async (to) => {
|
||||
if (import.meta.server) return;
|
||||
// The requested page, not the current one, is where the shopper should land
|
||||
// after signing in — deep links into the buyer centre must survive.
|
||||
const signIn = signInPath(to.fullPath);
|
||||
const session = useSessionStore();
|
||||
if (!session.token) session.hydrate();
|
||||
if (!session.token) return navigateTo("/login");
|
||||
if (!session.token) return navigateTo(signIn);
|
||||
// Trust the auth API's answer rather than whatever localStorage claims; a
|
||||
// rejected token clears the session inside validate().
|
||||
if (!(await session.validate())) return navigateTo("/login");
|
||||
if (session.user?.role !== "customer") return navigateTo("/login");
|
||||
if (!(await session.validate())) return navigateTo(signIn);
|
||||
if (session.user?.role !== "customer") return navigateTo(signIn);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user