@@ -3,7 +3,6 @@ import { db, auth } from "../firebase"
33import { z } from "zod"
44import { checkRequestZod , checkAuth } from "../common"
55import { setRole } from "../auth"
6- import { Role } from "../auth/types"
76
87const CreateProfileRequest = z . object ( {
98 requestedRole : z . enum ( [ "user" , "organization" , "pendingUpgrade" ] )
@@ -14,25 +13,31 @@ export const finishSignup = functions.https.onCall(async (data, context) => {
1413
1514 const { requestedRole } = checkRequestZod ( CreateProfileRequest , data )
1615
17- let role : Role = requestedRole
16+ const {
17+ fullName,
18+ orgCategories,
19+ notificationFrequency,
20+ email,
21+ public : isPublic
22+ } = data
1823
1924 // Only an admin can approve organizations, after they've signed up initially
2025 // There's a nextjs api route: PATCH /users/<uid> {"role": <role>}
21-
22- // Removing the "pendingUpgrade" flow (temporarily) because the
23- // organization approval process is currently too cumbersome.
24-
25- // if (requestedRole === "organization") {
26- // role = "pendingUpgrade"
27- // }
28-
29- await setRole ( { role , auth , db , uid } )
30-
31- // upgrade requests table pulls from the profiles collection
32- await db . doc ( `profiles/ ${ uid } ` ) . set (
33- {
34- role
35- } ,
36- { merge : true }
37- )
26+ if ( requestedRole === "organization" ) {
27+ await setRole ( {
28+ role : "organization" ,
29+ auth ,
30+ db ,
31+ uid ,
32+ newProfile : { fullName , email , orgCategories }
33+ } )
34+ } else {
35+ await setRole ( {
36+ role : "user" ,
37+ auth ,
38+ db ,
39+ uid ,
40+ newProfile : { fullName , notificationFrequency , email , public : isPublic }
41+ } )
42+ }
3843} )
0 commit comments