-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
api: guard movies/:id/{comments,stream} endpoint
- Loading branch information
Showing
4 changed files
with
23 additions
and
7 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
import { getServerSession, getToken } from "#auth"; | ||
|
||
export default defineEventHandler(async (event) => { | ||
// TODO: check auth | ||
const session = await getServerSession(event); | ||
const token = await getToken({ event }); | ||
if (!session || !token?.email) throw createError({ statusCode: 401 }); | ||
|
||
const users = await db | ||
.select({ id: tables.users.id }) | ||
.from(tables.users) | ||
.where(eq(tables.users.email, token.email)); | ||
|
||
const body = await readBody<{ content: string }>(event, { | ||
strict: true, | ||
}); | ||
const id = getRouterParam(event, "id"); | ||
if (!body?.content || !id) throw createError({ statusCode: 400 }); | ||
return await db | ||
.insert(tables.comments) | ||
// TODO: add user id from auth | ||
.values({ content: body.content, movie_id: id }) | ||
.values({ content: body.content, movie_id: id, authorId: users[0].id }) | ||
.returning(); | ||
}); |
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