next-auth

Im working on auth in this next app using next auth with google and credentials providers, and custom sign in and register page . I definitely don't knw if I'm doing it in the right safest way to prevent my data from attackers. I made only the
play
play
route redirect u to the login page when u're not logged in i'll do the same for the rest of the pages later except blogs, home, sign in routes Also the dashboard route will be protected route with user based auth
For now i wanna knw if my method is correct or not and what the things that i missed or did wrong. This is the github repo pls feel free to check it out : https://github.com/CLOG9/PuzChess/tree/main
GitHub
GitHub - CLOG9/PuzChess: a new chess puzzles platform made with nex...
a new chess puzzles platform made with next js. Contribute to CLOG9/PuzChess development by creating an account on GitHub.
261 Replies
Lumberjack
Lumberjack15mo ago
@smolcheeld
KP
KP15mo ago
you on app dir or pages dir ?
Lumberjack
Lumberjack15mo ago
App Check the repo
KP
KP15mo ago
u can write a middleware to do it as well. this way isnt too bad tho i have done this way personally a few times as well in the form of making a HOC that redirects to other pages this is the better way to do it tho. google around for some examples for this
Lumberjack
Lumberjack15mo ago
I saw how to make middleware Just two lines of code and u did it
KP
KP15mo ago
yea do that then, its a safer option than HOC
Lumberjack
Lumberjack15mo ago
Really?
KP
KP15mo ago
yes
Lumberjack
Lumberjack15mo ago
I thought the HOC is safer
KP
KP15mo ago
btw u will still have to check if user is auth to make typescript happy for either way
Lumberjack
Lumberjack15mo ago
Wdym
KP
KP15mo ago
next auths useSession hook that returns data it wont know if ur middleware has checked for it or not i believe so ts will show data returned by useSession as session | null
Lumberjack
Lumberjack15mo ago
Aaaah okay i got it So i don't need getServerSession? For the admin panel
KP
KP15mo ago
yea its not needed thats one of the advantages of middleware, u dont need to make HOCs for diff scenarios
Lumberjack
Lumberjack15mo ago
Or just i have to make special key in the .env file for the admin user? Yeh i'll use middleware then
Want results from more Discord servers?
Add your server