Svelte library aimed at helping implement WorkOS's Authkit and their User Management service in a Svelte application.
npm i @dasporal/svelte-authkit
Environment variables
WORKOS_CLIENT_ID
: WorkOS Client IDWORKOS_API_KEY
: WorkOS API key as provided by AuthKitWORKOS_REDIRECT_URI
: Redirect URI as setup in the dashboard (should look like somethinghttps://domain.tld/auth/callback
orhttp://localhost:PORT/auth/callback
for staging environment)JWT_SECRET_KEY
: Following WorkOS' guidelines on how to create a secret key.
Add the SvelteAuthKit
component to your root +layout.svelte
file.
<script lang="ts">
import { SvelteAuthKit } from '@dasporal/svelte-authkit';
</script>
<SvelteAuthKit />
<slot />
This component will initialize on each app mount to retrieve the user. It will then store the data in the userStore
, with its property being accessible by importing import { user, isAuthenticated } from '$lib/stores/userStore';
on the relevant components and pages.
The signIn
and signOut
functions from $lib/utils/client/auth.ts
and $lib/utils/client/auth.ts
can be applied to any custom Button component you may have, and it is not planned for the moment to provide premade button components. This allows you to implement the library's functionality while using your own design system.
The library will listen to 4 new routes:
/auth
/auth/callback
/auth/verify-token
/auth/sign-out
An example of expected setup can be browsed in this repo at src/routes
, with src/routes/+page.svelte
containing a sign-in and sign-out button, along with conditional rendering, and src/hooks.server.ts
containing the logic to handle the requests.
- Tests