Mapo Doofus
Mapo Doofus
SSolidJS
Created by Mapo Doofus on 10/7/2024 in #support
Auth in layout?
Is it safe to do auth in layout components? For instance if I have a function like so and call it in the layout component with createAsync will it work on all page changes within that layout? Or is it like Nextjs where it should be called per page?
export const authOrRedirect = cache(async (url?: string) => {
"use server";

const sess = await getAuthSession();

if (!sess.data.user) {
return redirect(url || "/auth/login", 302);
}

const dbSess = await getUnexpiredSession(sess.data.id);

if (!dbSess) {
await logout();
return redirect(url || "/auth/login", 302);
}

return sess;
}, "authRedirect");
export const authOrRedirect = cache(async (url?: string) => {
"use server";

const sess = await getAuthSession();

if (!sess.data.user) {
return redirect(url || "/auth/login", 302);
}

const dbSess = await getUnexpiredSession(sess.data.id);

if (!dbSess) {
await logout();
return redirect(url || "/auth/login", 302);
}

return sess;
}, "authRedirect");
10 replies