You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{Amplify}from'aws-amplify'importconfigfrom'~/amplifyconfiguration.json'constunprotectedRoutes=['index','signin','signup','recovery','cause-areas','demo-amplify','cookie-policy','privacy-policy','recovery-confirm','terms-of-service',]exportdefaultdefineNuxtPlugin({name: 'AmplifyAuthRedirect',enforce: 'pre',setup(){addRouteMiddleware('AmplifyAuthMiddleware',defineNuxtRouteMiddleware(async(to)=>{try{// if we're running on the client, initialize Amplifyif(process.client)Amplify.configure(config,{ssr: useRuntimeConfig().public.ssrEnabled})// does the user have a valid session?// !! deleted users still possess valid tokens for 1 hour (Cognito "feature")const{ userId }=awaituseAuth().getCurrentUser()// if the user has a valid session, fetch their user dataif(userId){// !! testing simple getUser with Id query via vue-querytry{constTESTINGTHIS=awaituseQueryWrapper()// 👈 Doesn't work!useLogger().info('useQueryWrapper',TESTINGTHIS)}catch(e){useLogger().error('useQueryWrapper error',e)}// existing pinia-based implementationif(useAuthStore().isLoggedIn===false){// if not, fetch it from the APIawaituseAuthStore().fetchCurrentUser(userId)}if(to.name==='signin')returnnavigateTo('/feed')}}catch(e){if(einstanceofError&&'code'ine){if(e.code==='NotAuthorizedException'){useLogger().error('NotAuthorizedException')return}}if(!unprotectedRoutes.includes(to.name))returnnavigateTo('/signin')}}),{global: true},)},})
Describe the bug
Hi! Thanks for all your great work on this plugin :)
I'm struggling with just one specific implementation.
I'm able to call useQueryWrapper in the setup block of one of my pages.
I'm able to call useQueryWrapper in my Pinia store (I <3 Pinia, but I'm tryna replace it with vue-query, so I'm really only calling useQueryWrapper from inside pinia as a test...)
In my my authStore.ts (pinia), I can successfully do this:
useQueryWrapper().then((data)=>{console.log("Hai antfu, posva, and herbilicious! ",data)})
I'm unable to call useQueryWrapper from inside the global middleware I create in the plugin I've shared above.
If I could, I'd implement that whole plugin differently, but this is the specific way that the AWS Amplify documentation insists that we implement a routeGuard with SSR + Nuxt3 + Amplify.
I did do lots of digging and searching, and I found this: TanStack/query#5533
I don't understand how we're not getting any context from inside a plugin...I'm just confused (and probably a bit of a newb).
Based on that discussion, I even tried to do useNuxtApp().runWithContext(async () => await useQueryWrapper()) from inside the 03.auth-redirect.ts plugin.
I'm totally stuck. Would you happen to have any suggestion or idea as to how I can get this working. I'm sure that I'm missing something stupid/ovious, but it's 4AM here and I'm already starting to lose it 😂
Thank you for any help or direction you may be able to provide! 🙌🏼
Additional context
No response
Logs
03.auth-redirect.ts:45 [ERROR] 24:03.34 DEV - useQueryWrapper error Error: vue-query hooks can only be used inside setup() function or functions that support injection context.
at useQueryClient (useQueryClient.ts:9:11)
at useQueryWrapper (useQueryWrapper.ts:5:23)
at wrappred (function-metrics-helpers.mjs:42:17)
at 03.auth-redirect.ts:41:62
at executeAsync (index.mjs:111:19)
at 03.auth-redirect.ts:41:51
at async router.js:138:39
The text was updated successfully, but these errors were encountered:
Environment
Reproduction
composables/useQueryWrapper.ts
plugins/03.auth-redirect.ts
Describe the bug
Hi! Thanks for all your great work on this plugin :)
I'm struggling with just one specific implementation.
useQueryWrapper
in the setup block of one of my pages.useQueryWrapper
in my Pinia store (I <3 Pinia, but I'm tryna replace it withvue-query
, so I'm really only callinguseQueryWrapper
from inside pinia as a test...)In my my authStore.ts (pinia), I can successfully do this:
useQueryWrapper
from inside the global middleware I create in the plugin I've shared above.If I could, I'd implement that whole plugin differently, but this is the specific way that the AWS Amplify documentation insists that we implement a routeGuard with SSR + Nuxt3 + Amplify.
I did do lots of digging and searching, and I found this: TanStack/query#5533
I don't understand how we're not getting any context from inside a plugin...I'm just confused (and probably a bit of a newb).
Based on that discussion, I even tried to do
useNuxtApp().runWithContext(async () => await useQueryWrapper())
from inside the03.auth-redirect.ts
plugin.I'm totally stuck. Would you happen to have any suggestion or idea as to how I can get this working. I'm sure that I'm missing something stupid/ovious, but it's 4AM here and I'm already starting to lose it 😂
Thank you for any help or direction you may be able to provide! 🙌🏼
Additional context
No response
Logs
The text was updated successfully, but these errors were encountered: