Frontend-only SDK
While ClerkJS can be used in any browser context and framework, realistically users expect to consume its features through the conventions and syntax of their framework of choice. For example, @clerk/clerk-react
turns ClerkJS into React components, @clerk/astro
into Astro components, and so on.
In non-browser environments, you’ll need to re-implement the Clerk class in the SDK’s programming language, interacting with the FAPI.
Expected features
- User only needs to provide their Publishable Key
- User only needs to adjust one or two files to add Clerk to their app (e.g. adding Clerk to the configuration file of that framework)
- User can use Clerk’s components in their choice of framework (e.g. in a React-based framework you import these components as React components)
- Give users access to
Client
,Session
,User
, andOrganization
properties through the framework’s choice of state management - User should be able to use ClerkJS options
Implementation
While the implementation details will vary for each SDK, there are certain steps you'll have to go through in any case. Consider the steps below a rough guidance on what needs to be done, and also remember to follow the conventions.
Create a Clerk instance
Create a Clerk instance that will only be invoked once (e.g. following the singleton pattern). During its initialization you'll execute the following steps.
Hotload ClerkJS
In order to make Clerk
available on the window
object, your SDK needs to load ClerkJS. Call loadClerkJsScript()
from @clerk/shared
.
Call window.Clerk.load()
By calling window.Clerk.load()
the Clerk class is initialized and your SDK now has access to all its functionality.
Add event listeners
Expose properties to the internal state (e.g. a useState
in React) through adding event listeners.
Add UI components
Build out the components that your users will utilize in their app. Call the mount()
function when the component is in view/mounts and the unmount()
function when the component is unmounted. These functions are described in the Clerk
class components.
Use the idiomatic way of your framework for doing this. If you can abstract these repetitions into a re-usable hook/directive, then do that.
Feedback
Last updated on