mirror of
https://github.com/ArthurDanjou/website.git
synced 2026-01-18 22:11:42 +01:00
add oauth and create suggestion
This commit is contained in:
@@ -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,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
@@ -28,7 +28,7 @@ export default defineEventHandler(async (event) => {
|
||||
return await prisma.talent.findMany({
|
||||
where: whereClause,
|
||||
orderBy: {
|
||||
createdAt: 'desc',
|
||||
name: 'asc',
|
||||
},
|
||||
include: {
|
||||
categories: {
|
||||
|
||||
18
src/server/routes/auth/github.get.ts
Normal file
18
src/server/routes/auth/github.get.ts
Normal 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)
|
||||
},
|
||||
})
|
||||
12
src/server/routes/auth/google.get.ts
Normal file
12
src/server/routes/auth/google.get.ts
Normal 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, '/')
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user