auth syncing
This commit is contained in:
@ -20,16 +20,33 @@ export default {
|
||||
|
||||
const db = drizzle(env.DB);
|
||||
|
||||
if (path === "/api/user" && method === "GET") {
|
||||
const params = url.searchParams;
|
||||
if (path === "/api/user") {
|
||||
if (method === "GET") {
|
||||
const params = url.searchParams;
|
||||
|
||||
if (params.has("id")) {
|
||||
const id = params.get("id") as string;
|
||||
const res = await db.select().from(user).where(eq(user.id, id)).get();
|
||||
return json(res ?? {});
|
||||
if (params.has("id")) {
|
||||
const id = params.get("id") as string;
|
||||
const res = await db.select().from(user).where(eq(user.id, id)).get();
|
||||
console.log(res);
|
||||
return json(res ?? {});
|
||||
} else {
|
||||
const res = await db.select().from(user).all();
|
||||
return json(res ?? {});
|
||||
}
|
||||
} else if (method === "POST") {
|
||||
const userSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
email: z.string().email(),
|
||||
});
|
||||
|
||||
const body = await request.json();
|
||||
const { id, name, email } = userSchema.parse(body);
|
||||
|
||||
const res = await db.insert(user).values({ id, name, email }).returning().get();
|
||||
return json({ res });
|
||||
} else {
|
||||
const res = await db.select().from(user).all();
|
||||
return new Response(JSON.stringify(res));
|
||||
return new Response("Method Not Allowed", { status: 405 });
|
||||
}
|
||||
} else return new Response("Not Found", { status: 404 });
|
||||
},
|
||||
|
Reference in New Issue
Block a user