|
1 |
| -# post-signup-event |
| 1 | +# Post Sign-up Event with Google Calendar |
| 2 | + |
| 3 | +This sample demonstrates how to use an [Auth blocking function](https://firebase.google.com/docs/functions/auth-blocking-events) to save a user's Google OAuth2 access token to Firestore upon sign-up. It then uses a [task queue](https://firebase.google.com/docs/functions/task-functions) to schedule a Cloud Function that uses this token to create a Google Calendar event for the user. |
| 4 | + |
| 5 | +## Functions Code |
| 6 | + |
| 7 | +See file [functions/main.py](functions/main.py) for the code. |
| 8 | + |
| 9 | +The function `savegoogletoken` is an Auth blocking function that triggers before a user is created. If the user is signing up with Google, it saves their OAuth2 access token to a `user_info` collection in Firestore. It then creates a task to call the `scheduleonboarding` function. |
| 10 | + |
| 11 | +The `scheduleonboarding` function is a task queue function that retrieves the user's access token from Firestore, creates a new event on their primary Google Calendar, and then deletes the access token from Firestore. |
| 12 | + |
| 13 | +## Trigger rules |
| 14 | + |
| 15 | +- The `savegoogletoken` function is triggered by `beforeUserCreated` Auth blocking event. |
| 16 | +- The `scheduleonboarding` function is triggered by a task queue. |
| 17 | + |
| 18 | +## Deploy and test |
| 19 | + |
| 20 | +To deploy and test the sample: |
| 21 | + |
| 22 | +1. Create a Firebase project on the [Firebase Console](https://console.firebase.google.com). |
| 23 | +2. Enable the **Google Calendar API** for your project in the [Google Cloud Console](https://console.cloud.google.com/apis/library/calendar-json.googleapis.com). |
| 24 | +3. Enable blocking functions for your project in the Firebase console: |
| 25 | + - Go to the **Authentication** > **Settings** page. |
| 26 | + - In the **Blocking functions** section, select **Before user creation (beforeCreate)** from the dropdown menu. |
| 27 | + - Ensure that **Enable credential pass-through** is checked. |
| 28 | +4. Get the code, for instance using `git clone https://github.com/firebase/functions-samples` |
| 29 | +5. Enter the correct directory `cd functions-samples/Python/post-signup-event` |
| 30 | +6. Set up the CLI to use your Firebase project using `firebase use --add` and select your Firebase project. |
| 31 | +7. Deploy your project's code using `firebase deploy`. |
| 32 | +8. Sign up for your app using a Google account. |
| 33 | +9. After a minute, check your Google Calendar for a new "Onboarding with ExampleCo" event. |
0 commit comments