Stripe checkout: products created, signup flow with plan selection, API endpoints
This commit is contained in:
@@ -2,35 +2,52 @@ import { NextRequest, NextResponse } from "next/server"
|
||||
import { cookies } from "next/headers"
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const { email, password, name } = await req.json()
|
||||
const { email, password, name, user_type, plan } = await req.json()
|
||||
|
||||
if (!email || !password) {
|
||||
return NextResponse.json({ error: "Email and password required" }, { status: 400 })
|
||||
}
|
||||
|
||||
// In production: hash password, store in DB
|
||||
// For MVP: create user in backend DB, set cookie
|
||||
try {
|
||||
const res = await fetch(`${process.env.API_URL || "http://localhost:8000"}/users`, {
|
||||
const apiUrl = process.env.API_URL || "http://localhost:8000"
|
||||
|
||||
const res = await fetch(`${apiUrl}/autojobs/api/users`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ user_id: email.split("@")[0], email, name })
|
||||
body: JSON.stringify({
|
||||
email,
|
||||
name,
|
||||
user_type: user_type || "private",
|
||||
plan: plan || "free"
|
||||
})
|
||||
})
|
||||
|
||||
if (!res.ok) {
|
||||
return NextResponse.json({ error: "Failed to create user" }, { status: 500 })
|
||||
}
|
||||
|
||||
const data = await res.json()
|
||||
|
||||
const cookieStore = await cookies()
|
||||
cookieStore.set("autojobs_user", email.split("@")[0], {
|
||||
cookieStore.set("autojobs_user", email, {
|
||||
httpOnly: true,
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
sameSite: "lax",
|
||||
maxAge: 60 * 60 * 24 * 30 // 30 days
|
||||
maxAge: 60 * 60 * 24 * 30
|
||||
})
|
||||
|
||||
// Also store user_id for checkout
|
||||
if (data.id) {
|
||||
cookieStore.set("autojobs_user_id", String(data.id), {
|
||||
httpOnly: true,
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
sameSite: "lax",
|
||||
maxAge: 60 * 60 * 24 * 30
|
||||
})
|
||||
}
|
||||
|
||||
return NextResponse.json({ status: "ok" })
|
||||
return NextResponse.json({ status: "ok", user_id: data.id })
|
||||
} catch {
|
||||
return NextResponse.json({ error: "Server error" }, { status: 500 })
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user