Sync auth status between your Chrome Extension and web app
Clerk allows you to sync the authentication state from your web app to your Chrome Extension using Clerk's Sync Host feature. When a user authenticates in your web app, they will also be authenticated in your Chrome Extension.
Add PLASMO_PUBLIC_CLERK_SYNC_HOST
to your environment variables
The PLASMO_PUBLIC_CLERK_SYNC_HOST
environment variable defines the host that the Chrome Extension will sync with.
The values for PLASMO_PUBLIC_CLERK_SYNC_HOST
will differ between development and production environments. Using separate .env.development
and .env.production
files allows you to seamlessly pass the appropriate values to your builds.
Use the following tabs to view the instructions for development versus production instances.
Add PLASMO_PUBLIC_CLERK_SYNC_HOST
to your .env.development
file. The value should be http://localhost
.
Add PLASMO_PUBLIC_CLERK_SYNC_HOST
to your .env.production
file. The value should be the domain your web app's production server runs on. For example, https://clerk.com
.
Add syncHost
prop to your <ClerkProvider>
Add the syncHost
prop to your Chrome Extension's <ClerkProvider>
component. This prop tells the <ClerkProvider>
which host to sync with.
Configure host_permissions
host_permissions
specifies which hosts, or websites, will have permission to sync auth state with your app. It accepts an array, allowing you to add more than one host.
In the package.json
file, in the manifest
object, update the host_permissions
array. Remove http://localhost/*
and replace with $PLASMO_PUBLIC_CLERK_SYNC_HOST/*
, as shown in the following example:
Add the Extension's ID to your web app's allowed_origins
To allow your Chrome Extension to sync with your web app, you must add the extension's ID to your web app's allowed_origins
.
- In the Clerk Dashboard, navigate to the API Keys page.
- Copy your secret key. It should start with
pk_test_
orpk_live_
for your development and production instances, respectively. - In your terminal, paste the following command. Replace
YOUR_SECRET_KEY
with your Clerk secret key and the<CHROME_EXTENSION_KEY>
with your extension's ID.
The final result should resemble the following:
Feedback
Last updated on