[ConvexAuth] getting jwtToken to pass to auth headers in fetch on client
Is there a way to get the jwtToken client side when authenticated, when using convex auth? i'd like to pass it in the auth headers of a fetch request from my client
Like for example with clerk you could do something like:
16 Replies
I'm trying to secure this http action:
Why not use an action instead of an http route?
Yeah not currently exposed (we made https://github.com/get-convex/convex-auth/issues/38 to track).
In terms of workarounds for now, you could go for this path using
storage.generateUploadUrl
(https://docs.convex.dev/file-storage/upload-files#uploading-files-via-upload-urls), and check auth in the mutation that produces the upload URL, or potentially switch to a normal action (and be okay with only being able to upload files up to 8MB with no streaming to fall under the function argument size limits)Uploading and Storing Files | Convex Developer Hub
Files can be uploaded by your users and stored in Convex.
They are not intended to be called client side, as far as i understand?
Went ahead and read the docs on the subject again. Def had it twisted the way i set it up. Now it works just how i want it.
@oscklm you can now authenticate HTTP actions with the useAuthToken hook.
https://labs.convex.dev/auth/authz#authenticate-http-actions
Authorization - Convex Auth
Authentication library for your Convex backend
Awesome stuff Michael! Thanks for the heads up
@Michal Srb so does this mean Next JS server components, including middleware.ts is now supported in Convex Auth?
@samtalksAI there’s an alpha release, check it out and share any feedback: Try out the Next.js alpha:
npm i @convex-dev/auth@0.0.48-alpha.0
@Michal Srb sure thing! Doc still the same right? https://labs.convex.dev/auth/setup
Any articles on stack to go over this in more clarity or was the auth example repo updated to show the server side stuff?
Set Up Convex Auth - Convex Auth
Authentication library for your Convex backend
The docs have the instructions, starting from Setup. And there's a test-nextjs demo in the convex-auth repo.
https://docs.convex.dev/api/classes/browser.ConvexHttpClient
After authorization, where can I get a token so that I can transfer it to my backend, where it will process the request?@Michal Srb
Class: ConvexHttpClient | Convex Developer Hub
browser.ConvexHttpClient
Authorization - Convex Auth
Authentication library for your Convex backend
That's not it. I'm using
I had to look for these functions under the hood, there is no such information in the documentation or I missed it... I need to access your backend through the backend of my server. And get a token and not a frontend one
There's an alpha out for Next.js. Can you open a new thread and describe all the relevant details? (What's your fronted, what's your additional server)
@Michal Srb only astro ssr + integrated vue
so I do something like
We don't have SSR support for this in Astro. You can look at how the Next.js integration works and try to replicate it for Astro (1. proxy auth actions through the astro server, 2. store tokens in cookies).