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
This application is not ready for general usage
; + return
You do not have access to this application currently
; } diff --git a/src/app/page.tsx b/src/app/page.tsx index 2f8a406..5864a2c 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -2,16 +2,24 @@ import { getServerSession } from "next-auth/next"; import { AuthOptions } from "./api/auth/[...nextauth]/route"; import GoogleSignInButton from "./components/signin/GoogleSignInButton"; import MicrosoftSignInButton from "./components/signin/MicrosoftSignInButton"; +import EmailSignInButton from "./components/signin/CredentialsButton"; import { redirect } from "next/navigation"; import Image from "next/image"; -export default async function Home() { +export default async function Home({ + searchParams, +}: { + searchParams: { error?: string }; +}) { const session = await getServerSession(AuthOptions); if (session?.user) { redirect("/home"); } + // Extract the error parameter from the searchParams object + const error = searchParams.error; + return (
{/* Left Half */} @@ -23,7 +31,7 @@ export default async function Home() { {/* Right Half */}
-
+
Start managing your portfolios
+ +
+ {/* This width has been manually set to align the buttons but should be improved */} + +
+
Sign in with a Social Account
-