How can I get the users JWT token after logging when using the Nuxt module?
Hey, i'm using the Nuxt module and I am trying to get the JWT token after login so I can pass it through to my Cloudflare Workers API in the Authorization header. Is this possible? I can't find anything in the Nuxt Module documentation that says how to access the token.
3 Replies
There is a composable called
useKindeClient
. There is an async method called getToken()
. Use that to get your jwt.
I realise that intellisense/documentation is severely lacking...Thanks! That worked for me. In case anyone else has a similar issue I implemented it by adding this to my
app.vue
:
This makes sure the token
is also provided to the client for subsequent API calls. You can then use it in your API requests like so:
[nuxt] A composable that requires access to the Nuxt instance was called outside of a plugin, Nuxt hook, Nuxt middleware, or Vue setup function. This is probably not a Nuxt bug. Find out more at
https://nuxt.com/docs/guide/concepts/auto-imports#vue-and-nuxt-composables
.
When I added the above code to my app.vue to add token handling globally, this occurred. It appears as though my useKindeClient() composable calls are returning a null client, despite being logged in - bizarre.