Created
September 17, 2022 00:14
-
-
Save ChristianOConnor/35bf955d1d5614348c3816ce650b3b9f to your computer and use it in GitHub Desktop.
fresh app Creator Island 092622
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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