Тёмный

Build a custom login page for your SaaS app with Next.js, Tailwind CSS, and Next Auth (App Dir)! 

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

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

 

14 окт 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 61   
@gamescope2607
@gamescope2607 11 месяцев назад
Hello, thanks for the video. I have a question about how to implement multiple custom logins for different user roles, such as clients and administrators. Can you provide some guidance on this?
@0xtz_
@0xtz_ Год назад
Man keep going ur videos are so helpful 🔥, thanks 🙏
@ethan_mick
@ethan_mick Год назад
Dude, thank you so much. Time to start getting deep into the weeds and build some SaaS!!
@0xtz_
@0xtz_ Год назад
@@ethan_mick 🙏 I'm planning to start an open source project hhh, but idk what it is exactly 😂
@Mantenner
@Mantenner Год назад
Another great episode mate, getting closer to having a full site made up now with your help! Getting more comfortable with the CRUD side of postgres and next.js. Keen to move on to the next video.
@ethan_mick
@ethan_mick Год назад
That's awesome! Glad your project is coming along well. Once the CRUD mechanics are familiar you're 90% of the way there :)
@KelberStuchi
@KelberStuchi Год назад
user roles like admin, reviewer and user to complete authentication. Tks
@ethan_mick
@ethan_mick Год назад
Great idea, I'll definitely dig deeper into this. Important stuff for any SaaS
@logistics_guy
@logistics_guy Год назад
Love this channel. So clear and straight to the point. Good work!
@ethan_mick
@ethan_mick Год назад
Thank you so much!
@raymondmichael4987
@raymondmichael4987 Год назад
I’ll look into this later, because lately I spend few projects on clerk now had to come back to next-auth but things was little bumpy 😊
@ethan_mick
@ethan_mick Год назад
This is a good one. If you want some help setting up Next Auth and prisma (really, with any database), check out ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-2kgqPvs0j_I.html
@nasarissa749
@nasarissa749 11 месяцев назад
Great episode. 1) I noticed during the middleware section that my home page was protected as well. What is the way to unprotect it along with register, api and login? 2) Is there a downside to not protecting your api folder? 3) I redirect to signin after registering a user. Once I sign in, the app redirects back to the signin page rather than dashboard. It works normally if I start from home page, then signin page, then dashboard. Any ideas why that happens? #EDIT# My signin page url has a callback to signup. Do I need to use useRouter in my signup page rather than using nextAuth's signIn() functionality when I successfully signed up a user?
@aqmalcode9563
@aqmalcode9563 Год назад
I hope ur, make crud with image upload with next js 13. BTW great video
@0xtz_
@0xtz_ Год назад
I think for the image upload use normal form data, but not sure if that's what u need
@ethan_mick
@ethan_mick Год назад
Thanks! @0xtz_ is right, this can be accomplished with FormData. I'll see what I can do on making a guide for this! Also, keep in mind that you can't save the images on the server if deploying serverless -- you need to use object storage like S3. developer.mozilla.org/en-US/docs/Web/API/FormData
@geraldaburto7712
@geraldaburto7712 11 месяцев назад
I have a problem with the middleware setting, It also protect files in /public folder, so I can't access them from the login page, how can I fix this?
@irtazahussain8118
@irtazahussain8118 Год назад
pl share the github repo for better understanding. I want to see the NextAuth part. I've to login from my own external endpoints and create a user session in NextAuth. But I'm not getting the credentials that I'm sending from signIn function of NextAuth.
@ethan_mick
@ethan_mick Год назад
Hey, source code can be found at the bottom of the blog post: ethanmick.com/build-a-custom-login-page-with-next-js-tailwind-css-and-next-auth/ (Become a member! 😊 )
@joylodralive
@joylodralive Год назад
Hi, ethan thanks for making the video! Can you talk about how to save states in the local storage in next 13? Or have you ever made an article about it? Thank you!
@ethan_mick
@ethan_mick Год назад
Thanks! I can write/video something up on that. It'll be similar to React, so consider something like this: usehooks.com/useLocalStorage/
@ziaahmad8738
@ziaahmad8738 Год назад
Hi, I can't my wrap my head around how I can redirect users to dashboard if they are logged in already. I want to do this via a middleware. I tried to use `getServerSession` but that does not work in middleware.
@ziaahmad8738
@ziaahmad8738 Год назад
Nevermind, getToken approach was not working for some reason it kept giving me null but 5 mins after this comment it started working. idk what i was doing wrong.
@ethan_mick
@ethan_mick Год назад
Sometimes you just need to post a comment and then it starts working. Let me know if you need anything else!
@ziaahmad8738
@ziaahmad8738 Год назад
@@ethan_mick😂💪
@tunaralyarzada
@tunaralyarzada Год назад
amazing brother! I am about done auth part, so i am gonna pass to opearations like fetching data or crud operations. but just have a quick question to u:) when i get session object, as you know we dont get accessToken property. so do we really need it or not? cause i wanna send request to for instance "/product" root to fetch some products with axios. so do i need send accessToken in header part of axios to check if i am authenticated in api route handler. or we just should write getServerSession() to get session object in api handler file and check authentification?
@ethan_mick
@ethan_mick Год назад
You shouldn't need the "accessToken" property. When you make the request with Axios to your own domain, it will include the cookies by default. You can use the cookie server side to check the authentication. Assuming valid auth, you can then return "/products" or whatnot. In general, I'd use middleware to protect the routes (including API routes) and then in your handlers you can just trust there is a valid user and use the session data.
@tunaralyarzada
@tunaralyarzada Год назад
​@@ethan_mick I mean, if someone try to send request to api from external device or postman to fetch my database. So in this case, what i have to do in my api handlers? u said, i dont need accessToken check, so i can just call const session = getServerSession() function and if(!session) return error u mean?
@ethan_mick
@ethan_mick Год назад
​@@tunaralyarzada Right. You can either use middleware or "const session = await getServerSession()" to get the session. Next-Auth will validate that it is a VALID session. If not, return an error. If it is, then you can lookup the data in your database.
@tunaralyarzada
@tunaralyarzada Год назад
@@ethan_mick thank u so much, man!
@ronaldpaek
@ronaldpaek Год назад
Your content is so good, I've been looking for these solutions for the past month, will you also be showing how you can use stripe payments with route handler API vs the pages API? thank you so much for this!
@ethan_mick
@ethan_mick Год назад
Yeah, I think I'm going to build some full featured SaaS apps in the future and walk through all of that.
@vincentgauthier2298
@vincentgauthier2298 10 месяцев назад
how can this work with auth0 provider? ideally id like to show all the options auth0 has.
@franckray8438
@franckray8438 Год назад
Great content! Just wonder how to not show the password in the URL when using a custom login page?
@ethan_mick
@ethan_mick Год назад
If you're seeing the URL your form is making a GET request. Make sure it's calling the `signIn` method or making a POST request.
@KarimFawaz
@KarimFawaz Год назад
Thanks for the videos, really amazing!. One thing tho, after adding the folders to (app) and (auth) and changing the middleware configuration, the login and sign up pages look very different. I created my own form instead of the prebuilt ones you used and now the form shrunk and the image I had is not accessible. Any ideas?
@ethan_mick
@ethan_mick Год назад
Hmmm, off the top of my head, not totally sure. Are you using Tailwind? Is that configured properly?
@anuj7286
@anuj7286 Год назад
Great explanation sir. Could you please make a tutorial on best way to protect routes in react. Thankyou
@ethan_mick
@ethan_mick Год назад
I'll add it to the list! React can't do things server side so it ends up being more session management. But there are some good libraries to help with this.
@LuisCastroem
@LuisCastroem Год назад
Loved the middleware exclusion pattern but what if I would also like to include the root page in that pattern?
@ethan_mick
@ethan_mick Год назад
Hmmm, perhaps try something like the following: (^\/$|((?!api|_next\/static|_next\/image|favicon.ico).)*) The ^\/$ part of the regex matches the root ("/") exactly. The | (pipe) acts as a logical OR, so either the root path is matched, or any path not starting with "api", "_next/static", "_next/image", or "favicon.ico" is matched.
@noormuhammad888
@noormuhammad888 Год назад
​@@ethan_mick I ran into the same problem of including the root page inside the middleware exclusion pattern. it looks like Next.js doesn't allow doing it this way. throwing error of "`source` does not start with / for route {"source":"(^/$|((?!random|singin|api).)*)"}" Do you have another solution?
@FrenchBaguette69
@FrenchBaguette69 2 месяца назад
hi i get unhandeled runtime error: Unhandled Runtime Error Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports. Check the render method of `Form`.
@John-vm7fq
@John-vm7fq Год назад
Are usestate still a thing in nextjs app directory?
@ethan_mick
@ethan_mick Год назад
Yes, for sure. It only works in client components, so the question is more "In places where you had to `useState`, is there a better way?"
@coderwala
@coderwala Год назад
15:48 How this automatically redirecting into login page when its protected by routes? i mean whats the code here!
@ethan_mick
@ethan_mick Год назад
The redirect is handled by the "export { default } from ..." code. Docs: next-auth.js.org/configuration/nextjs#middleware Essentially you're exporting the default function from Next Auth which is the entire middleware. You can see what this function does here: github.com/nextauthjs/next-auth/blob/4f3241f8ddc84958774707de37be4da05ad1de93/packages/next-auth/src/next/middleware.ts#L99-L154 It does what you'd expect: Read the request, check the cookie, get the JWT, and check if it's valid. If it is, continue. If it's not, redirect the user to the signin page.
@coderwala
@coderwala Год назад
@@ethan_mick Got it...and thanks man for this amazing tutorial
@marcelo-3k
@marcelo-3k Год назад
how can i add a field userRole in my session or jwt based on my user.role field?
@ethan_mick
@ethan_mick Год назад
You can see how I do this here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-2kgqPvs0j_I.html Instead of the ID, pass through your userRole.
@marcelo-3k
@marcelo-3k Год назад
@@ethan_mick i'll check, thank you ethan!
@emmanueladufo
@emmanueladufo Год назад
My saviour 🙏
@ethan_mick
@ethan_mick Год назад
Glad I could help, haha. Cheers!
@seyhaphan7319
@seyhaphan7319 Год назад
how to hide navbar when login page with app dir
@ethan_mick
@ethan_mick Год назад
Try putting the login page in it's own route group (auth) so it can have a different root layout.
@sumitwadhwa8823
@sumitwadhwa8823 Год назад
csrf token??
@ethan_mick
@ethan_mick Год назад
That’s taken care of by the “signIn” method of Next Auth: next-auth.js.org/getting-started/client#signin
@xyzxyzxyzxyz
@xyzxyzxyzxyz 5 месяцев назад
Usually I watch tutorials at 1.5-2x speed but I regularly need to pause to see what the heck you are typing
@chanmyaemaung
@chanmyaemaung Год назад
Are you a developer laid off by FAANG? 😅
@ethan_mick
@ethan_mick Год назад
LOL, no, but I did work at Apple and Microsoft a long time ago.
Далее
10 Tailwind Classes I Wish I Knew Earlier
13:31
Просмотров 188 тыс.
The Ultimate Guide to Next Auth - Everything You Need
1:36:26