Skip to content

Instantly share code, notes, and snippets.

@ChristianOConnor
Created September 17, 2022 00:14
Show Gist options
  • Save ChristianOConnor/35bf955d1d5614348c3816ce650b3b9f to your computer and use it in GitHub Desktop.
Save ChristianOConnor/35bf955d1d5614348c3816ce650b3b9f to your computer and use it in GitHub Desktop.
fresh app Creator Island 092622
import { Handlers, PageProps } from "$fresh/server.ts";
import UserDb from "../../database.ts";
export const handler = {
POST: async (request, ctx) => {
console.log(await request.json());
if (!request.hasBody) {
ctx.status = 400;
ctx.body = { msg: "Invalid user data" };
return ;
}
const body = request.body();
const {
email, key
} = JSON.parse(await body.formData());
console.log(email);
if (!email || !key) {
ctx.status = 422;
ctx.body = { msg: "Incorrect user data. Email and key are required" };
return;
}
const userId = await UserDb.create({
email: email,
key: key,
created_at: new Date()
});
ctx.body = { msg: "User created", userId };
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment