-
-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathmodifyAccount.ts
More file actions
41 lines (31 loc) · 987 Bytes
/
modifyAccount.ts
File metadata and controls
41 lines (31 loc) · 987 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import * as functions from "firebase-functions"
import { db, auth } from "../firebase"
import { z } from "zod"
import {
checkRequestZod,
checkAuth,
checkAdmin,
checkAuthv2,
checkAdminv2
} from "../common"
import { setRole } from "."
import { onCall, CallableRequest } from "firebase-functions/v2/https"
import { ZRole } from "./types"
const Request = z.object({
uid: z.string(),
role: ZRole
})
export const modifyAccount = functions.https.onCall(async (data, context) => {
checkAuth(context, false)
checkAdmin(context)
const { uid, role } = checkRequestZod(Request, data)
console.log(`Setting role for ${uid} to ${role}`)
await setRole({ role, auth, db, uid })
})
export const modifyAccountv2 = onCall(async (request: CallableRequest) => {
checkAuthv2(request, false)
checkAdminv2(request)
const { uid, role } = checkRequestZod(Request, request.data)
console.log(`Setting role for ${uid} to ${role}`)
await setRole({ role, auth, db, uid })
})