Skip to content

Commit 069a057

Browse files
authored
feat(firestore-stripe-payments): createPortalLink auth tweaks (#420)
Throw 'unauthenticated' code instead of 'failed-precondition' and use optional chaining (supported in Node 14) to avoid redundant check for 'context.auth.uid'.
1 parent e97216a commit 069a057

File tree

1 file changed

+3
-4
lines changed
  • firestore-stripe-payments/functions/src

1 file changed

+3
-4
lines changed

firestore-stripe-payments/functions/src/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,16 +329,15 @@ exports.createCheckoutSession = functions
329329
export const createPortalLink = functions.https.onCall(
330330
async (data, context) => {
331331
// Checking that the user is authenticated.
332-
if (!context.auth) {
332+
const uid = context.auth?.uid;
333+
if (!uid) {
333334
// Throwing an HttpsError so that the client gets the error details.
334335
throw new functions.https.HttpsError(
335-
'failed-precondition',
336+
'unauthenticated',
336337
'The function must be called while authenticated!'
337338
);
338339
}
339-
const uid = context.auth.uid;
340340
try {
341-
if (!uid) throw new Error('Not authenticated!');
342341
const { returnUrl: return_url, locale = 'auto', configuration } = data;
343342
// Get stripe customer id
344343
const customer = (

0 commit comments

Comments
 (0)