save twitch credentials cloud function

This commit is contained in:
mantikoros 2022-08-30 12:12:41 -05:00
parent 24933165a2
commit 8d567e06b4
2 changed files with 25 additions and 0 deletions

View File

@ -53,6 +53,7 @@ export * from './resolve-market'
export * from './unsubscribe' export * from './unsubscribe'
export * from './stripe' export * from './stripe'
export * from './mana-bonus-email' export * from './mana-bonus-email'
export * from './save-twitch-credentials'
import { health } from './health' import { health } from './health'
import { transact } from './transact' import { transact } from './transact'

View File

@ -0,0 +1,24 @@
import * as admin from 'firebase-admin'
import { z } from 'zod'
import { APIError, newEndpoint, validate } from './api'
const bodySchema = z.object({
userId: z.string(),
twitchInfo: z.object({
twitchName: z.string(),
controlToken: z.string(),
}),
})
const BOT_ID = 'BOT_ID'
export const savetwitchcredentials = newEndpoint({}, async (req, auth) => {
if (auth.uid !== BOT_ID) throw new APIError(403, 'Invalid access credentials')
const { userId, twitchInfo } = validate(bodySchema, req.body)
await firestore.doc(`private-users/${userId}`).update({ twitchInfo })
return { success: true }
})
const firestore = admin.firestore()