-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preserve site without api #87
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
export async function sendQuestion({ | ||
question, | ||
slug, | ||
recaptchaToken, | ||
userId, | ||
}: { | ||
question: string; | ||
slug: string; | ||
recaptchaToken: string; | ||
userId: string; | ||
}) { | ||
const isRecaptchaValid = await validateRecaptcha(recaptchaToken); | ||
if (!isRecaptchaValid) { | ||
console.error('Recaptcha validation failed'); | ||
return 400; | ||
} | ||
if (!question || !slug) { | ||
return 400; | ||
} | ||
const res = await fetch(`https://konf-qna.kir-dev.hu/api/presentation/${slug}/question`, { | ||
method: 'POST', | ||
body: JSON.stringify({ content: question, userId }), | ||
}); | ||
if (res.status === 200) { | ||
return 201; | ||
} else if (res.status === 400) { | ||
return 400; | ||
} | ||
return 500; | ||
} | ||
|
||
async function validateRecaptcha(token: string) { | ||
const res = await fetch('https://www.google.com/recaptcha/api/siteverify', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
}, | ||
body: `secret=${process.env.RECAPTCHA_SECRET}&response=${token}`, | ||
}); | ||
const data = await res.json(); | ||
return data.success; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would've been better if this was left here as a comment, could be a big help next year.
Also at the network functions
No description provided.