11import * as admin from 'firebase-admin'
22import * as functions from 'firebase-functions'
3- import { CallableContext , Request } from 'firebase-functions/lib/providers/https'
4- import { ChargebeeSubscriptionAPIClient , CustomClaimsSetter , refreshUserSubscriptionStatus } from "./subscriptions" ;
3+ import { CallableContext , Request } from 'firebase-functions/lib/providers/https'
4+ import { ChargebeeSubscriptionAPIClient , CustomClaimsSetter , refreshUserSubscriptionStatus } from "./subscriptions" ;
55
66const chargebee = require ( 'chargebee' )
77
@@ -41,15 +41,15 @@ const notAuthenticatedResponse = errorResponse('auth', 'Not Authenticated')
4141 * Helper function to set the user Auth context of an emulator
4242 * @param context
4343 */
44- const helpTesting = ( context : any ) => {
44+ const helpTesting = ( context : CallableContext ) => {
4545 if ( runningInEmulator ) {
46- context . auth = testUserDetails
46+ context . auth = testUserDetails as any
4747 }
4848 return context ;
4949}
5050const testUserDetails = {
5151 uid : 'CGPoLZClUlh1pIejEFwKjv3lCl32' ,
52- token :
{ "email" :
"[email protected] " } , 52+ token :
{ "email" :
"[email protected] " } , 5353}
5454
5555/**
@@ -78,12 +78,17 @@ const resultFormatter = (error: any, result: any) => {
7878 )
7979 }
8080
81- return { result} ;
81+ return { result } ;
8282}
8383
84- export const getLoginToken = functions . https . onCall ( async ( data : any , _context : CallableContext ) => {
84+ export const getLoginToken = functions . https . onCall ( async ( data : any , _context : CallableContext ) => {
8585 const context = helpTesting ( _context )
86- return admin . auth ( ) . createCustomToken ( context . uid )
86+ const uid = context . auth && context . auth . uid
87+ if ( uid ) {
88+ return admin . auth ( ) . createCustomToken ( uid )
89+ } else {
90+ return null
91+ }
8792} ) ;
8893
8994/**
@@ -102,7 +107,7 @@ const getCheckoutLink = functions.https.onCall(
102107 chargebee . configure ( getChargebeeOptions ( ) )
103108
104109 const checkoutOptions = {
105- subscription : { plan_id : data . planId } ,
110+ subscription : { plan_id : data . planId } ,
106111 customer : getUser ( context ) ,
107112 }
108113
0 commit comments