templates2.Base.Nuxt/app/composables/useSession.ts
w4c-templates a7a56fd5e0
Some checks failed
CI / quality (push) Has been cancelled
chore(template): publish Base.Nuxt
2026-10-11 23:23:38 +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' }) },
);
}