Tesseral Svelte SDK
If this is your first time using the Tesseral Svelte SDK, we recommend following the Tesseral Quickstart.
Tesseral’s Svelte SDK lets you add B2B auth support to your clientside Svelte app.
The Tesseral Svelte SDK is open-source and available on GitHub.
Getting Started
Install the Tesseral Svelte SDK by running:
Then, in your Svelte application, add a TesseralProvider at the root of your
Svelte application in your top-level +layout.svelte file:
Replace publishable_key_... with your project’s Publishable Key. You can find
it in the API Keys
Settings of the
Tesseral Console.
You’ll need to use a separate Publishable Key for development and production.
It’s up to you how to pass a different publishableKey for dev vs prod.
In development, make sure you’re using a Publishable Key that has “Dev Mode” enabled.
Once you’ve added TesseralProvider, all visitors to your Svelte app will
automatically be authenticated. Unauthenticated visitors are redirected to a
Tesseral-hosted login flow before being redirected back to your application.
Accessing details about the authenticated user
The Tesseral Svelte SDK makes information about your authenticated user available through a set of Svelte stores.
Tesseral’s Svelte SDK stores will throw an error if used outside of a child
component of TesseralProvider.
getUser
To get the current logged-in User, call getUser:
getOrganization
To get the Organization that the User works for,
call getOrganization:
getLogout
To force the current User to log out, call the callback returned from
getLogout:
getUserSettingsUrl
Tesseral automatically provides a self-serve user settings UI to handle tasks like changing emails, resetting passwords, and configuring multi-factor authentication.
You can get a link to that UI using getUserSettingsUrl:
getOrganizationSettingsUrl
Tesseral automatically provides a self-serve organization settings UI to handle tasks like managing collaborators, creating and revoking user invites, and customizing login methods.
You can get a link to that UI using getOrganizationSettingsUrl:
getAccessToken
Most folks never need to use getAccessToken, because Tesseral automatically
sets an authentication cookie on your visitor’s browsers.
To directly access the User’s access token, call getAccessToken:
getHasPermission
To use getHasPermission, you must first configure Role-Based Access
Control for your Project.
To check if the current user has a specific permission, use getHasPermission:
Advanced Usage
Tesseral provides polished, self-serve UIs for user and organization settings on
your behalf, which you can redirect your users to using getUserSettingsUrl and
getOrganizationSettingsUrl.
Everything those prebuilt UIs do, you can also do from your own clientside code. Doing so is an advanced feature and is not required.
For details on how to do this, see the documentation for the Tesseral Frontend API.