N
Nuxtβ€’2y ago
formigueiro

Pinia its not showing my store

I'm using nuxt 3 and I want to persist the pinia store data when switching pages with SSr, I installed pinia-plugin-persistedstate but I don't know how to register this plugin in the application, can someone help me?
No description
No description
21 Replies
formigueiro
formigueiroOPβ€’2y ago
No description
Likonima
Likonimaβ€’2y ago
Where are you using the store? Also no need to persist between pages
formigueiro
formigueiroOPβ€’2y ago
wow worked
Likonima
Likonimaβ€’2y ago
This would be for reloading the page or reopening. It would read from the defined store. Default is cookies
formigueiro
formigueiroOPβ€’2y ago
to show i need to to put on setup, for example login.vue
Likonima
Likonimaβ€’2y ago
🧐 There is no need to persist
formigueiro
formigueiroOPβ€’2y ago
One thing I noticed, when persisting it removes it from devtools and keeps it by default in cookies
Likonima
Likonimaβ€’2y ago
Why are you persisting in the first place ?
formigueiro
formigueiroOPβ€’2y ago
i need to persist data to manage authenticates routes i need to check getter
Likonima
Likonimaβ€’2y ago
You could just store the token in a cookie or localstorage yourself
formigueiro
formigueiroOPβ€’2y ago
logged
Likonima
Likonimaβ€’2y ago
No need for a plugin
formigueiro
formigueiroOPβ€’2y ago
yes, but i could to created a getter logged to show true or false what do you mean, pinia?
Likonima
Likonimaβ€’2y ago
But you dont wanna store the whole user in a cookie You would only store a token
formigueiro
formigueiroOPβ€’2y ago
im not storing whole user im storing only token and setting a getter
Likonima
Likonimaβ€’2y ago
Look at the useCookie composable from nuxt There is no need for a store
formigueiro
formigueiroOPβ€’2y ago
showing cookies, my pinia data its encoded
No description
Likonima
Likonimaβ€’2y ago
Username john doe is encoded? πŸ’€ Check the useCookie composable and use that to store and read a cookie The store is not necessary
formigueiro
formigueiroOPβ€’2y ago
so i could just use usecookie? @Likonima I'm coming to vue2 and there we had the mixins that were shared throughout the application, I don't want to instruct usecookies all the time and get this data. I wanted to create a looged: true or false mixin based on this cookie, is it possible?
Likonima
Likonimaβ€’2y ago
yeah i see you still have to call the store though you can do that without the persisted plugin though and directly use the composable in the store
formigueiro
formigueiroOPβ€’2y ago
how could i do that, would i create a composable/auth.ts and create a useState? i have this composabled auth.ts
export const useAuth = () => useState(() => {
const [cookies] = useCookies(['auth'])
})
export const useAuth = () => useState(() => {
const [cookies] = useCookies(['auth'])
})
but im getting usecookies its no defined
Want results from more Discord servers?
Add your server