first user setup and login

This commit is contained in:
2025-06-23 13:27:45 -04:00
parent bbe5eb0ccd
commit 12148e642d
13 changed files with 216 additions and 80 deletions

View File

@@ -0,0 +1,7 @@
import React from 'react'
export default function DashboardPage() {
return (
<div>DashboardPage</div>
)
}

21
app/(auth)/layout.tsx Normal file
View File

@@ -0,0 +1,21 @@
'use client'
import { SessionProvider, useSession } from 'next-auth/react'
import { redirect } from 'next/navigation'
import { ReactNode } from 'react'
import Navbar from '@/components/Navbar'
export default function AuthLayout({ children }: { children: ReactNode }) {
return (
<>
<SessionProvider>
<Navbar />
<main className="p-4">
{/* Could also add a private header here */}
{children}
</main>
</SessionProvider>
</>
)
}

10
app/(public)/layout.tsx Normal file
View File

@@ -0,0 +1,10 @@
import { ReactNode } from 'react'
export default function PublicLayout({ children }: { children: ReactNode }) {
return (
<main>
{/* Public site header if any */}
{children}
</main>
)
}

View File

@@ -0,0 +1,10 @@
import LoginForm from '@/components/LoginForm';
import React, { useState } from 'react'
export default function LoginPage() {
return (
<div>
<LoginForm />
</div>
)
}

View File

@@ -0,0 +1,76 @@
import NextAuth, { type NextAuthOptions } from 'next-auth'
import CredentialsProvider from 'next-auth/providers/credentials'
import { PrismaClient } from '@prisma/client'
import bcrypt from 'bcrypt'
const prisma = new PrismaClient()
export const authOptions: NextAuthOptions = {
providers: [
CredentialsProvider({
name: 'Credentials',
credentials: {
email: { label: 'Email', type: 'email' },
password: { label: 'Password', type: 'password' },
},
async authorize(credentials) {
if (!credentials?.email || !credentials?.password) {
console.log('[AUTH] Missing credentials')
return null
}
const user = await prisma.user.findUnique({
where: { email: credentials.email },
})
if (!user) {
console.log('[AUTH] User not found')
return null
}
if (!user.password) {
console.log('[AUTH] User has no password set')
return null
}
const isValid = await bcrypt.compare(credentials.password, user.password)
if (!isValid) {
console.log('[AUTH] Invalid password')
return null
}
console.log('[AUTH] Successful login', user.email)
return {
id: user.id,
email: user.email,
name: user.name,
role: user.role,
}
},
}),
],
session: {
strategy: 'jwt',
},
callbacks: {
async jwt({ token, user }) {
if (user) {
token.id = user.id
token.role = user.role
}
return token
},
async session({ session, token }) {
if (session.user) {
session.user.id = token.id as string
session.user.role = token.role as "COUPLE" | "PLANNER" | "GUEST"
}
return session
},
},
secret: process.env.NEXTAUTH_SECRET,
}
const handler = NextAuth(authOptions)
export { handler as GET, handler as POST }