Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions app/api/register/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export async function POST(req: Request) {
return NextResponse.json({ error: "Missing fields" }, { status: 400 });
}

const [existingUser] = await db.select().from(users).where(eq(users.email, email)).limit(1);
const normalizedEmail = email.toLowerCase();

const [existingUser] = await db.select().from(users).where(eq(users.email, normalizedEmail)).limit(1);

if (existingUser) {
return NextResponse.json({ error: "User already exists" }, { status: 400 });
Expand All @@ -22,10 +24,10 @@ export async function POST(req: Request) {

const [user] = await db.insert(users).values({
name,
email,
email: normalizedEmail,
password: hashedPassword,
status: "PENDING",
role: email === process.env.ADMIN_EMAIL ? "ADMIN" : "USER",
role: normalizedEmail === process.env.ADMIN_EMAIL?.toLowerCase() ? "ADMIN" : "USER",
}).returning();

return NextResponse.json({ user: { email: user.email, name: user.name } });
Expand Down
20 changes: 15 additions & 5 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,21 @@ export default function LandingPage() {
</div>
</main>

<footer className="p-8 text-center text-foreground-muted/60 border-t border-primary/10">
<p className="mb-2">Contact: 647-781-8371</p>
<p className="font-script text-xl text-accent/80">
Blessings of peace, Baba Virtuehearts
</p>
<footer className="p-8 text-center text-foreground-muted/60 border-t border-primary/10 space-y-4">
<div>
<p className="mb-2">Contact: 647-781-8371</p>
<p className="font-script text-xl text-accent/80">
Blessings of peace, Baba Virtuehearts
</p>
</div>
<div>
<Link
href="/admin"
className="text-xs hover:text-accent transition-colors opacity-50 hover:opacity-100"
>
Admin Sanctuary
</Link>
</div>
</footer>
</div>
);
Expand Down
88 changes: 0 additions & 88 deletions dev_server.log

This file was deleted.

19 changes: 12 additions & 7 deletions lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ export const authOptions: NextAuthOptions = {
throw new Error("Invalid credentials");
}

const isAdmin = credentials.email === process.env.ADMIN_EMAIL;
const normalizedEmail = credentials.email.toLowerCase();
const isAdmin = normalizedEmail === process.env.ADMIN_EMAIL?.toLowerCase();
const adminPasswordEnv = process.env.ADMIN_PASSWORD;

const [existingUser] = await db.select().from(users).where(eq(users.email, credentials.email)).limit(1);
const [existingUser] = await db.select().from(users).where(eq(users.email, normalizedEmail)).limit(1);
let user = existingUser;

// 1. Try DB password first (important if changed via UI)
Expand All @@ -49,7 +50,7 @@ export const authOptions: NextAuthOptions = {
if (isAdmin && adminPasswordEnv && credentials.password === adminPasswordEnv) {
if (!user) {
const [newUser] = await db.insert(users).values({
email: credentials.email,
email: normalizedEmail,
password: await bcrypt.hash(adminPasswordEnv, 10),
role: "ADMIN",
status: "APPROVED",
Expand Down Expand Up @@ -91,12 +92,15 @@ export const authOptions: NextAuthOptions = {
callbacks: {
async signIn({ user, account }) {
if (account?.provider === "google") {
const [existingUser] = await db.select().from(users).where(eq(users.email, user.email!)).limit(1);
const normalizedEmail = user.email?.toLowerCase();
if (!normalizedEmail) return false;

const [existingUser] = await db.select().from(users).where(eq(users.email, normalizedEmail)).limit(1);

if (!existingUser) {
const isAdmin = user.email === process.env.ADMIN_EMAIL;
const isAdmin = normalizedEmail === process.env.ADMIN_EMAIL?.toLowerCase();
await db.insert(users).values({
email: user.email!,
email: normalizedEmail,
name: user.name,
image: user.image,
status: isAdmin ? "APPROVED" : "PENDING",
Expand All @@ -108,7 +112,8 @@ export const authOptions: NextAuthOptions = {
},
async jwt({ token, user }) {
if (user) {
const [dbUser] = await db.select().from(users).where(eq(users.email, user.email!)).limit(1);
const normalizedEmail = user.email?.toLowerCase();
const [dbUser] = await db.select().from(users).where(eq(users.email, normalizedEmail!)).limit(1);
if (dbUser) {
token.id = dbUser.id;
token.role = dbUser.role;
Expand Down
1 change: 0 additions & 1 deletion scripts/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ function main() {
}

const defaultEnv = {
NEXTAUTH_URL: 'http://localhost:3000',
NEXTAUTH_SECRET: crypto.randomBytes(32).toString('hex'),
DATABASE_URL: 'file:./dev.db',
ADMIN_EMAIL: 'admin@virtuehearts.org',
Expand Down