diff --git a/src/app/api/auth/[...nextauth]/route.ts b/src/app/api/auth/[...nextauth]/route.ts index e9dd86b..8cc6019 100644 --- a/src/app/api/auth/[...nextauth]/route.ts +++ b/src/app/api/auth/[...nextauth]/route.ts @@ -1,6 +1,7 @@ import NextAuth, { NextAuthOptions } from "next-auth"; import GoogleProvider from "next-auth/providers/google"; import AzureADB2CProvider from "next-auth/providers/azure-ad-b2c"; +import CredentialsProvider from "next-auth/providers/credentials"; import { db } from "@/app/db/db"; import { user as userTable, User } from "@/app/db/schema/users"; @@ -42,10 +43,43 @@ export const AuthOptions: NextAuthOptions = { authorization: { params: { scope: "openid profile offline_access", - prompt: "login", // + prompt: "login", }, }, }), + CredentialsProvider({ + name: "Email Login", + credentials: { + email: { + label: "Email", + type: "email", + }, + }, + async authorize(credentials, req) { + if (!credentials || !credentials.email) { + throw new Error("Email is required"); + } + + const { email } = credentials; + + // Query the database to find the user by email + const dbUser = await db + .select() + .from(userTable) + .where(eq(userTable.email, email)); + + // If the email exists, return the user object (no password check) + if (dbUser.length === 1) { + return { + id: dbUser[0].id.toString(), // Convert bigint to string to avoid serialization issues + email: dbUser[0].email, + dbId: dbUser[0].id.toString(), // Ensure dbId is added and is a string + }; + } + + return null; + }, + }), ], pages: { signIn: "/", diff --git a/src/app/beta/page.tsx b/src/app/beta/page.tsx index ed4ef26..14afc45 100644 --- a/src/app/beta/page.tsx +++ b/src/app/beta/page.tsx @@ -1,3 +1,3 @@ export default function Beta() { - return