From 94e4691b0ef900032dbaaa86f5e7b965cb1b05c7 Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Sun, 27 Jul 2025 16:45:52 +0200 Subject: [PATCH] Updates --- prisma/schema.prisma | 6 +- src/app/api/auth/[...nextauth]/route.ts | 5 +- src/app/dashboard/page.tsx | 53 ++- src/app/login/page.tsx | 536 ++++++++++++------------ src/app/page.tsx | 41 +- src/app/page_init.tsx | 103 ----- src/app/signup/page.tsx | 142 +++---- src/lib/auth.ts | 70 ---- src/lib/prisma.ts | 2 +- tsconfig.json | 3 +- 10 files changed, 378 insertions(+), 583 deletions(-) delete mode 100644 src/app/page_init.tsx delete mode 100644 src/lib/auth.ts diff --git a/prisma/schema.prisma b/prisma/schema.prisma index d26a36c7..6ec57efc 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -8,7 +8,7 @@ generator client { datasource db { provider = "sqlite" - url = "file:./dev.db" + url = env("DATABASE_URL") } model Account { @@ -26,6 +26,10 @@ model Account { session_state String? user User @relation(fields: [userId], references: [id], onDelete: Cascade) + displayName String + avatarUrl String? + bio String? + @@unique([provider, providerAccountId]) } diff --git a/src/app/api/auth/[...nextauth]/route.ts b/src/app/api/auth/[...nextauth]/route.ts index dac21021..dabbf18d 100644 --- a/src/app/api/auth/[...nextauth]/route.ts +++ b/src/app/api/auth/[...nextauth]/route.ts @@ -4,9 +4,6 @@ import { authConfig } from '@/auth'; // Initialize NextAuth with the configuration export const { handlers: { GET, POST }, - auth, - signIn, - signOut, } = NextAuth({ ...authConfig, // Enable debug logs in development @@ -25,4 +22,4 @@ export const { }, }); -export { GET, POST, auth, signIn, signOut }; \ No newline at end of file +export { GET, POST}; \ No newline at end of file diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx index f634e4c8..a66371d2 100644 --- a/src/app/dashboard/page.tsx +++ b/src/app/dashboard/page.tsx @@ -1,12 +1,12 @@ 'use client'; -import { signOut } from '@/app/api/auth/[...nextauth]/route'; -import { useSession } from 'next-auth/react'; -import { useRouter } from 'next/navigation'; -import { useEffect } from 'react'; +import {signOut, useSession} from "next-auth/react"; +import {useRouter} from 'next/navigation'; +import {useEffect} from 'react'; export default function DashboardPage() { - const { data: session, status } = useSession(); + console.log('DashboardPage'); + const {data: session, status} = useSession(); const router = useRouter(); useEffect(() => { @@ -16,6 +16,7 @@ export default function DashboardPage() { }, [status, router]); if (status === 'loading') { + console.log("LOADING"); return (
@@ -23,7 +24,9 @@ export default function DashboardPage() { ); } - if (status === 'unauthenticated') { + console.log(status, session); + + if (status === 'unauthenticated' || !session) { // router.push('/login'); return null; } @@ -41,7 +44,7 @@ export default function DashboardPage() { Welcome, {session.user?.name || 'User'}! +
+ + + + + {success && ( +
+
+
+ + + +
+
+

{success}

+
+
+
+ )} + {error && ( +
+
+
+ + + +
+
+

{error}

+
+
+
+ )} +
+ +
+
+ + setEmail(e.target.value)} + /> +
+
+ + setPassword(e.target.value)} + /> +
+
+ +
+
+ + +
+ +
+ + Forgot your password? + +
+
+ +
+ +
+
- -
-
- -
- -
- -
-
- - {success && ( -
-
-
- - - -
-
-

{success}

-
-
-
- )} - {error && ( -
-
-
- - - -
-
-

{error}

-
-
-
- )} -
- -
-
- - setEmail(e.target.value)} - /> -
-
- - setPassword(e.target.value)} - /> -
-
- -
-
- - -
- -
- - Forgot your password? - -
-
- -
- -
-
- - - ); + ); } diff --git a/src/app/page.tsx b/src/app/page.tsx index 41ca9387..abaa30d0 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -6,17 +6,17 @@ export default function Home() {

- Welcome to BayesBond + BayesBond

- A modern web application with authentication and more. + A bonding platform for rational thinkers

- Get Started + Sign Up
- -
-

Features

-
-
-
- - - -
-

Fast

-

Built with Next.js for optimal performance and SEO.

-
- -
-
- - - -
-

Secure

-

Built-in authentication with NextAuth.js.

-
- -
-
- - - -
-

Modern

-

Built with the latest web technologies.

-
-
-
); diff --git a/src/app/page_init.tsx b/src/app/page_init.tsx deleted file mode 100644 index 2dde49eb..00000000 --- a/src/app/page_init.tsx +++ /dev/null @@ -1,103 +0,0 @@ -import Image from "next/image"; - -export default function Home() { - return ( -
-
- Next.js logo -
    -
  1. - Get started by editing{" "} - - src/app/page.tsx - - . -
  2. -
  3. - Save and see your changes instantly. -
  4. -
- -
- - Vercel logomark - Deploy now - - - Read our docs - -
-
- -
- ); -} diff --git a/src/app/signup/page.tsx b/src/app/signup/page.tsx index 1b0db99f..fafe3943 100644 --- a/src/app/signup/page.tsx +++ b/src/app/signup/page.tsx @@ -110,6 +110,70 @@ export default function SignupPage() { Sign in

+ +
+
+
+ + setName(e.target.value)} + /> +
+
+ + setEmail(e.target.value)} + /> +
+
+ + setPassword(e.target.value)} + /> +
+
+ +
+ +
+
@@ -121,8 +185,8 @@ export default function SignupPage() {
-
-
+
+
- -
- -
@@ -171,69 +223,7 @@ export default function SignupPage() { )} -
-
-
- - setName(e.target.value)} - /> -
-
- - setEmail(e.target.value)} - /> -
-
- - setPassword(e.target.value)} - /> -
-
-
- -
-
); diff --git a/src/lib/auth.ts b/src/lib/auth.ts deleted file mode 100644 index e55ce818..00000000 --- a/src/lib/auth.ts +++ /dev/null @@ -1,70 +0,0 @@ -import { PrismaAdapter } from "@auth/prisma-adapter"; -import { NextAuthOptions } from "next-auth"; -import CredentialsProvider from "next-auth/providers/credentials"; -import { prisma } from "./prisma"; -import { compare } from 'bcryptjs'; - -export const authOptions: NextAuthOptions = { - adapter: PrismaAdapter(prisma), - session: { - strategy: "jwt", - }, - pages: { - signIn: "/login", - signOut: "/", - error: "/login", - }, - providers: [ - CredentialsProvider({ - name: "Credentials", - credentials: { - email: { label: "Email", type: "email" }, - password: { label: "Password", type: "password" }, - }, - async authorize(credentials) { - if (!credentials?.email || !credentials?.password) { - throw new Error("Please enter your email and password"); - } - - const user = await prisma.user.findUnique({ - where: { - email: credentials.email, - }, - }); - - if (!user || !user.password) { - throw new Error("No user found with this email"); - } - - const isValid = await compare(credentials.password, user.password); - - if (!isValid) { - throw new Error("Incorrect password"); - } - - return { - id: user.id, - email: user.email, - name: user.name, - image: user.image, - }; - }, - }), - ], - callbacks: { - async jwt({ token, user }) { - if (user) { - token.id = user.id; - } - return token; - }, - async session({ session, token }) { - if (session?.user) { - session.user.id = token.id as string; - } - return session; - }, - }, - secret: process.env.NEXTAUTH_SECRET, - debug: process.env.NODE_ENV === "development", -} as const; diff --git a/src/lib/prisma.ts b/src/lib/prisma.ts index 6cb2c902..23181f34 100644 --- a/src/lib/prisma.ts +++ b/src/lib/prisma.ts @@ -5,7 +5,7 @@ declare global { var prisma: PrismaClient | undefined; } -const globalForPrisma = globalThis as unknown as { prisma: PrismaClient }; +const globalForPrisma = global as unknown as { prisma: PrismaClient } export const prisma = globalForPrisma.prisma || new PrismaClient(); diff --git a/tsconfig.json b/tsconfig.json index c1334095..59e472b2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -23,5 +23,6 @@ } }, "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], - "exclude": ["node_modules"] + "exclude": ["node_modules"], + "sourceMap": true }