23 lines
625 B
TypeScript
23 lines
625 B
TypeScript
export default defineNuxtPlugin({
|
|
name: 'better-auth-triplit',
|
|
enforce: 'pre',
|
|
async setup(nuxtApp) {
|
|
if (import.meta.client) {
|
|
const triplit = useTriplitClient();
|
|
const { session, fetchSession } = useAuth();
|
|
|
|
nuxtApp.hook('app:mounted', async () => {
|
|
if (!session.value) {
|
|
await fetchSession();
|
|
}
|
|
|
|
if (!session.value) return;
|
|
|
|
if ('startSession' in triplit) {
|
|
await triplit.startSession(session.value.token);
|
|
}
|
|
});
|
|
}
|
|
},
|
|
});
|