current user in middleware
is it possible to get the current user data in the middleware?
6 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
Which auth and which framework? Here's middleware working with convex auth in a next template: https://github.com/get-convex/v1/blob/76e705b8dc78c3da702cceba999f5c1b2a35b663/apps/app/src/middleware.ts
ah yes sorry, the question was a bit vague 😅
working with nextjs and convex auth and wondering if it's possible to get some data (from the db) of the current user, if there's a way to access it
You can always do this by adding your own query that loads the user based on auth and call it via
fetchQuery
since you'll have the access token in your Next.js middleware.
We may one day build a function like this into Convex Auth + a nice syntax to fetch it, but writing your own query should hopefully get you the same behavior nowty that worked perfectly
Thanks it helped a lot @sshader