22 lines
617 B
TypeScript
22 lines
617 B
TypeScript
import { assert } from "~~/utils/assert";
|
|
|
|
export default defineNuxtPlugin({
|
|
name: 'better-auth',
|
|
enforce: 'pre',
|
|
async setup(nuxtApp) {
|
|
if (import.meta.client) {
|
|
const { session, fetchSession } = useAuth();
|
|
|
|
nuxtApp.hook('app:mounted', async () => {
|
|
if (!session.value) {
|
|
const result = await fetchSession();
|
|
if (!result.ok) {
|
|
console.warn('Failed to fetch session:', result.error);
|
|
return;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
},
|
|
});
|