feat(frontend): Use betterAuth implementation from nuxthub-better-auth project

This commit is contained in:
2025-04-20 09:54:16 +02:00
parent 4e7a962a06
commit eec15dd7ef
17 changed files with 209 additions and 66 deletions

View File

@@ -0,0 +1,12 @@
// Copied from https://github.com/atinux/nuxthub-better-auth
export default defineNuxtPlugin(async (nuxtApp) => {
if (!nuxtApp.payload.serverRendered) {
await useAuth().fetchSession()
} else if (Boolean(nuxtApp.payload.prerenderedAt) || Boolean(nuxtApp.payload.isCached)) {
// To avoid hydration mismatch
nuxtApp.hook('app:mounted', async () => {
await useAuth().fetchSession()
})
}
})

View File

@@ -0,0 +1,13 @@
// Copied from https://github.com/atinux/nuxthub-better-auth
export default defineNuxtPlugin({
name: 'better-auth-fetch-plugin',
enforce: 'pre',
async setup(nuxtApp) {
// Flag if request is cached
nuxtApp.payload.isCached = Boolean(useRequestEvent()?.context.cache)
if (nuxtApp.payload.serverRendered && !nuxtApp.payload.prerenderedAt && !nuxtApp.payload.isCached) {
await useAuth().fetchSession()
}
}
})