save twitch credentials cloud function
This commit is contained in:
parent
24933165a2
commit
8d567e06b4
|
@ -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'
|
||||||
|
|
24
functions/src/save-twitch-credentials.ts
Normal file
24
functions/src/save-twitch-credentials.ts
Normal 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()
|
Loading…
Reference in New Issue
Block a user