You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Always use 2nd-gen functions for new development.
4
-
*Use v1 functions *only* for Analytics, basic Auth, and Test Lab triggers.
5
-
* Use `firebase-functions` SDK version 6.0.0 and above
6
-
* Use top-level imports (e.g., `firebase-functions/https`). These are 2nd gen by default.
3
+
- Always use 2nd-gen functions for new development.
4
+
-Use v1 functions _only_ for Analytics, basic Auth, and Test Lab triggers.
5
+
- Use `firebase-functions` SDK version 6.0.0 and above
6
+
- Use top-level imports (e.g., `firebase-functions/https`). These are 2nd gen by default.
7
7
8
8
## Configuration: Use Secret Params for API Keys
9
9
10
10
For sensitive information like API keys (e.g., for LLMs, payment providers, etc.), **always** use `defineSecret`. This stores the value securely in Cloud Secret Manager.
// Use the apiKey to make a call to the LLM service
25
-
logger.info('Calling LLM with API key.');
25
+
logger.info("Calling LLM with API key.");
26
26
27
27
// insert code here to call LLM...
28
-
29
-
res.send('LLM API call initiated.');
28
+
29
+
res.send("LLM API call initiated.");
30
30
});
31
31
```
32
+
32
33
When you deploy a function with `secrets`, the CLI will prompt you to enter the secret's value.
33
34
34
35
## Use the Firebase Admin SDK
36
+
35
37
To interact with Firebase services like Firestore, Auth, or RTDB from within your functions, you need to initialize the Firebase Admin SDK. Call `initializeApp` without any arguments so that Application Default Credentials are used.
36
38
37
39
1.**Install the SDK:**
40
+
38
41
```bash
39
42
npm i firebase-admin
40
43
```
41
44
42
45
2. **Initialize in your code:**
46
+
43
47
```typescript
44
-
import * as admin from 'firebase-admin';
48
+
import * as admin from "firebase-admin";
45
49
46
50
admin.initializeApp();
47
51
```
52
+
48
53
This should be done once at the top level of your `index.ts` file.
0 commit comments