templates2.Store.Nuxt/app/composables/useSession.ts
w4c-templates 228f2f01f2
Some checks failed
CI / quality (push) Has been cancelled
chore(template): publish Store.Nuxt
2026-10-11 23:24:30 +03:00

19 lines
514 B
TypeScript

import type { SessionUser } from '#shared/types';
export type Session = { user: SessionUser | null; plan: string };
/** Fetch the current session (user + plan) once per request and share it across components. */
export function useSession() {
return useAsyncData<Session>(
'session',
async () => {
try {
return await $fetch<Session>('/api/auth/me');
} catch {
return { user: null, plan: 'free' };
}
},
{ default: () => ({ user: null, plan: 'free' }) },
);
}