All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 9m43s
29 lines
893 B
TypeScript
29 lines
893 B
TypeScript
import { Router } from "express";
|
|
import { createKey } from "../services/keys.js";
|
|
import logger from "../services/logger.js";
|
|
|
|
export const signupRouter = Router();
|
|
|
|
// Simple signup: email → instant API key (no verification for now)
|
|
signupRouter.post("/free", async (req, res) => {
|
|
const { email } = req.body;
|
|
|
|
if (!email || typeof email !== "string" || !email.includes("@")) {
|
|
res.status(400).json({ error: "Valid email required" });
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const key = await createKey(email.toLowerCase().trim(), "free");
|
|
logger.info({ email: email.slice(0, 3) + "***" }, "Free signup");
|
|
res.json({
|
|
apiKey: key.key,
|
|
tier: "free",
|
|
limit: 100,
|
|
message: "Your API key is ready! 100 free screenshots/month.",
|
|
});
|
|
} catch (err: any) {
|
|
logger.error({ err }, "Signup failed");
|
|
res.status(500).json({ error: "Signup failed" });
|
|
}
|
|
});
|