-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Description
SSR causes document is not defined
within a nuxt application using the @descope/vue-sdk
Reproduce
-
Create a basic nuxt application using
pnpm dlx nuxi@latest init <project-name>
-
Then setup your
nuxt.config.ts
file
export default defineNuxtConfig({
future: {
compatibilityVersion: 4
}
})
- Create your plugin in the
app/plugins
directory asdescope.client.js
import descope, { getSdk } from "@descope/vue-sdk";
import { defineNuxtPlugin, useRuntimeConfig } from '#imports'
export default defineNuxtPlugin({
name: 'descope',
async setup ({ vueApp }) {
vueApp.use(descope, {
projectId: <ProjectId>,
baseUrl: <BaseURL>
});
const sdk = getSdk();
sdk?.onSessionTokenChange((newSession) => {
// here you can implement custom logic when the session is changing
});
}
})
- Then simply try to use one of the composables or the Descope component in a page
# app/pages/index.vue
<script setup>
import { Descope, useDescope } from "@descope/vue-sdk"; // Causes document not defined from within the BaseDescopeWc.ts
</script>
<template>
<div>
<Descope flowId="sign-in" />
</div>
</template>
Note: This works but has issues too, though this is not a viable because if you try to use a composable anywhere outside of the client rendered component you still get the document issue.
# app/components/DescopeClient.vue
<script setup>
import { Descope, useDescope } from "@descope/vue-sdk";
</script>
<template>
<div>
<Descope flowId="sign-in" />
</div>
</template>
# app/components/DescopeClient.vue
<script setup>
import { Descope, useDescope } from "@descope/vue-sdk";
</script>
<template>
<div>
<ClientOnly fallbackTag="span">
<DescopeClient />
<template #fallback>Loading Component<template>
</ClientOnly>
</div>
</template>
Issue: The issue here is vue warns component and can't resolve
because vue thinks descope-wc
is a vue component.
*Why this is an issue: Nuxt and even Vue have SSR capabilities. Not being able to use this feature and descope sdk is a major barrier to using descope as an auth solution. Especially the composables within an SSR application.
Metadata
Metadata
Assignees
Labels
No labels