Token für Reload zusätzlich lokal sichern
This commit is contained in:
@@ -8,7 +8,8 @@ export default defineNuxtPlugin(() => {
|
||||
credentials: "include",
|
||||
|
||||
async onRequest({ options }) {
|
||||
const token = useCookie<string | null>("token", { path: "/" }).value
|
||||
const auth = useAuthStore()
|
||||
const token = auth.getStoredToken()
|
||||
|
||||
// Falls im Request explizit ein anderer JWT übergeben wird
|
||||
if (options.context?.jwt) {
|
||||
|
||||
@@ -43,7 +43,11 @@ export const useAuthStore = defineStore("auth", {
|
||||
.map((part) => part.trim())
|
||||
.find((part) => part.startsWith("token="))
|
||||
|
||||
return tokenCookie ? decodeURIComponent(tokenCookie.slice("token=".length)) : null
|
||||
if (tokenCookie) {
|
||||
return decodeURIComponent(tokenCookie.slice("token=".length))
|
||||
}
|
||||
|
||||
return localStorage.getItem("token")
|
||||
},
|
||||
|
||||
clearScopedTokenCookies() {
|
||||
@@ -164,6 +168,14 @@ export const useAuthStore = defineStore("auth", {
|
||||
this.clearScopedTokenCookies()
|
||||
this.tokenCookie().value = token
|
||||
|
||||
if (process.client) {
|
||||
if (token) {
|
||||
localStorage.setItem("token", token)
|
||||
} else {
|
||||
localStorage.removeItem("token")
|
||||
}
|
||||
}
|
||||
|
||||
if (!token) {
|
||||
this.clearSessionTimers()
|
||||
this.sessionWarningVisible = false
|
||||
|
||||
Reference in New Issue
Block a user