Skip to content

Commit 92ab3d5

Browse files
committed
Update dependencies.
1 parent f6127c5 commit 92ab3d5

12 files changed

+4223
-258
lines changed

Diff for: README.md

+3-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
1-
<p align="center">
2-
<a href="https://nextjs-postgres-auth.vercel.app/">
3-
<img src="/public/logo.png" height="96">
4-
<h3 align="center">Next.js Prisma PostgreSQL Auth Starter</h3>
5-
</a>
6-
</p>
7-
8-
<p align="center">
9-
This is a <a href="https://nextjs.org/">Next.js</a> starter kit that uses <a href="https://next-auth.js.org/">Next-Auth</a> for simple email + password login<br/>
10-
<a href="https://www.prisma.io/">Prisma</a> as the ORM, and a <a href="https://vercel.com/postgres">Neon Postgres</a> database to persist the data.</p>
11-
12-
<br/>
1+
# Next.js + PostgreSQL Auth Starter
2+
3+
This is a [Next.js](https://nextjs.org/) starter kit that uses [NextAuth.js](https://next-auth.js.org/) for simple email + password login, [Drizzle](https://orm.drizzle.team) as the ORM, and a [Neon Postgres](https://vercel.com/postgres) database to persist the data.
134

145
## Deploy Your Own
156

Diff for: app/auth.config.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ export const authConfig = {
1010
],
1111
callbacks: {
1212
authorized({ auth, request: { nextUrl } }) {
13-
const isLoggedIn = !!auth?.user;
14-
const isOnDashboard = nextUrl.pathname.startsWith('/protected');
13+
let isLoggedIn = !!auth?.user;
14+
let isOnDashboard = nextUrl.pathname.startsWith('/protected');
15+
1516
if (isOnDashboard) {
1617
if (isLoggedIn) return true;
1718
return false; // Redirect unauthenticated users to login page
1819
} else if (isLoggedIn) {
1920
return Response.redirect(new URL('/protected', nextUrl));
2021
}
22+
2123
return true;
2224
},
2325
},

Diff for: app/auth.ts

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import NextAuth from 'next-auth';
22
import Credentials from 'next-auth/providers/credentials';
33
import bcrypt from 'bcrypt';
4-
import prisma from 'app/prisma';
4+
import { getUser } from 'app/db';
55
import { authConfig } from 'app/auth.config';
66

77
export const {
@@ -14,15 +14,10 @@ export const {
1414
providers: [
1515
Credentials({
1616
async authorize({ email, password }: any) {
17-
let user = await prisma.user.findUnique({
18-
where: {
19-
email,
20-
},
21-
});
22-
23-
if (!user) return null;
24-
let passwordsMatch = await bcrypt.compare(password, user.password);
25-
if (passwordsMatch) return user as any;
17+
let user = await getUser(email);
18+
if (user.length === 0) return null;
19+
let passwordsMatch = await bcrypt.compare(password, user[0].password!);
20+
if (passwordsMatch) return user[0] as any;
2621
},
2722
}),
2823
],

Diff for: app/db.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { drizzle } from 'drizzle-orm/postgres-js';
2+
import { pgTable, serial, varchar } from 'drizzle-orm/pg-core';
3+
import { eq } from 'drizzle-orm';
4+
import postgres from 'postgres';
5+
import { hash } from 'bcrypt';
6+
7+
let client = postgres(`${process.env.POSTGRES_URL!}?sslmode=require`);
8+
let db = drizzle(client);
9+
10+
let users = pgTable('User', {
11+
id: serial('id').primaryKey(),
12+
email: varchar('email', { length: 64 }),
13+
password: varchar('password', { length: 64 }),
14+
});
15+
16+
export async function getUser(email: string) {
17+
return await db.select().from(users).where(eq(users.email, email));
18+
}
19+
20+
export async function createUser(email: string, password: string) {
21+
return await db
22+
.insert(users)
23+
.values({ email, password: await hash(password, 10) });
24+
}

Diff for: app/layout.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import './globals.css';
22

33
import { GeistSans } from 'geist/font/sans';
44

5-
const title = 'Next.js Prisma Postgres Auth Starter';
6-
const description =
5+
let title = 'Next.js + Postgres Auth Starter';
6+
let description =
77
'This is a Next.js starter kit that uses NextAuth.js for simple email + password login and a Postgres database to persist the data.';
88

99
export const metadata = {
@@ -17,7 +17,7 @@ export const metadata = {
1717
metadataBase: new URL('https://nextjs-postgres-auth.vercel.app'),
1818
};
1919

20-
export default async function RootLayout({
20+
export default function RootLayout({
2121
children,
2222
}: {
2323
children: React.ReactNode;

Diff for: app/opengraph-image.png

-324 KB
Binary file not shown.

Diff for: app/page.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default function Page() {
2020
</svg>
2121
<div className="text-center max-w-screen-sm mb-10">
2222
<h1 className="text-stone-200 font-bold text-2xl">
23-
Next.js Prisma PostgreSQL Auth Starter
23+
Next.js + Postgres Auth Starter
2424
</h1>
2525
<p className="text-stone-400 mt-5">
2626
This is a{' '}
@@ -48,7 +48,7 @@ export default function Page() {
4848
rel="noopener noreferrer"
4949
className="text-stone-400 underline hover:text-stone-200 transition-all"
5050
>
51-
Vercel Postgres
51+
Postgres
5252
</a>{' '}
5353
database to persist the data.
5454
</p>

Diff for: app/prisma.ts

-11
This file was deleted.

Diff for: app/register/page.tsx

+4-17
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,19 @@
11
import Link from 'next/link';
22
import { Form } from 'app/form';
3-
import prisma from '@/app/prisma';
4-
import { hash } from 'bcrypt';
53
import { redirect } from 'next/navigation';
4+
import { createUser, getUser } from 'app/db';
65

76
export default function Login() {
87
async function register(formData: FormData) {
98
'use server';
109
let email = formData.get('email') as string;
1110
let password = formData.get('password') as string;
11+
let user = await getUser(email);
1212

13-
const exists = await prisma.user.findUnique({
14-
where: {
15-
email,
16-
},
17-
});
18-
19-
if (exists) {
20-
console.log('User already exists');
13+
if (user.length > 0) {
2114
return 'User already exists'; // TODO: Handle errors with useFormStatus
2215
} else {
23-
await prisma.user.create({
24-
data: {
25-
email,
26-
password: await hash(password, 10),
27-
},
28-
});
29-
console.log('User created');
16+
await createUser(email, password);
3017
redirect('/login');
3118
}
3219
}

Diff for: package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
{
22
"private": true,
33
"scripts": {
4-
"dev": "prisma generate && next dev --turbo",
5-
"build": "prisma generate && prisma db push && next build",
4+
"dev": "next dev --turbo",
5+
"build": "next build",
66
"start": "next start",
77
"lint": "next lint"
88
},
99
"dependencies": {
10-
"@prisma/client": "^5.7.1",
1110
"@types/node": "^20.10.5",
1211
"@types/react": "^18.2.45",
1312
"bcrypt": "^5.1.1",
13+
"drizzle-orm": "^0.29.2",
1414
"geist": "^1.2.0",
1515
"next": "^14.0.4",
1616
"next-auth": "5.0.0-beta.4",
17+
"postgres": "^3.4.3",
1718
"react": "^18.2.0",
1819
"react-dom": "^18.2.0"
1920
},
@@ -23,7 +24,6 @@
2324
"eslint": "8.56.0",
2425
"eslint-config-next": "^14.0.4",
2526
"postcss": "^8.4.32",
26-
"prisma": "^5.7.1",
2727
"tailwindcss": "^3.4.0",
2828
"typescript": "^5.3.3"
2929
}

0 commit comments

Comments
 (0)