Initial Falah Mobile rebuild — all 7 blocks complete

- Auth system (login/register/profile)
- Nur AI chat with persona system
- Souq marketplace with FLH economy
- Forum community with Shariah moderation
- Wallet & FLH top-up
- Premium/Pro tier upgrade with Polar.sh
- Halal Monitor with map & bookmarks
- Home dashboard with daily verse & streaks
- Health endpoints

Next.js 16.2.7, Prisma v5 SQLite, JWT auth, Tailwind CSS v4
This commit is contained in:
root
2026-06-15 09:28:22 +02:00
parent ab8a2053e1
commit 5483dd291e
56 changed files with 7619 additions and 100 deletions
+59
View File
@@ -0,0 +1,59 @@
import { NextRequest, NextResponse } from "next/server";
import bcrypt from "bcryptjs";
import { prisma } from "@/lib/prisma";
import { signJWT } from "@/lib/auth";
export async function POST(req: NextRequest) {
try {
const { email, password } = await req.json();
if (!email || !password) {
return NextResponse.json(
{ error: "Email and password are required" },
{ status: 400 }
);
}
const user = await prisma.user.findUnique({ where: { email } });
if (!user || !user.passwordHash) {
return NextResponse.json(
{ error: "Invalid email or password" },
{ status: 401 }
);
}
const valid = await bcrypt.compare(password, user.passwordHash);
if (!valid) {
return NextResponse.json(
{ error: "Invalid email or password" },
{ status: 401 }
);
}
const token = await signJWT({
userId: user.id,
email: user.email,
isPremium: user.isPremium,
isPro: user.isPro,
});
return NextResponse.json({
token,
user: {
id: user.id,
email: user.email,
name: user.name,
isPremium: user.isPremium,
isPro: user.isPro,
flhBalance: user.flhBalance,
dailyMsgCount: user.dailyMsgCount,
},
});
} catch (error) {
console.error("Login error:", error);
return NextResponse.json(
{ error: "Login failed. Please try again." },
{ status: 500 }
);
}
}
+37
View File
@@ -0,0 +1,37 @@
import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";
import { requireAuth } from "@/lib/auth";
export async function GET(req: NextRequest) {
const jwtPayload = await requireAuth(req);
if (!jwtPayload) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
const user = await prisma.user.findUnique({
where: { id: jwtPayload.userId },
});
if (!user) {
return NextResponse.json({ error: "User not found" }, { status: 404 });
}
return NextResponse.json({
user: {
id: user.id,
email: user.email,
name: user.name,
isPremium: user.isPremium,
isPro: user.isPro,
flhBalance: user.flhBalance,
dailyMsgCount: user.dailyMsgCount,
experienceLevel: user.experienceLevel,
madhab: user.madhab,
coachPersona: user.coachPersona,
preferredName: user.preferredName,
coachingGoals: user.coachingGoals,
trialEndsAt: user.trialEndsAt,
createdAt: user.createdAt,
},
});
}
+70
View File
@@ -0,0 +1,70 @@
import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";
import { requireAuth } from "@/lib/auth";
const VALID_MADHABS = ["Hanafi", "Maliki", "Shafi'i", "Hanbali"];
export async function PATCH(req: NextRequest) {
const jwtPayload = await requireAuth(req);
if (!jwtPayload) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
try {
const body = await req.json();
const { name, preferredName, coachPersona, madhab, coachingGoals } = body;
if (madhab && !VALID_MADHABS.includes(madhab)) {
return NextResponse.json(
{
error: `Invalid madhab. Must be one of: ${VALID_MADHABS.join(", ")}`,
},
{ status: 400 }
);
}
const updateData: Record<string, string | undefined> = {};
if (name !== undefined) updateData.name = name;
if (preferredName !== undefined) updateData.preferredName = preferredName;
if (coachPersona !== undefined) updateData.coachPersona = coachPersona;
if (madhab !== undefined) updateData.madhab = madhab;
if (coachingGoals !== undefined) updateData.coachingGoals = coachingGoals;
if (Object.keys(updateData).length === 0) {
return NextResponse.json(
{ error: "No fields to update" },
{ status: 400 }
);
}
const user = await prisma.user.update({
where: { id: jwtPayload.userId },
data: updateData,
});
return NextResponse.json({
user: {
id: user.id,
email: user.email,
name: user.name,
isPremium: user.isPremium,
isPro: user.isPro,
flhBalance: user.flhBalance,
dailyMsgCount: user.dailyMsgCount,
experienceLevel: user.experienceLevel,
madhab: user.madhab,
coachPersona: user.coachPersona,
preferredName: user.preferredName,
coachingGoals: user.coachingGoals,
trialEndsAt: user.trialEndsAt,
createdAt: user.createdAt,
},
});
} catch (error) {
console.error("Profile update error:", error);
return NextResponse.json(
{ error: "Profile update failed" },
{ status: 500 }
);
}
}
+63
View File
@@ -0,0 +1,63 @@
import { NextRequest, NextResponse } from "next/server";
import bcrypt from "bcryptjs";
import { prisma } from "@/lib/prisma";
import { signJWT } from "@/lib/auth";
export async function POST(req: NextRequest) {
try {
const { email, name, password } = await req.json();
if (!email || !name || !password) {
return NextResponse.json(
{ error: "Email, name, and password are required" },
{ status: 400 }
);
}
const existing = await prisma.user.findUnique({ where: { email } });
if (existing) {
return NextResponse.json(
{ error: "An account with this email already exists" },
{ status: 409 }
);
}
const passwordHash = await bcrypt.hash(password, 12);
const user = await prisma.user.create({
data: {
email,
name,
passwordHash,
flhBalance: 5000,
trialEndsAt: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000),
},
});
const token = await signJWT({
userId: user.id,
email: user.email,
isPremium: user.isPremium,
isPro: user.isPro,
});
return NextResponse.json({
token,
user: {
id: user.id,
email: user.email,
name: user.name,
isPremium: user.isPremium,
isPro: user.isPro,
flhBalance: user.flhBalance,
dailyMsgCount: user.dailyMsgCount,
},
});
} catch (error) {
console.error("Register error:", error);
return NextResponse.json(
{ error: "Registration failed. Please try again." },
{ status: 500 }
);
}
}