-
-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(nuxt): avoid calling runWithContext (#334)
* fix(nuxt): avoid calling runWithContext * fix: infer `CookieStorageOptions` from `@nuxt/schema` rather than `nuxt/schema`
- Loading branch information
Showing
8 changed files
with
100 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const useTokenStore = defineStore('token', () => { | ||
const token = ref('') | ||
|
||
return { token } | ||
}, { | ||
persist: true, | ||
}) |
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,11 @@ | ||
export default defineNuxtRouteMiddleware((to) => { | ||
const tokenStore = useTokenStore() | ||
|
||
if (!tokenStore.token && to.path !== '/login') { | ||
return navigateTo('/login') | ||
} | ||
|
||
if (tokenStore.token && to.path === '/login') { | ||
return navigateTo('/page') | ||
} | ||
}) |
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,44 @@ | ||
<script setup lang="ts"> | ||
const cookieStore = useCookieStore() | ||
const localStorageStore = useLocalStorageStore() | ||
const sessionStorageStore = useSessionStorageStore() | ||
</script> | ||
|
||
<template> | ||
<main> | ||
<label for="cookie">{{ cookieStore.$id }}</label> | ||
<input id="cookie" v-model="cookieStore.username"> | ||
<label for="local">{{ localStorageStore.$id }}</label> | ||
<input id="locale" v-model="localStorageStore.username"> | ||
<label for="session">{{ sessionStorageStore.$id }}</label> | ||
<input id="session" v-model="sessionStorageStore.username"> | ||
</main> | ||
</template> | ||
|
||
<style scoped> | ||
main { | ||
max-width: 600px; | ||
padding: 10px; | ||
display: grid; | ||
grid-template-columns: auto 1fr; | ||
gap: 10px; | ||
} | ||
label { | ||
margin: auto 0 auto auto; | ||
} | ||
input { | ||
border-radius: 5px; | ||
border-width: 2px; | ||
border-style: solid; | ||
border-color: #585b70; | ||
background-color: transparent; | ||
color: inherit; | ||
font-size: inherit; | ||
} | ||
input:focus-visible { | ||
outline: #cba6f7 2px solid; | ||
} | ||
</style> |
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,17 @@ | ||
<script setup lang="ts"> | ||
const tokenStore = useTokenStore() | ||
async function login() { | ||
tokenStore.token = 'loginToken' | ||
await navigateTo('/page') | ||
} | ||
</script> | ||
|
||
<template> | ||
<main> | ||
<h1>Login page</h1> | ||
<button @click="login"> | ||
Login | ||
</button> | ||
</main> | ||
</template> |
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,14 @@ | ||
<script setup lang="ts"> | ||
async function goToLogin() { | ||
await navigateTo('/login') | ||
} | ||
</script> | ||
|
||
<template> | ||
<main> | ||
<h1>home page</h1> | ||
<button @click="goToLogin"> | ||
To Login Page | ||
</button> | ||
</main> | ||
</template> |
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