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.
Hide unsupported authentication methods
When using the Sync Host feature, authentication methods that you want to use in your web app may not be fully supported in the Chrome Extension environment. To hide unsupported methods in your Chrome Extension, you can use the appearance
prop with your extension's <SignUp>
and <SignIn>
components as demonstrated in the following examples.
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
sk_test_
orsk_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