Тёмный

Set up Next-Auth with Next.js and Prisma with this ultimate guide! 

Build SaaS with Ethan
Подписаться 7 тыс.
Просмотров 52 тыс.
50% 1

This is the ULTIMATE guide for setting up Next Auth with the credential provider and Prisma. Check out my other video for setting up Prisma and then dive in to hook it all up.
Learn how to protect routes, get session information, and configure everything so you can fully use Next Auth.
ALL IN THE APP DIRECTORY!
Let's go!
🔖 Chapters 🔖
00:00 - Intro
01:18 - Overview and Install
02:10 - Set up Next Auth Route
06:55 - Get Session Data
14:22 - Connect with Prisma
17:40 - Authorize function with Prisma
23:46 - Update session JWT with new data
33:22 - Protected Routes
41:55 - Outro
📜 Code 📜
• github.com/ethanmick/next-aut...
📚 Resources 📚
• Setup Prisma: • How to set up Prisma w...
• Next.js API Routes: • FIRST LOOK! Next.js Ap...
🔗 Links 🔗
• Next.js: nextjs.org/
• Next Auth: next-auth.js.org/
• Prisma: www.prisma.io/
👨🏼‍💻 About Me 👨🏼‍💻
I am a principal software engineer and architect who loves building cool cloud software.
• Blog: ethanmick.com/
• Hire Me: ethanmick.dev/

Наука

Опубликовано:

 

8 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 320   
@ethan_mick
@ethan_mick Год назад
>>>>> UPDATE
@yoayopersibbandung2685
@yoayopersibbandung2685 Год назад
build crud admin dashboard and midleware homepage please, i like your tutorial
@alariclg
@alariclg Месяц назад
Thank's for this explicit tutorial !
@baybay1234
@baybay1234 Год назад
I really like how you breakdown a complex concept in a step by step format. Especially the part where you talk about the three different ways of getting session data and their respective use case. It’s very clear and informative. Instant sub for me right there
@ethan_mick
@ethan_mick Год назад
Thanks! I try to think through the best ways to make a complicated topic approachable. Let me know if you have any questions!
@cb73
@cb73 Год назад
If I start doing tutorials you’re the exact person I would be looking to emulate. GREAT job!
@ethan_mick
@ethan_mick Год назад
Wow, thank you!! That is such a nice compliment. I'm just doing what I can to help people out :)
@shockgalaxy9849
@shockgalaxy9849 9 месяцев назад
Hands down the best auth video about next and next-auth I've ever seen. You've got a new subscriber. Thank you so much!
@ethan_mick
@ethan_mick 9 месяцев назад
Glad it helped you out!
@Mantenner
@Mantenner 9 месяцев назад
Legendary mate, just finished up this one and your explanations are flawless as usual, can't wait to get onto the next one! This content is golden.
@ethan_mick
@ethan_mick 9 месяцев назад
Thanks a ton!
@PM-4564
@PM-4564 10 месяцев назад
This tutorial was on another level of prepared/concise. I like the showing multiple ways to do do protected routes, and the error notice related to loading bcrypt in the client bundle.
@ethan_mick
@ethan_mick 10 месяцев назад
Thank you! I normally try to make the tutorials "error free" but some errors are so common they even catch me and I'm like "Oh yeah, this is definitely going to get someone else" haha.
@fujisan0388
@fujisan0388 Год назад
This is a great tutorial! You seem like a natural teacher and RU-vidr, please keep them coming.
@ethan_mick
@ethan_mick Год назад
Thank you! I'll keep them coming!
@TheGaoNan
@TheGaoNan Год назад
The way you are explaining everything is top notch, best tutorial I've found on RU-vid, of course I've subbed!
@ethan_mick
@ethan_mick Год назад
Thank you! That means a lot 😊
@dawidu8656
@dawidu8656 Год назад
Been looking for something like this for some time now, I'm glad I found you since this really explains everything I needed in great detail. Thank you :)
@ethan_mick
@ethan_mick Год назад
Thank you! There's a lot here, but once you get it working it's so satisfying.
@younesalturkey
@younesalturkey 7 месяцев назад
I got phenomenal value out of this video ! Thank you, Ethan.
@younesalturkey
@younesalturkey 7 месяцев назад
Thank you! You 10x my auth game .
@muhammadisa440
@muhammadisa440 9 месяцев назад
Thank you very much Ethan. I really like your fast forward pace. Much much appreciated
@ethan_mick
@ethan_mick 9 месяцев назад
Thanks, haha. I didn't want it to take too long
@levantos
@levantos Год назад
Really well thought out and well explained tutorial Ethan. Really helped with my understanding with setting up Next-Auth with the latest versions of Next :)
@ethan_mick
@ethan_mick Год назад
Thanks! I'm glad I could help out :)
@user-te2pe5qm8o
@user-te2pe5qm8o Год назад
I'm looking for this video for several days, Thanks a lot!
@ethan_mick
@ethan_mick Год назад
I'm glad I could help! Let me know if you need anything else!
@amirhosseinshahabnia
@amirhosseinshahabnia Год назад
In this week, I have been struggling to learn auth with next-auth and prisma. This has been super helpful, thanks a lot!
@ethan_mick
@ethan_mick Год назад
You're very welcome! I'm glad I could help.
@marcelo-3k
@marcelo-3k 11 месяцев назад
there we go! thank you so much for this! u are amazing
@ethan_mick
@ethan_mick 11 месяцев назад
Heck ya! Glad I could help!
@aswnss2688
@aswnss2688 5 месяцев назад
Really great content and explained really well
@noeldolan518
@noeldolan518 6 месяцев назад
Great tutorial, thank you! :)
@matthewgregerson1447
@matthewgregerson1447 10 месяцев назад
Awesome guide Ethan! Love your work.
@ethan_mick
@ethan_mick 10 месяцев назад
Thanks so much!
@dwolrdcojp
@dwolrdcojp 6 месяцев назад
This was a really comprehensive video on everything you need to get next auth set up. We're doing exactly the same thing in our enterprise SaaS. Currently exploring the new @auth package which next-auth is moving to, would be great to see you do an update video on this one with the new auth beta package (if you already haven't).
@bogdan.c
@bogdan.c Год назад
Thank you! This was an awesome tutorial. Keep 'em coming! 👍
@ethan_mick
@ethan_mick Год назад
Thanks, will do!
@Benicioplay6y
@Benicioplay6y Месяц назад
Dude you are life saver man
@ignacioportigliatti2794
@ignacioportigliatti2794 Год назад
You are my Angel man ! Thanks for this excellent explaination, was stuck like 4 days with NextAuth but this video resolved my problem in just 40 minutes. Thanks thanks !
@ethan_mick
@ethan_mick Год назад
Great to hear!
@s.bamahfoodh
@s.bamahfoodh 5 месяцев назад
You are amazing man 🍾
@user-hk3zk2of9j
@user-hk3zk2of9j 5 месяцев назад
You are the best dude!
@1989amcm
@1989amcm Год назад
Thank you so much for this!
@ethan_mick
@ethan_mick Год назад
You're so welcome!!
@phil5293
@phil5293 10 месяцев назад
Awesome Nextjs, NextAuthjs tutorial. Keep it up
@ethan_mick
@ethan_mick 10 месяцев назад
Thank you!
@hasifzulkifli5416
@hasifzulkifli5416 Год назад
this channel will blow up soon, sit tight buddies! Thanks for the info sharing mate!
@ethan_mick
@ethan_mick Год назад
Thank you! I'm just gonna keep making great content in the meantime :)
@dronia1590
@dronia1590 10 месяцев назад
Amazing explanation! Thank you so much
@ethan_mick
@ethan_mick 10 месяцев назад
You are welcome!
@mouadhnida4639
@mouadhnida4639 9 месяцев назад
You are really the best tutor I have ever seen . First video about next-auth that is complete thank you
@ethan_mick
@ethan_mick 9 месяцев назад
Glad you think so!
@francogalfras9041
@francogalfras9041 7 месяцев назад
Thanks for the video! It was really helpful! 😀
@Roschl
@Roschl 9 месяцев назад
Thanks for this awesome tutorial :)
@ethan_mick
@ethan_mick 9 месяцев назад
You're very welcome!
10 месяцев назад
Great video man, found this in reddit and is just what I needed to handle users in my project!
@ethan_mick
@ethan_mick 10 месяцев назад
Thanks, Reddit (for real). I haven't been super active since I don't want to spam self-promo but I try to make useful things. Glad it helped!
@andrescampos8333
@andrescampos8333 11 месяцев назад
Great work, thank you
@ethan_mick
@ethan_mick 11 месяцев назад
You are very welcome!
@codiumyt
@codiumyt 9 месяцев назад
This video is extremely well done, and set me up perfectly for my webapp. Thank you, truly.
@ethan_mick
@ethan_mick 9 месяцев назад
You're very welcome!
@cidhighwind8590
@cidhighwind8590 Год назад
The best video ive found on this topic. Im subbin!
@ethan_mick
@ethan_mick Год назад
Thank you so much!
@stanislavus
@stanislavus Год назад
Excellent tutorial. Clear and concise, thank you
@ethan_mick
@ethan_mick Год назад
Thank you!!
@hoanghai6690
@hoanghai6690 9 месяцев назад
you save my life. the tutorial is super informative & easy to follow up.
@ethan_mick
@ethan_mick 9 месяцев назад
Glad to hear that!
@joeyhills212
@joeyhills212 11 месяцев назад
by far the best App directory Next-auth tutorial to date. And you made it while the build was still in beta LOL.
@ethan_mick
@ethan_mick 11 месяцев назад
Haha, I know, it still holds up pretty good! Thanks :)
@tunaralyarzada
@tunaralyarzada Год назад
really, this was one of the best tutorial for next auth ever. u explained this content very clearly. thank u so much. i appreciate it and i would like u to go ahead and make video about api at crud process in next 13
@ethan_mick
@ethan_mick Год назад
Thank you, I'm glad you found it helpful! Yes, I'll add that to my list and work on it!
@alicodes22
@alicodes22 Год назад
Hi Ethan, your videos are amazing 🔥💯
@ethan_mick
@ethan_mick Год назад
Thank you so much! I’m glad you like them!
@malcolmvernon6808
@malcolmvernon6808 10 месяцев назад
this is really helping me. thank you
@ethan_mick
@ethan_mick 10 месяцев назад
Glad I could help!
@daviddavis1173
@daviddavis1173 10 месяцев назад
Great tutorial! Lots of good information in this video. I also like your presentation style. You never cover the user registration process so I will bring this tutorial down from 'ultimate' to 'almost ultimate' but it was still worth the watch!!
@ethan_mick
@ethan_mick 10 месяцев назад
Haha, that's fair. Next-Auth takes the stance that registration is outside the scope of Authentication (which is true for OAuth). I created a video on making a custom register page that also covers saving the user with Prisma here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-HVFMc5Ac1F8.html
@lawfal6203
@lawfal6203 10 месяцев назад
OMG thanks Ethan... i already desperate learning about authentication
@ethan_mick
@ethan_mick 10 месяцев назад
Glad I could help! It's a big subject with lots of nuance. Let me know how else I can help!
@chenenpei
@chenenpei Год назад
Super helpful! Thank you!
@ethan_mick
@ethan_mick Год назад
You're welcome!
@Grishopping
@Grishopping Год назад
Thank you friend ......... the way you explain... now I have a clearer vision... before I understood it in a general way but you made me understand it step by step... thanks again Att. Jose Grillo
@majedyafa902
@majedyafa902 Год назад
This channel should be subscribed! You are awesome in simplifying things.
@ethan_mick
@ethan_mick Год назад
Thank you so much 😀
@TheLoloS
@TheLoloS Год назад
Love you man! ❤
@ethan_mick
@ethan_mick Год назад
Thank you!!
@rawcoders
@rawcoders Год назад
thanks for great videos 🙏
@ethan_mick
@ethan_mick Год назад
Thank you!
@luckyvictory6617
@luckyvictory6617 11 месяцев назад
Well explained ❤
@ethan_mick
@ethan_mick 11 месяцев назад
Glad it was helpful!
@ataidenb
@ataidenb Год назад
Nice nice nice... amazing video, thanks Ethan.
@ethan_mick
@ethan_mick Год назад
Thank you so much!
@sdsim1
@sdsim1 Год назад
Nice content, thanks for this video ! 👏
@ethan_mick
@ethan_mick Год назад
Thanks, glad you liked it!
@rayjonathan2889
@rayjonathan2889 3 месяца назад
Bro, Thankyou so much for the tutorial. Hope u have a good day, good life, and everything good because i could make a login page using credentials now. GOD BLESS YOU SO MUCH BRO!!!!!!!!!!!!!!!!!!!!
@manishankarvakta
@manishankarvakta 4 месяца назад
Nice Video, Thanks
@olatech7252
@olatech7252 Год назад
Thank you Next Auth for good guide.
@ethan_mick
@ethan_mick Год назад
Glad you liked it!
@raphauy
@raphauy Год назад
Thank you ver much!!!
@ethan_mick
@ethan_mick Год назад
You're welcome!
@daphnesplyntr
@daphnesplyntr Год назад
This works very well. Thank you
@ethan_mick
@ethan_mick Год назад
Glad it helped!!
@personzen8028
@personzen8028 Год назад
thank you so much for the great job you do, greetings from morocco.
@ethan_mick
@ethan_mick Год назад
Thank you so much!
@jeffg56
@jeffg56 Год назад
amazing tutorial
@ethan_mick
@ethan_mick Год назад
Thank you!
@lightninginmyhands4878
@lightninginmyhands4878 Год назад
Thank you so much!
@ethan_mick
@ethan_mick Год назад
Glad it helped!
@mascode.
@mascode. 6 месяцев назад
thanks a lot!
@athulgeorge4873
@athulgeorge4873 Год назад
This was the most in-depth tutorial for NexAuth with NextJS I have seen. Really great work, you explained everything very clearly. I have no doubt this chanell will blow up. Just wondering if you could maybe cover the T3 stack and how to handle redirects to a specified page when unauthenticated (instead of just to the signin page) and how you would use the credentialProvider with email and password with the T3 stacks session tokens. Thanks again for the great video.
@ethan_mick
@ethan_mick Год назад
Thank you! I'll add the T3 stack to my list and make some content around how to do those things. For handling the redirect when unauthenticated, you should be able to use `redirect` (server component) or the useSession hook and point the user to any page you want. I used the login page here, but it could be a different one. I'll make a followup video for creating a custom login page and show how to redirect to that.
@simonhblanco
@simonhblanco Год назад
There are a lots of tutorial but this is the best tutorial for next auth ever. !!! keep going like that.
@ethan_mick
@ethan_mick Год назад
Thank you so much!
@simonhblanco
@simonhblanco Год назад
@@ethan_mick Small question.. How do you avoid that the user open two or more tabs at same time. "Duplicate Tabs". ?
@ethan_mick
@ethan_mick Год назад
@@simonhblanco Hmm, I'm not quite sure what you mean. Any user might be on your site and using multiple tabs -- some products use that flow heavily. The cookies are shared between all tabs so authentication should Just Work. Could you clarify what the problem is?
@simonhblanco
@simonhblanco Год назад
@@ethan_mick Thanks for the answer!!! and Yes you are right!!!. For a normal page, where people just log in to watch a movie, it's ok, but imagine a gambling site. two tabs open at the same time, it can be a problem ... users will try to make simultaneous transactions. or on a bank page. Can something be done in authnext to avoid that?
@ethan_mick
@ethan_mick Год назад
@@simonhblanco That's outside the scope of what Next-Auth can do. Here's my recommendation -- anything that needs to be protected from simultaneous requests needs to be handled in the backend (API route or database). Because if simultaneous transactions can break the site, people will make thousands of requests from bots and get around your tab protection. So it needs to be handled on your backend with server protection not client-side protection.
@megamind452
@megamind452 Год назад
Well explained 👏
@ethan_mick
@ethan_mick Год назад
Thank you 🙂
@frankylopez4477
@frankylopez4477 7 месяцев назад
Thank you
@alowais900
@alowais900 9 месяцев назад
Hi Ethan! Really loved your series on setting up a NextJS app with Prisma, Postgres and Next-Auth. The way you delve into the background mechanics and offer contextual understanding is a huge plus for me! I'm not certain if this has been broached before, but possibly a video you can add to your backlog of ideas, is a video dedicated to handling dev/production environments. My primary intrigue lies in the nitty gritty of how to host a POSTGRES database and integrating it with the deployed NEXTJS app. One hurdle, i've been struggling to understand how to properly manage different environment variables and how to set it up properly for local vs production setups. Your insights on this would be golden! Or if you have any resources you could recommend on this topic, that would be super helpful too!
@Mantenner
@Mantenner 9 месяцев назад
Just to chime in as I've also been wondering this, I originally hosted my DB locally using postgres but recently switched to Amazon RDS by suggestion of a developer friend, it integrates almost identically to how Ethan showed in his first video, and was relatively easy to set up in RDS. My DB seeding and migrations also worked seamlessly! This also would allow deploying the actually application to be done separately to the DB (Although likely done on AWS, but really anything would work with the RDS connection string). Not sure if this helped you at all, but I do recommend giving Amazon RDS a go as it has a great free tier and is very well received. Regarding your point about the env variables, for local dev/things you don't want to commit to prod etc you can use the .env.local file, but I must say I'm a bit fuzzy on that myself, someone else with greater insight might be able to assist there.
@alowais900
@alowais900 9 месяцев назад
hi @@Mantenner, thanks for the recommendation. I'll definitely check out RDS. I've been playing around with .env variables for the last few days. Seems like there's a bit of a conflict on how Prisma and NEXTJS like to consume variables from those files.
@ethan_mick
@ethan_mick 9 месяцев назад
Thanks for the kid words, and great idea! Having a good understanding of how the environments work, how to set them up, and how to use variables between them is a great idea for a video. I'll work on that!
@MrPlaiedes
@MrPlaiedes 11 месяцев назад
Subbed. Great job!
@ethan_mick
@ethan_mick 11 месяцев назад
Thanks so much!
@kamichikora6035
@kamichikora6035 Год назад
Damn great content... This is damn great content
@ethan_mick
@ethan_mick Год назад
Thank you!
@ekimcemulger8101
@ekimcemulger8101 Год назад
Well done Ethan, the guides you are providing are up to date and clear ! Thank you for your effort
@ethan_mick
@ethan_mick Год назад
Glad you like them!
@robinvx1
@robinvx1 9 месяцев назад
23:27 "Thanks Chrome, so secure." Gets me every time 😄
@ethan_mick
@ethan_mick 9 месяцев назад
Right?? lol
@imtaxu
@imtaxu Год назад
I appreciate you very much, you have a very good command of the subject and your expression is very clear. Could you please next tutorial using next-auth and next-intl together?
@ethan_mick
@ethan_mick Год назад
Thank you! I've had this request before, I'll add it to the list!
@MrCone9
@MrCone9 7 месяцев назад
thanks for the video, I saw months ago and now I had to use, best youtube video about nextauth. I' thinking how to implement "enable/disable" user access, maybe with short JWT expiration...
@itsandyagain
@itsandyagain 11 месяцев назад
thanks for the help. As I'm sure you already know, much of the docs and tuts are outdated. I was pulling my hair out trying to get this to work
@ethan_mick
@ethan_mick 11 месяцев назад
Glad I could help! Yeah, I think it’s really helpful to step through all of these things end to end
@eliuddyn
@eliuddyn Год назад
Amazing 🔥🔥
@ethan_mick
@ethan_mick Год назад
Thank you!
@heychazza
@heychazza Год назад
After days of frustration with JWT and session stuff, your video solved it! Massive thanks, subbed! Clear and concise. Would be awesome to do a video on how we can use custom User types (for TS stuff) for sessions. E.g. getting rid of the default “image” property etc
@ethan_mick
@ethan_mick Год назад
Welcome and thank you! I'll do what I can to make a video on that, I think it would be a great blog post too. Thanks!
@justjeremiah4255
@justjeremiah4255 Год назад
This is precisely what i needed! Thanks!
@ethan_mick
@ethan_mick Год назад
Thank you! Glad I could help :)
@0xtz_
@0xtz_ Год назад
Now I need to change the my files 😂 I was waiting for this
@ethan_mick
@ethan_mick Год назад
lol, hope it’s not too much of a change!
@0xtz_
@0xtz_ Год назад
@@ethan_mick no just some few changes but gonna get a clean files
@Rutthawit
@Rutthawit Год назад
Thank you.
@ethan_mick
@ethan_mick Год назад
You’re welcome!
@austinwhitbeck3362
@austinwhitbeck3362 Год назад
Also would love to see your thoughts and process on adding CSS in JSX when things like Material UI and Chakra UI catch up with the server components :) Thanks again!
@ethan_mick
@ethan_mick Год назад
Will do! I've been doing a lot of Tailwind for my Server Components which works very well.
@tylerdrabek1592
@tylerdrabek1592 8 месяцев назад
If anyone else has an issue with the middleware not securing the pages you specify, make sure the middleware.ts file is at the same folder level as your root page. For me this was in my /src folder.
@eduardo.bernardo
@eduardo.bernardo Год назад
What an amazing tutorial! Could you explain (or maybe make a second video) about how to use Next Auth in a custom middleware (for example, a saas with custom subdomain settings)?
@ethan_mick
@ethan_mick Год назад
Yes! For my SaaS apps that are on subdomain (such as app.domain.com or dashboard.domain.com) I put all the Auth stuff *on* that subdomain as well. This means the cookies and everything will Just Work. If you don't do that, or you need to share the cookies across sub/domains you'll want to take a look at the Next Auth cookie options to configure all of this. next-auth.js.org/configuration/options#cookies
@oamarkanji3153
@oamarkanji3153 9 месяцев назад
@@ethan_mick Please look into using middleware to protect pages with the prisma adapter. It does not seem to work for me :(
@ethan_mick
@ethan_mick 9 месяцев назад
@@oamarkanji3153 are you using JWTs are database sessions?
@z1982_
@z1982_ 8 месяцев назад
Thanks a lot, amazing! Can you advise where on the doc it is showing how to set up the providers.tsx with the new app router ?
@nclsDesign
@nclsDesign Год назад
Why didn't RU-vid show me this yesterday when I was looking for exactly this??? I struggled with it all day, then managed to get it and now YouTuube recommends it to me. That's cyberbullying! Anyways, great video. Earned a sub!
@ethan_mick
@ethan_mick Год назад
Thank you so much! Sorry you were struggling, auth can be a pain to get right!
@Zechey
@Zechey Год назад
Nice video, learnt a lot. About the middleware though, what if we wanted to have other stuff as middleware? I tested it out and if I export default the other middlewares stop working. Do you have a video on that? Thanks.
@ethan_mick
@ethan_mick Год назад
I don't yet, but this is probably the trickiest thing when working with Middleware. I'll do what I can to make a video and try out a few ways. Do you have middleware you're using that you want to see merged together?
@yycode
@yycode Год назад
I see some people have a prisma database query inside the JWT function to obtain some additional information about the user. Is that a good practice? if the jwt function is going to run multiple times, would it cause performance issues to have a database query inside?
@ethan_mick
@ethan_mick Год назад
I would not put database logic inside the JWT encode/decode functions, those are called way too often. If the database query is only on token creation that's probably fine, assuming the tokens live for a few minutes. The database should easily be able to handle a simple SELECT query like that.
@dileepnagendra8199
@dileepnagendra8199 11 месяцев назад
Awesome
@ethan_mick
@ethan_mick 11 месяцев назад
Thank you!
@johnhuang4618
@johnhuang4618 8 месяцев назад
I really appreciate all your efforts in explaining these concepts. It's so helpful. But I do have a question about the client side session. It seems like all the extra info added isn't reflected on the session obtained via useSession(client side)?
@z1982_
@z1982_ 8 месяцев назад
Will the middleware strategy to protect the app wil also protect the API routes? Can we specify them in the config ?
@shawn-skull
@shawn-skull Год назад
Please make videos about deployments of that kind of projects, with migrations.
@ethan_mick
@ethan_mick Год назад
🫡 You got it
@kristiankanya431
@kristiankanya431 9 месяцев назад
Note that the middleware.ts file should be "at the root or in the src directory (same level as your pages)" (see: docs). I have an src directory (not sure if this the preferred way to set up the project!), so it had to go in there, rather than at the project root as shown in the video. Thx for the video.
@ethan_mick
@ethan_mick 9 месяцев назад
Very true! I normally don't use the `src` directory, but this is an excellent point.
@kristiankanya431
@kristiankanya431 9 месяцев назад
Do you think it's unnecessary? I wasn't sure. @@ethan_mick
@ethan_mick
@ethan_mick 9 месяцев назад
@@kristiankanya431 I personally don't use it because: 1. Most of Vercel's code doesn't, and if they don't do it, I didn't see the reason to 2. I like to keep my directory structure simple, so fewer is better 3. The `src` felt like it was legacy behavior and no longer necessary. That being said, if you like the organization it gives, that's fine! I prefer flatter directories, so I don't use it.
@kristiankanya431
@kristiankanya431 9 месяцев назад
@@ethan_mick Good points made, thanks. I will work on altering it.
@ronaldpaek
@ronaldpaek Год назад
Everything seems to work fine with the specific package version you provided, the only thing I couldn't get to work was the /localhost:3000/api route handler, when I was using the other 2 auth methods client side and server side, but when I used the middleware technique at the very end now /api seems to work.
@ethan_mick
@ethan_mick Год назад
Glad it works at least at the end!
@ICOReviewtoken
@ICOReviewtoken Год назад
I want custom login is pop-up with form login have many fields, how should i do ? 😮
@ethan_mick
@ethan_mick Год назад
Oooo, that's a good idea. I should make a a variation of this. What fields do you want in the login?
@anthonymifsud6141
@anthonymifsud6141 6 месяцев назад
What if you wish to store the session in the database, regularly revalidate it, and, as a system administrator, have the capability to revoke access for a specific session? How would this be accomplished?
@tylerdrabek1592
@tylerdrabek1592 9 месяцев назад
Hey Ethan, thanks for the great vid! Any way you could show how to do this with a provider like Google?
@ethan_mick
@ethan_mick 9 месяцев назад
Check it: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-ot9yuKg15iA.htmlsi=J5gP0wUSjUoGCInk
@aashishdhakal913
@aashishdhakal913 Год назад
Loved the content. Can you please make one with authorization too, instead of just authentication for the protected routes.
@ethan_mick
@ethan_mick Год назад
Thanks! Any particular style of Authorization? Eg, simple roles, RBAC, Policy Based Controls, etc?
@aashishdhakal913
@aashishdhakal913 Год назад
@@ethan_mick Just something that takes a jwt from the frontend and uses nextauth to verify and get decoded token, to give access to routes. I would be thankful if you used tRPC. 🙏
@speedster784
@speedster784 Год назад
Question why did you add the second env file when there was one already there is that needed or just something u always do??
@ethan_mick
@ethan_mick Год назад
Next.js has support for environment files per environment. The .env file is read in *every* environment, which is rarely desired. Rather, you will have separate environment variables per environment. If the value was the same in all environments, it doesn't need to be a variable. So I create the .env.local file to manage my environment variables locally. These won't go to production, which is good, because I want to set a much more secure secret for production. If you add it to the .env file, you might forget to do this. Prisma, really, really, REALLY, should also use the environment specific files. But it doesn't by default. They have some docs (www.prisma.io/docs/guides/development-environment/environment-variables/using-multiple-env-files) to hack it together, but you'd rather it Just Work. So I use the .env file for the Prisma DATABASE_URL variable and nothing else. I also make sure I override that in production. Hope that helps!
@speedster784
@speedster784 Год назад
@@ethan_mick thanks for the reply I'm currently developing a site but I keep getting this error " [next-auth][error][client_fetch_error] not a proper json" which is usually link to missing "NEXTAUTH-URL" but I have that in my env file and error still person . Any ideas?? Using next js 13.4 by the way
@ethan_mick
@ethan_mick Год назад
@@speedster784 Do you also have `NEXTAUTH_SECRET=secret` in your environment?
@MrAtomUniverse
@MrAtomUniverse 10 месяцев назад
I can't seem to use middleware to protect routes when i use google/twitter providers ,do you have an example of that?
@ethan_mick
@ethan_mick 10 месяцев назад
Huh, that should work without needing to change anything. Once the user logs in with the provider then they have a JWT (assuming you're using JWTs) and the middleware will check and validate that. Post login nothing really should be different. I use the Google Provider in my Time Tracking SaaS App ru-vid.com3lAsw0vNuDo?feature=share and post: ethanmick.com/time-tracker-saas-app/
@krasnenaramky6321
@krasnenaramky6321 Год назад
Hello when i tried to add in layout i have error function parseModel(response, json) { return JSON.parse(json, response._fromJSON); } do you know what it can means ? thank you
@ethan_mick
@ethan_mick Год назад
Hmm, what code is that a part of? Did you make sure you have `use client` at the top of the file?
@krasnenaramky6321
@krasnenaramky6321 Год назад
Hello, thank you for your reply. It is next 13.3 bug 13.2 is OK. But there is another problem when you first time sign in with credentials there is no session cookie in response so you have just token and callback cookies,…If you try to log again with these 2 coookis,…session is sent and saved,…you can try delete cookies and try to log in withou callback cookie. Do you know where can be the bug?
@RyanDotElliott
@RyanDotElliott Год назад
I'm trying to use a provider with a custom login page, however, I seem to get an constant redirect loop where the callback is repeatedly added on to the end of my url. Would you have any idea why this is / how to fix it? My `pages` config is setup with my `/login` route, but I cannot seem to figure it out.
@ethan_mick
@ethan_mick Год назад
It sounds like you're using the CredentialProvider with a custom login page. If you're using Middelware to protect routes, you need to ensure that route is "unprotected", otherwise the middleware captures the request and redirects you... back to the login page. If you're not using Middleware, check what else might be protecting the page. Let me know if that helps!
@TheDevOpsEngineer
@TheDevOpsEngineer 5 месяцев назад
THanks for the video, good job, but for some reason, my token in the session callback is always undefined :(
Далее
Set up Google OAuth with Next.js using Next-Auth!
21:00
How to set up Prisma with Next.js and Postgres!
17:40
ДВЕ МЕДИЦИНЫ В ОДНОЙ СТРАНЕ
43:03
Next-Auth on App Router - Solid Auth, Super Fast
17:20
Просмотров 104 тыс.
The Ultimate Guide to Next Auth - Everything You Need
1:36:26
Master NextAuth v5: Next.js Authentication Made Easy
31:35