Feature: Added self-service merchant registration and updated login onboarding flow

This commit is contained in:
mstfyldz
2026-03-12 23:25:47 +03:00
parent 889eff49c8
commit 252d18bec6
3 changed files with 213 additions and 1 deletions

View File

@@ -0,0 +1,37 @@
import { NextRequest, NextResponse } from 'next/server';
import { db } from '@/lib/db';
import crypto from 'crypto';
export async function POST(req: NextRequest) {
try {
const { name } = await req.json();
if (!name || name.length < 3) {
return NextResponse.json({ error: 'Firma adı en az 3 karakter olmalıdır.' }, { status: 400 });
}
// Generate a 10-char ID
const short_id = crypto.randomBytes(5).toString('hex');
const api_key = crypto.randomBytes(24).toString('hex'); // Secure API Key
// Insert into database
const result = await db.query(
`INSERT INTO merchants (name, short_id, api_key)
VALUES ($1, $2, $3)
RETURNING *`,
[name, short_id, api_key]
);
const merchant = result.rows[0];
return NextResponse.json({
success: true,
merchantId: merchant.id,
shortId: merchant.short_id,
apiKey: merchant.api_key
});
} catch (err: any) {
console.error('[Registration Error]:', err.message);
return NextResponse.json({ error: 'Sunucu hatası: ' + err.message }, { status: 500 });
}
}