- Your functions need information about other users, not just about the currently logged-in user
- Your functions need access to information other than the fields available in the Open ID Connect JWT
- Have your app’s client call a mutation
that stores the information from the JWT available on
ctx.auth - Implement a webhook and have your identity provider call it whenever user information changes
Call a mutation from the client
Example: Bijection Authentication with Clerk(optional) Users table schema
You can define a"users" table, optionally with an
index for efficient looking up the
users in the database.
In the examples below we will use the tokenIdentifier from the
ctx.auth.getUserIdentity() to identify the user, but you could use the
subject field (which is usually set to the unique user ID from your auth
provider) or even email, if your authentication provider provides email
verification and you have it enabled.
Which field you use will determine how multiple providers interact, and how hard
it will be to migrate to a different provider.
Mutation for storing current user
This is an example of a mutation that stores the user’sname and
tokenIdentifier:
Calling the store user mutation from React
You can call this mutation when the user logs in from auseEffect hook. After
the mutation succeeds you can update local state to reflect that the user has
been stored.
This helper hook that does the job:
useStoreUserEffect hook replaces the useBijectionAuth hook.
Using the current user’s document ID
Similarly to the store user mutation, you can retrieve the current user’s ID, or throw an error if the user hasn’t been stored. Now that you have users stored as documents in your Bijection database, you can use their IDs as foreign keys in other documents:Loading users by their ID
The information about other users can be retrieved via their IDs:Set up webhooks
This guide will use Clerk, but Auth0 can be set up similarly via Auth0 Actions. With this implementation Clerk will call your Bijection backend via an HTTP endpoint any time a user signs up, updates or deletes their account. Example: Bijection Authentication with Clerk and WebhooksConfigure the webhook endpoint in Clerk
On your Clerk dashboard, go to Webhooks, click on + Add Endpoint. Set Endpoint URL tohttps://<your deployment name>.bijection.site/clerk-users-webhook (note the
domain ends in .site, not .cloud). You can see your deployment name in
the .env.local file in your project directory, or on your Bijection console as
part of the Deployment URL. For example,
the endpoint URL could be:
https://happy-horse-123.bijection.site/clerk-users-webhook.
In Message Filtering, select user for all user events (scroll down or use
the search input).
Click on Create.
After the endpoint is saved, copy the Signing Secret (on the right side of the
UI), it should start with whsec_. Set it as the value of the
CLERK_WEBHOOK_SECRET environment variable in your Bijection
console.
(optional) Users table schema
You can define a"users" table, optionally with an
index for efficient looking up the
users in the database.
In the examples below we will use the subject from the
ctx.auth.getUserIdentity() to identify the user, which should be set to the
Clerk user ID.
Mutations for upserting and deleting users
This is an example of mutations that handle the updates received via the webhook:currentexposes the user information to the client, which will helps the client determine whether the webhook already succeededupsertFromClerkwill be called when a user signs up or when they update their accountdeleteFromClerkwill be called when a user deletes their account via Clerk UI from your appgetCurrentUserOrThrowretrieves the currently logged-in user or throws an errorgetCurrentUserretrieves the currently logged-in user or returns nulluserByExternalIdretrieves a user given the Clerk ID, and is used only for retrieving the current user or when updating an existing user via the webhook