Next.js Discord

Discord Forum

Can we pass props through middleware

Unanswered
shaurya#007 posted this in #help-forum
Open in Discord
Avatar
I am authenticating uses in middleware using jwt , can i pass user data to routes after authentication ?

19 Replies

Avatar
Kawakawa
What data are you trying to pass to the user?
As you can't with middleware directly pass data to other parts of the application.
Avatar
Ok, actually I am learning next js. I want to implement role based authentication.
Can you suggest some methods.

I tried with nextAuth but the package is depreciated.
I want to extract user id form jwt, fetch user data with that and then provide the data to routes
Avatar
Kawakawa
What data are you fetching, though
Is it a large object?
Avatar
No, it is a single JSON object .
I am fetching it from a mongo server
Avatar
Kawakawa
What is the data??! 😂
Is it their profile? Is it their role stuff?
Avatar
Yes
Avatar
Kawakawa
"I tried with nextAuth but the package is depreciated."
That is very much not the case, what do you mean it's deprecated?
Avatar
Image
Avatar
Kawakawa
That package name doesn't look right. Check the usage on the official next-auth webpage: https://next-auth.js.org/
Avatar
I did checked that
Image
Avatar
Kawakawa
No, check how you're using the package.
Avatar
It is working with next-auth version 4.22.1
I am new to next, is it a good framework for backend? Or I should stick with express
For backend