🐛 Fix logut menu item

This commit is contained in:
Luke Vella 2025-01-03 21:53:57 +00:00
parent 00548ab763
commit 471d98d50b
No known key found for this signature in database
GPG key ID: 469CAD687F0D784C
3 changed files with 12 additions and 24 deletions

View file

@ -33,6 +33,7 @@ export const UserContext = React.createContext<{
userId?: string | null;
guestId?: string | null;
}) => boolean;
logout: () => Promise<void>;
} | null>(null);
export const useUser = () => {
@ -105,6 +106,12 @@ export const UserProvider = (props: { children?: React.ReactNode }) => {
locale: user.locale ?? i18n.language,
},
refresh: session.update,
logout: async () => {
await fetch("/api/logout", { method: "POST" });
posthog?.capture("logout");
posthog?.reset();
window.location.href = "/login";
},
ownsObject: (resource) => {
return isOwner(resource, { id: user.id, isGuest });
},