|
21 | 21 | const {
|
22 | 22 | onDocumentWrittenWithAuthContext,
|
23 | 23 | } = require("firebase-functions/v2/firestore");
|
24 |
| -const { logger } = require("firebase-functions"); |
| 24 | +const {logger} = require("firebase-functions"); |
25 | 25 |
|
26 | 26 | exports.verifyComment = onDocumentWrittenWithAuthContext(
|
27 |
| - "comments/{commentId}", |
28 |
| - (event) => { |
29 |
| - const snapshot = event.data; |
30 |
| - if (!snapshot) { |
31 |
| - logger.log("No data associated with the event"); |
32 |
| - return; |
33 |
| - } |
34 |
| - const data = snapshot.data(); |
| 27 | + "comments/{commentId}", |
| 28 | + (event) => { |
| 29 | + const snapshot = event.data; |
| 30 | + if (!snapshot) { |
| 31 | + logger.log("No data associated with the event"); |
| 32 | + return; |
| 33 | + } |
| 34 | + const data = snapshot.data(); |
35 | 35 |
|
36 |
| - // retrieve auth context from event |
37 |
| - const { authType, authId } = event; |
| 36 | + // retrieve auth context from event |
| 37 | + const {authType, authId} = event; |
38 | 38 |
|
39 |
| - let verified = false; |
40 |
| - if (authType === "system") { |
| 39 | + let verified = false; |
| 40 | + if (authType === "system") { |
41 | 41 | // system-generated users are automatically verified
|
42 |
| - verified = true; |
43 |
| - } else if (authType === "unknown" || authType === "unauthenticated") { |
44 |
| - // admin users from a specific domain are verified |
45 |
| - if (authId.endsWith("@example.com")) { |
46 | 42 | verified = true;
|
| 43 | + } else if (authType === "unknown" || authType === "unauthenticated") { |
| 44 | + // admin users from a specific domain are verified |
| 45 | + if (authId.endsWith("@example.com")) { |
| 46 | + verified = true; |
| 47 | + } |
47 | 48 | }
|
48 |
| - } |
49 | 49 |
|
50 |
| - // add auth medadata to the document |
51 |
| - return data.after.ref.set( |
52 |
| - { |
53 |
| - created_by: authId, |
54 |
| - verified, |
55 |
| - }, |
56 |
| - { merge: true } |
57 |
| - ); |
58 |
| - } |
| 50 | + // add auth medadata to the document |
| 51 | + return data.after.ref.set( |
| 52 | + { |
| 53 | + created_by: authId, |
| 54 | + verified, |
| 55 | + }, |
| 56 | + {merge: true}, |
| 57 | + ); |
| 58 | + }, |
59 | 59 | );
|
60 | 60 |
|
61 | 61 | // [END all]
|
0 commit comments