add oauth and create suggestion

This commit is contained in:
2023-12-09 23:03:04 +01:00
parent 4a3ff6c7ac
commit ff2d5ae7a8
9 changed files with 143 additions and 35 deletions

View File

@@ -1,11 +1,22 @@
import { z } from 'zod'
const SuggestionValidator = z.object({
author: z.string().trim(),
content: z.string(),
}).parse
export default defineEventHandler(async (event) => {
const { author, content } = await getValidatedQuery(event, SuggestionValidator)
const { content } = await readValidatedBody(event, SuggestionValidator)
const { user } = await requireUserSession(event)
return await usePrisma().suggestion.upsert({
where: {
author: user.email,
},
update: {
content,
},
create: {
author: user.email,
content,
},
})
})

View File

@@ -28,7 +28,7 @@ export default defineEventHandler(async (event) => {
return await prisma.talent.findMany({
where: whereClause,
orderBy: {
createdAt: 'desc',
name: 'asc',
},
include: {
categories: {

View File

@@ -0,0 +1,18 @@
export default oauth.githubEventHandler({
config: {
emailRequired: true,
},
async onSuccess(event: any, { user }: any) {
await setUserSession(event, {
user: {
email: user.email,
picture: user.avatar_url,
username: String(user.name).trim(),
},
})
return sendRedirect(event, '/')
},
onError(error: any) {
console.error('GitHub OAuth error:', error)
},
})

View File

@@ -0,0 +1,12 @@
export default oauth.githubEventHandler({
async onSuccess(event: any, { user }: any) {
await setUserSession(event, {
user: {
email: user.email,
picture: user.photoUrl,
username: String(user.displayName).trim(),
},
})
return sendRedirect(event, '/')
},
})