Skip to content

Commit bf2ee79

Browse files
committed
Fix auth generation function and temporarily exclude timestamp checks from security rules
1 parent 75d2a3f commit bf2ee79

File tree

4 files changed

+1069
-37
lines changed

4 files changed

+1069
-37
lines changed

firebase/firestore.rules

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@ service cloud.firestore {
2323
request.auth.uid == userId
2424
;
2525
allow update: if
26-
// Type checks
27-
(!('sharedUntil' in request.resource.data.keys()) || request.resource.data.sharedUntil is timestamp) &&
28-
29-
30-
// Validation rules
31-
((!('sharedUntil' in request.resource.data)) || (request.resource.data.sharedUntil == request.time)) &&
32-
33-
3426
// Ownership rules
3527
request.auth.uid == userId
3628
;

firebase/functions/src/index.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as admin from 'firebase-admin'
22
import * 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

66
const 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
}
5050
const 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

Comments
 (0)