first commit
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import {
|
||||
getAppUserLoginContextFromRequest,
|
||||
loginAppUser,
|
||||
} from "@/server/app/app-auth";
|
||||
import { NextResponse } from "next/server";
|
||||
import { z } from "zod";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
const loginSchema = z.object({
|
||||
email: z.email(),
|
||||
password: z.string().min(1),
|
||||
});
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const parsed = loginSchema.safeParse(await request.json());
|
||||
|
||||
if (!parsed.success) {
|
||||
return NextResponse.json(
|
||||
{ ok: false, error: "Invalid request body." },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
const data = await loginAppUser({
|
||||
...parsed.data,
|
||||
context: getAppUserLoginContextFromRequest(request),
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
ok: true,
|
||||
data,
|
||||
});
|
||||
} catch (error) {
|
||||
const message =
|
||||
error instanceof Error ? error.message : "Unknown error.";
|
||||
return NextResponse.json(
|
||||
{ ok: false, error: message },
|
||||
{ status: 401 },
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import { registerAppUser } from "@/server/app/app-auth";
|
||||
import { NextResponse } from "next/server";
|
||||
import { z } from "zod";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
const registerSchema = z.object({
|
||||
email: z.email(),
|
||||
password: z.string().min(8),
|
||||
displayName: z.string().optional().nullable(),
|
||||
});
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const parsed = registerSchema.safeParse(await request.json());
|
||||
|
||||
if (!parsed.success) {
|
||||
return NextResponse.json(
|
||||
{ ok: false, error: "Invalid request body." },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
const data = await registerAppUser(parsed.data);
|
||||
|
||||
return NextResponse.json({
|
||||
ok: true,
|
||||
data,
|
||||
});
|
||||
} catch (error) {
|
||||
const message =
|
||||
error instanceof Error ? error.message : "Unknown error.";
|
||||
return NextResponse.json(
|
||||
{ ok: false, error: message },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user