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

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…

Contents