Fix API URLs: signup/login now use /autojobs/api/auth/*, fix JSONResponse import, fix db references in Stripe checkout

This commit is contained in:
2026-04-14 14:17:04 +02:00
parent 21d65286f7
commit 4417bb2a57
3 changed files with 15 additions and 7 deletions
+13 -5
View File
@@ -5,6 +5,7 @@ import os
import stripe
"""
from fastapi import FastAPI, HTTPException, Depends, APIRouter, Request
from fastapi.responses import JSONResponse
from fastapi.middleware.cors import CORSMiddleware
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
from pydantic import BaseModel
@@ -959,13 +960,18 @@ async def create_checkout(request: Request):
if price_id is None and plan_id != "agency_enterprise":
return JSONResponse({"error": "Invalid plan"}, status_code=400)
user = db.get("SELECT * FROM users WHERE id = ?", (user_id,))
conn = sqlite3.connect(DB_PATH)
conn.row_factory = sqlite3.Row
user = conn.execute("SELECT * FROM users WHERE id = ?", (user_id,)).fetchone()
if not user:
return JSONResponse({"error": "User not found"}, status_code=404)
if plan_id == "free":
# Free plan - just update and return
db.run("UPDATE users SET plan = ?, user_type = ? WHERE id = ?", (plan_id, user_type, user_id))
conn.execute("UPDATE users SET plan = ?, user_type = ? WHERE id = ?", (plan_id, user_type, user_id))
conn.commit()
conn.close()
return JSONResponse({"success": True, "plan": plan_id})
return JSONResponse({"success": True, "plan": plan_id})
if plan_id == "agency_enterprise":
@@ -975,7 +981,7 @@ async def create_checkout(request: Request):
stripe.api_key = os.environ.get("STRIPE_SECRET_KEY")
customer = stripe.Customer.create(
email=user["email"],
name=user["name"],
name=user["name"] or user[1],
metadata={"autojobs_user_id": str(user_id)}
)
@@ -1018,13 +1024,15 @@ async def stripe_webhook(request: Request):
plan_id = session["metadata"]["plan_id"]
stripe_sub_id = session.get("subscription")
db.run("UPDATE users SET plan = ?, stripe_subscription_id = ?, stripe_customer_id = ? WHERE id = ?",
conn.execute("UPDATE users SET plan = ?, stripe_subscription_id = ?, stripe_customer_id = ? WHERE id = ?",
(plan_id, stripe_sub_id, session.get("customer"), user_id))
conn.commit()
elif event_type == "customer.subscription.deleted":
sub = event["data"]["object"]
customer_id = sub.get("customer")
db.run("UPDATE users SET plan = 'free' WHERE stripe_customer_id = ?", (customer_id,))
conn.execute("UPDATE users SET plan = 'free' WHERE stripe_customer_id = ?", (customer_id,))
conn.commit()
return JSONResponse({"received": True})
+1 -1
View File
@@ -15,7 +15,7 @@ export default function LoginPage() {
setError("")
try {
const res = await fetch("/api/auth/login", {
const res = await fetch("/autojobs/api/auth/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(form)
+1 -1
View File
@@ -39,7 +39,7 @@ function SignupForm() {
setError("")
try {
const res = await fetch("/api/auth/signup", {
const res = await fetch("/autojobs/api/auth/signup", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({