Skip to content

Commit

Permalink
feat(auth): setup nextauth, register with credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
tinspham209 committed May 5, 2023
1 parent 8217a50 commit 3a235c8
Show file tree
Hide file tree
Showing 8 changed files with 635 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
DATABASE_URL="mongodb+srv://<username>:<password>@cluster0.<cluster_id>.mongodb.net/<db_env>"
DATABASE_URL="mongodb+srv://<username>:<password>@cluster0.<cluster_id>.mongodb.net/<db_env>"
NEXTAUTH_SECRET=
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Zustand
- React-hook-form
- Prisma
- Next/auth

## Installation
```
Expand Down
3 changes: 0 additions & 3 deletions app/api/hello/route.ts

This file was deleted.

21 changes: 21 additions & 0 deletions app/api/register/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { NextResponse } from "next/server";
import bcrypt from "bcrypt";

import prisma from "@/app/libs/prismadb";

export async function POST(request: Request) {
const body = await request.json();
const { email, name, password } = body;

const hashedPassword = await bcrypt.hash(password, 12);

const user = await prisma.user.create({
data: {
email,
name,
hashedPassword,
},
});

return NextResponse.json(user);
}
13 changes: 13 additions & 0 deletions app/libs/prismadb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { PrismaClient } from "@prisma/client";

declare global {
var prisma: PrismaClient | undefined;
}

const client = globalThis.prisma || new PrismaClient();

if (process.env.NODE_ENV !== "production") {
globalThis.prisma = client;
}

export default client;
Loading

0 comments on commit 3a235c8

Please sign in to comment.