Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dopry/svelte-auth0
Svelte Auth0 Components
https://github.com/dopry/svelte-auth0
Last synced: about 1 month ago
JSON representation
Svelte Auth0 Components
- Host: GitHub
- URL: https://github.com/dopry/svelte-auth0
- Owner: dopry
- Created: 2020-01-14T02:23:04.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-06-19T02:12:37.000Z (8 months ago)
- Last Synced: 2024-12-13T03:55:14.729Z (about 2 months ago)
- Language: JavaScript
- Homepage: https://darrelopry.com/svelte-auth0/
- Size: 1.33 MB
- Stars: 72
- Watchers: 2
- Forks: 13
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
# svelte-auth0
An Auth0 Component for Svelte.
[Try out the demo](https://darrelopry.com/svelte-auth0/)
## Getting Started
Setup an [Auth0](http://auth0.com) Account. Get the domain client_id from the Default App.
`npm install @dopry/svelte-auth0`
### App.svelte
```svelte
import {
Auth0Context,
Auth0LoginButton,
Auth0LogoutButton,
authError,
authToken,
idToken,
isAuthenticated,
isLoading,
login,
logout,
userInfo,
} from '@dopry/svelte-auth0';Login
Logout
isLoading: {$isLoading}
isAuthenticated: {$isAuthenticated}
authToken: {$authToken}
idToken: {$idToken}
userInfo: {JSON.stringify($userInfo, null, 2)}
authError: {$authError}```
## Docs
### Components
* Auth0Context - component to initiate the Auth0 client. You only need one instance in your DOM tree at the root
Attributes:
* domain - Auth0 domain
* client_id - Auth0 ClientId
* audience - The default audience to be used for requesting API access
* callback_url - override the default url that Auth0 will redirect to after login. default: window.location.href
* logout_url - override the default url that Auth0 will redirect to after logout. default: window.location.href* Auth0LoginButton - log out the current context
Attributes:
* preserve_route - tell the callback handler to return to the current url after login. default: true
* callback_url - override the context callback_url* Auth0LogoutButton - log in the current context
Attributes:
* logout_url - override the context logout_url### Functions
* login(auth0Promise, preseveRoute = true, callback_url = null) - begin a user login.
* logout(auth0Promise, logout_url = null) - logout a user.
* refreshToken(auth0Promise) - function to refresh a token.### Stores
* isLoading - if true auth0 is still loading.
* isAuthenticated - true if user is currently authenticated
* authToken - api token
* userInfo - the currently logged in user's info from Auth0
* authError - the last authentication error.### Constants
* AUTH0_CONTEXT_CALLBACK_URL,
* AUTH0_CONTEXT_CLIENT_PROMISE - key for the Auth0 client in setContext/getContext.
* AUTH0_CONTEXT_LOGOUT_URL,## Release
**use semver**
npm publish
npm run showcase:build
npm run showcase:publish