wip migration
This commit is contained in:
18
plugins/auth-init.server.ts
Normal file
18
plugins/auth-init.server.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import cookie from 'cookie'
|
||||
import { useAuthStore } from '~/stores/auth'
|
||||
|
||||
export default defineNuxtPlugin(() => {
|
||||
const auth = useAuthStore()
|
||||
|
||||
try {
|
||||
const cookies = cookie.parse(useRequestHeaders().cookie || '')
|
||||
const authCookie = cookies['authentication-cookie']
|
||||
|
||||
if (authCookie) {
|
||||
const parsed = JSON.parse(authCookie)
|
||||
auth.setPayload(parsed.auth)
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to parse authentication cookie', err)
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user