From the course: Next.js Ecommerce: Build a Shopping Platform from Scratch
Unlock this course with a free trial
Join today to access over 25,200 courses taught by industry experts.
Sign-in and sign-out server actions - Next.js Tutorial
From the course: Next.js Ecommerce: Build a Shopping Platform from Scratch
Sign-in and sign-out server actions
OK, so now we want to work on the sign-in. And we're going to have a few videos dedicated to signing in and signing out. So we need to have an action for both where we interact with the database. We get the user from the database. We run it through the sign-in function that NextAuth offers. We return the user and so on. Then we need to create a page with a form to sign in. So there's a few steps to this. then we need to obviously hook up the form to that action. We need validation, and that's where Zod comes in. So I'm going to start off by creating a very simple Zod schema for the sign-in form. So if we go to lib and then validators TS, let's come down to the bottom here. And I'm just going to say schema for signing users in, and we'll export. So let's say export const. And I'm going to call this, let's say, sign in form schema. And set that to z.object. And then we're going to pass in some curly braces. And we're just going to have two fields, e-mail and password. So e-mail, we want…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Section intro2m 57s
-
(Locked)
Prisma user-related models9m 45s
-
(Locked)
Seed user data7m
-
(Locked)
NextAuth setup17m 31s
-
(Locked)
NextAuth catch all API route4m 12s
-
(Locked)
Sign-in and sign-out server actions8m 27s
-
(Locked)
Auth layout and sign-in page6m 58s
-
(Locked)
Credentials sign-in form6m 39s
-
(Locked)
Hook up sign-in form9m 28s
-
(Locked)
Callback URL redirect4m 26s
-
(Locked)
User button and sign-out11m 48s
-
(Locked)
Signup Zod schema and action8m 15s
-
(Locked)
Sign-up page and form7m 35s
-
(Locked)
Sign-up error handling12m 40s
-
(Locked)
Customize token with JWT callback8m 19s
-
(Locked)
-
-
-
-
-
-
-
-
-
-
-
-
-