Get auth state everywhere via Nuxt 3? #4932
Replies: 2 comments 3 replies
-
Digging in more, it seems like I need to use the custom auth store capability + Nuxt state somehow. Or onChange and have that trigger state changes. |
Beta Was this translation helpful? Give feedback.
-
If you want to listen to const removeListener = pb.authStore.onChange((token, model) => {
console.log('store data:', token, model)
}, true); // the true flag fires the callback immediately after registration
...
removeListener(); It is not clear in what context the above executes but note that it is safe to have a global SDK instance only on the client-side (eg. in the browser as SPA). If the above executes in a long running node process, it will be vulnerable because requests from different users will modify the same |
Beta Was this translation helpful? Give feedback.
-
I put the following in
utils/pocketbase.js
In my
app.vue
I have the following:Finally, in a login page
pages/login.vue
I simply do this:This does not add my logout button unless I F5 the whole page.
I assume that is because
<script setup
runs once...Do I need to put
pocketbase.authStore.isValid
in state? If so, how does state know when isValid changes?Beta Was this translation helpful? Give feedback.
All reactions