This repository is a set of example projects showing how Foundry can be used with Firebase. The overall theme is an app where you manage users and their workspaces.
Each directory is a separate Firebase Functions project showcasing different Foundry functionality.
Some projects integrate third party services like Slack or Sendgrid. You may want to join our Slack community where we provide API keys so you don't have to create an account with these services.
How to try Foundry with example projects:
- Install Foundry CLI by following instructions
$ git clone https://github.com/FoundryApp/examples.git$ cd examples$ cd auth-functions/functionsor any different example$ foundry go
Showcase of auth trigger functions: Create a default workspace for a new user and delete the user's data from Firestore when the user is deleted from Firebase Auth.
-
onCreate function
newUserWorkspacecreates a workspace in Firestore when a new user signs up -
onDelete function
userCleanupcleans a document of just deleted user in collectionuserInfosin Firestore + automatically updates all workspaces where the user was the owner
Showcase of the emulated Firebase Auth users: Fill the emulated Firebase Auth with custom users and with users from your production Firebase Auth.
- https function
getUserEmailreturns an email of a user that is specified in the fieldcollectionsin the function's request body
Showcase of the emulated Firestore database: Fill the emulated Firestore with custom documents and also with documents from your production Firestore database.
- https function
listCollectionsDocslists documents from the collections specified in arraycollectionsin the function's request body
Showcase of Firestore trigger functions: Functionality around workspaces and Slack notifications. When you create a workspace with new members, add members to an existing workspace, or delete a workspace, a relevant Slack notification will be sent.
Functions in this project send Slack notifications and need an env variable named SLACK_WEBHOOK_URL to be set.
You can either get the webhook URL we created for this project from our Slack community or create your own webhook URL.
After getting an webhook URL run the command $ foundry env-set SLACK_WEBHOOK_URL=<the webhook URL>.
-
onCreate function
notifyMembersInNewWorkspacesends a message to Slack mentioning all members from a newly created workspace -
onUpdate function
notifyMembersAddedToWorkspacesends a message to Slack mentioning all members that were added to an existing workspace -
onDelete function
notifyMembersInDeletedWorkspacesends a message to Slack mentioning all members that were in a deleted workspace
Showcase of HTTPS and HTTPS Callable functions: Custom API endpoints accessible by an HTTPS request or from within a Firebase app using the Firebase Client SDK.
Function askForWorkspaceInvite sends emails via Sendgrid and needs an env variable named SENDGRID_API_KEY to be set.
You can either get the API key we created for this project from our Slack community or create your own Sendgrid API key.
After getting an API key run the command $ foundry env-set SENDGRID_API_KEY=<the API key>.
-
https function
askForWorkspaceInviteallows anyone to send a REST request asking the owner of a workspace for an invite. The request's body expects 2 fields:workspaceId- an ID of a workspaceemail- an email where the invite will be sent
-
httpsCallable function
changeWorkspaceOwnerallows your Firebase app users to change ownership of their workspace. The functions expects 2 parameters:workspaceId- an ID of workspace where the ownership change should happennewOwner- an ID of user that will become a new owner