mirror of
https://github.com/SrIzan10/next-auth.git
synced 2026-05-01 10:55:20 +00:00
* chore: dev -> dev/nextjs * chore: move to /examples * chore: move to playgrounds, add dev/sveltekit * Update sync.yml * chore: dev scripts
20 lines
452 B
TypeScript
20 lines
452 B
TypeScript
import { Session } from "@auth/core"
|
|
|
|
export default defineNuxtPlugin(async () => {
|
|
const session = useSession()
|
|
|
|
addRouteMiddleware("auth", () => {
|
|
if (!session.value) return navigateTo("/")
|
|
})
|
|
|
|
if (process.server) {
|
|
const data = await $fetch<Session>("/api/auth/session", {
|
|
headers: useRequestHeaders() as any,
|
|
})
|
|
|
|
const hasSession = data && Object.keys(data).length
|
|
|
|
session.value = hasSession ? data : null
|
|
}
|
|
})
|