An open API service indexing awesome lists of open source software.

https://github.com/authorizerdev/authorizer-svelte

Svelte SDK for [authorizer.dev](https://authorizer.dev/)
https://github.com/authorizerdev/authorizer-svelte

hacktoberfest

Last synced: 10 months ago
JSON representation

Svelte SDK for [authorizer.dev](https://authorizer.dev/)

Awesome Lists containing this project

README

          

# authorizer-svelte

Svelte SDK for [authorizer.dev](https://authorizer.dev) integration in your [svelte-js](https://svelte.dev/) application. This will allow you to have authentication and authorization ready in minutes.

For detailed information about all the components check [docs](https://docs.authorizer.dev/authorizer-svelte)

## Getting Started

Here is a quick guide on getting started with `@authorizerdev/authorizer-svelte` package.

### Step 1 - Create Instance

Get Authorizer URL by instantiating [Authorizer instance](/deployment) and configuring it with necessary [environment variables](/core/env).

### Step 2 - Install package

Assuming you have svelte-js application up and running, install following package in your application

```sh
npm i --save @authorizerdev/authorizer-svelte
OR
yarn add @authorizerdev/authorizer-svelte
```

### Step 3 - Configure Provider and use Authorizer Component

Authorizer comes with global context `authorizerContext` which is available once you have configured `AuthorizerProvider` component.

Configure `AuthorizerProvider` at root level in your application and import `default.css`.

> Note: You can override default style with `css` variables. Check [docs](https://docs.authorizer.dev/authorizer-svelte) for more details.

`eg: routes/+layout.svelte`

```svelte

import { AuthorizerProvider } from '@authorizerdev/authorizer-svelte';
import '@authorizerdev/authorizer-svelte/styles/default.css';

```

**Use `Authorizer` Component**

`eg: routes/+page.svelte`

```svelte

import { getContext } from 'svelte';
import { Authorizer } from '@authorizerdev/authorizer-svelte';

/**
* @type {{ token: string; user: any; loading: boolean; logout: Function; }}
*/
let state;

const store = getContext('authorizerContext');

store.subscribe((/** @type {any} */ data) => {
state = data;
});

const logoutHandler = async () => {
await state.logout();
};

{#if state.user}


Hey 👋,


{state.user.email}


{#if state.loading}

Processing....


{:else}

Logout


{/if}

{:else}

{/if}
```

## Support our work

Github Sponsorship: https://github.com/sponsors/authorizerdev