19 lines
514 B
TypeScript
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' }) },
|
|
);
|
|
}
|