In this lesson, we will use the middleware and cookies to create a user authentication system so that only authenticated users can access certain routes.
User registration
First of all, update the Prisma schema to include a password
field.
prisma
1model User {
2 id Int @id @default(autoincrement())
3 email String @unique
4 name String
5 password String
6
7 posts Post[]
8}
Apply this new schema by running the following command:
bash
1npx prisma migrate dev
Update the interface for creating new users.
views/user/new.pug
pug
1extends ../layout.pug
2
3block meta
4 name Create New User
5
6block content
7 form(id="newUser")
8 label(for="name") Name:
9 input(type="text", name="name", id="name")
10 br
11 br
12
13 label(for="email") Email: