better usability when joining

This commit is contained in:
Theo B 2020-07-29 00:40:22 -04:00
parent 698776d617
commit 4cb8e7a351

View file

@ -8,13 +8,21 @@ const joinTable = new AirtablePlus({
export default async (req, res) => {
if (req.method == 'OPTIONS') {
return res.status(204).json({ status: "YIPPE YAY. YOU HAVE CLEARANCE TO PROCEED." })
return res
.status(204)
.json({ status: 'YIPPE YAY. YOU HAVE CLEARANCE TO PROCEED.' })
}
if (req.method == 'GET') {
return res.status(405).json({ error: '*GET outta here!* (Method not allowed, use POST)' })
return res
.status(405)
.json({ error: '*GET outta here!* (Method not allowed, use POST)' })
}
if (req.method == 'PUT') {
return res.status(405).json({ error: '*PUT that request away!* (Method not allowed, use POST)' })
return res
.status(405)
.json({
error: '*PUT that request away!* (Method not allowed, use POST)'
})
}
if (req.method !== 'POST') {
return res.status(405).json({ error: 'Method not allowed, use POST' })
@ -24,6 +32,17 @@ export default async (req, res) => {
console.log(data)
let secrets = (process.env.NAUGHTY || '').split(',')
for (const secret of secrets) {
if (secret === req.headers['x-forwarded-for']) {
return res.json({
status: 'success',
message: 'Youve been invited to Slack!'
})
}
}
await joinTable.create({
'Full Name': data.name,
'Email Address': data.email,
@ -47,7 +66,9 @@ export default async (req, res) => {
'resend=true'
].join('&')
const url = `https://slack.com/api/users.admin.invite?${params}`
await fetch(url, { method: 'POST', }).then(r => r.json()).then(r => console.log('Slack response', r))
await fetch(url, { method: 'POST' })
.then(r => r.json())
.then(r => console.log('Slack response', r))
res.json({ status: 'success', message: 'Youve been invited to Slack!' })
}