Next.js Discord

Discord Forum

Can we pass props through middleware

Unanswered
shaurya#007 posted this in #help-forum
Open in Discord
Avatar
shaurya#007OP
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
shaurya#007OP
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
shaurya#007OP
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
shaurya#007OP
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
shaurya#007OP
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
shaurya#007OP
I did checked that
Image
Avatar
Kawakawa
No, check how you're using the package.
Avatar
shaurya#007OP
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