forked from clerk/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.ts
More file actions
24 lines (20 loc) · 963 Bytes
/
Copy pathplugin.ts
File metadata and controls
24 lines (20 loc) · 963 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { setClerkJsLoadingErrorPackageName } from '@clerk/shared/loadClerkJsScript';
import { clerkPlugin } from '@clerk/vue';
import { setErrorThrowerOptions } from '@clerk/vue/internal';
import { defineNuxtPlugin, navigateTo, useRuntimeConfig, useState } from 'nuxt/app';
setErrorThrowerOptions({ packageName: PACKAGE_NAME });
setClerkJsLoadingErrorPackageName(PACKAGE_NAME);
export default defineNuxtPlugin(nuxtApp => {
// SSR-friendly shared state
const initialState = useState('clerk-initial-state', () => undefined);
if (import.meta.server) {
// Save the initial state from server and pass it to the plugin
initialState.value = nuxtApp.ssrContext?.event.context.__clerk_initial_state;
}
nuxtApp.vueApp.use(clerkPlugin, {
...(useRuntimeConfig().public.clerk ?? {}),
routerPush: (to: string) => navigateTo(to),
routerReplace: (to: string) => navigateTo(to, { replace: true }),
initialState: initialState.value,
});
});