use user id instead of bot id, add manifold api endpoint
This commit is contained in:
parent
8d567e06b4
commit
f6e5fe8a5e
|
@ -1,22 +1,20 @@
|
||||||
import * as admin from 'firebase-admin'
|
import * as admin from 'firebase-admin'
|
||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
|
|
||||||
import { APIError, newEndpoint, validate } from './api'
|
import { newEndpoint, validate } from './api'
|
||||||
|
|
||||||
const bodySchema = z.object({
|
const bodySchema = z.object({
|
||||||
userId: z.string(),
|
|
||||||
twitchInfo: z.object({
|
twitchInfo: z.object({
|
||||||
twitchName: z.string(),
|
twitchName: z.string(),
|
||||||
controlToken: z.string(),
|
controlToken: z.string(),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
const BOT_ID = 'BOT_ID'
|
|
||||||
|
|
||||||
export const savetwitchcredentials = newEndpoint({}, async (req, auth) => {
|
export const savetwitchcredentials = newEndpoint({}, async (req, auth) => {
|
||||||
if (auth.uid !== BOT_ID) throw new APIError(403, 'Invalid access credentials')
|
const { twitchInfo } = validate(bodySchema, req.body)
|
||||||
|
const userId = auth.uid
|
||||||
|
|
||||||
const { userId, twitchInfo } = validate(bodySchema, req.body)
|
|
||||||
await firestore.doc(`private-users/${userId}`).update({ twitchInfo })
|
await firestore.doc(`private-users/${userId}`).update({ twitchInfo })
|
||||||
return { success: true }
|
return { success: true }
|
||||||
})
|
})
|
||||||
|
|
23
web/pages/api/v0/twitch/save.ts
Normal file
23
web/pages/api/v0/twitch/save.ts
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
import { NextApiRequest, NextApiResponse } from 'next'
|
||||||
|
import {
|
||||||
|
CORS_ORIGIN_MANIFOLD,
|
||||||
|
CORS_ORIGIN_LOCALHOST,
|
||||||
|
} from 'common/envs/constants'
|
||||||
|
import { applyCorsHeaders } from 'web/lib/api/cors'
|
||||||
|
import { fetchBackend, forwardResponse } from 'web/lib/api/proxy'
|
||||||
|
|
||||||
|
export const config = { api: { bodyParser: true } }
|
||||||
|
|
||||||
|
export default async function route(req: NextApiRequest, res: NextApiResponse) {
|
||||||
|
await applyCorsHeaders(req, res, {
|
||||||
|
origin: [CORS_ORIGIN_MANIFOLD, CORS_ORIGIN_LOCALHOST],
|
||||||
|
methods: 'POST',
|
||||||
|
})
|
||||||
|
try {
|
||||||
|
const backendRes = await fetchBackend(req, 'savetwitchcredentials')
|
||||||
|
await forwardResponse(res, backendRes)
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error talking to cloud function: ', err)
|
||||||
|
res.status(500).json({ message: 'Error communicating with backend.' })
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user