cfff74e2db
Souq Marketplace: - Native souq pages: browse+filters, create listing, detail+seller profile, orders+chat - New API: reviews (POST), sellers/[id], upload (multipart), polar-checkout webhook - Listings API enhanced: minPrice, maxPrice, sortBy, deliveryDays filters - Seller workflow: start order, mark delivered, upload files, confirm delivery - Wallet: 5 Polar.sh FLH tiers, production checkout, mock fallback, success banner - Fix: order redirect /souq/history → /souq/orders Auth System: - Unified auth page, removed OAuth provider routing (2 files deleted) - Deleted oauth.ts (319 lines) — simplified auth chain - Streamlined login/register API routes Prisma Schema (+179 lines): - New models: Listing, Purchase, Review, Group/GroupMember - Gamification: DailyStreak, XpTransaction, Achievement, UserLevel - Learning: LearnCourse/Module/Enrollment/Certificate - Notifications, Referrals, Dhikr, PremiumBenefits Deleted legacy code: - src/app/api/marketplace/* (3 files) — replaced by /api/souq/* - src/app/api/files/[listingId]/route.ts — replaced by /api/souq/upload - src/app/api/seller/[sellerId]/route.ts — replaced by /api/souq/sellers/[id] Infrastructure: - Dockerfile: standalone output, Prisma runtime migration - docker-compose.yml: Polar env vars, healthcheck fix - docker-compose.staging.yml: staging on port 4014 - .gitea/workflows/ci.yml: CI pipeline
68 lines
1.8 KiB
TypeScript
68 lines
1.8 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { prisma } from "@/lib/prisma";
|
|
import { UMMAHID_URL } 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 }
|
|
);
|
|
}
|
|
|
|
// Proxy to Ummah ID
|
|
const ummahRes = await fetch(`${UMMAHID_URL}/api/auth/login`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ email, password }),
|
|
});
|
|
|
|
const ummahData = await ummahRes.json();
|
|
|
|
if (!ummahRes.ok) {
|
|
return NextResponse.json(
|
|
{ error: ummahData.error || "Authentication failed" },
|
|
{ status: ummahRes.status }
|
|
);
|
|
}
|
|
|
|
const { token, user: ummahUser } = ummahData;
|
|
|
|
// Find or create local user by email
|
|
let localUser = await prisma.user.findUnique({ where: { email } });
|
|
if (!localUser) {
|
|
localUser = await prisma.user.create({
|
|
data: {
|
|
email,
|
|
name: ummahUser?.name || email?.split("@")[0] || "User",
|
|
provider: "ummahid",
|
|
providerId: ummahUser.id,
|
|
walletBalance: 5000,
|
|
},
|
|
});
|
|
}
|
|
|
|
return NextResponse.json({
|
|
token,
|
|
user: {
|
|
id: localUser.id,
|
|
email: localUser.email,
|
|
name: localUser.name,
|
|
isPremium: localUser.isPremium,
|
|
isPro: localUser.isPro,
|
|
flhBalance: localUser.flhBalance,
|
|
dailyMsgCount: localUser.dailyMsgCount,
|
|
},
|
|
});
|
|
} catch (error) {
|
|
console.error("Login error:", error);
|
|
return NextResponse.json(
|
|
{ error: "Login failed. Please try again." },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|