-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remember profile after page change SSR
- Loading branch information
1 parent
b106b21
commit 98a617d
Showing
7 changed files
with
78 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// middleware/auth.ts | ||
const store = userStore(); | ||
const isAuth = computed(() => store.isLoggedIn); | ||
export default defineNuxtRouteMiddleware(async (to, from) => { | ||
if (import.meta.server) return; | ||
if (!isAuth.value) return; | ||
try { | ||
await store.getBasicInfo(); | ||
if (!isAuth.value) { | ||
return navigateTo("/"); | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
return navigateTo("/"); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Plugin identity-auth.ts | ||
export default defineNuxtPlugin((nuxtApp) => { | ||
const store = userStore(); | ||
const authCookie = useCookie("access_token"); | ||
|
||
if (import.meta.server) { | ||
// En el servidor, verifica si existe el token | ||
store.isLoggedIn = !!authCookie.value; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters