This package is designed to provide you with auth0 authentication for your svelte-kit app
If something is unclear, you can take a look at the Demo App and Demo app repo
Create an Application in Auth0 website
Under the settings tab of you application, find the Basic Information section.
Then find the Domain
and Client ID
strings. You will need these later.
Under the settings tab of you application, find the Application URIs section.
Then find the Allowed Logout URLs
, Allowed Web Origins
and Allowed Origins (CORS)
inputs.
Fill these inputs with the url that your app is running locally ( e.x. http://localhost:3000
).
There is an additional input Allowed Callback URLs
, fill this with your callback URL, if you do not have one - fill the url that your app is running at ( e.x. http://localhost:3000
).
Create an .env file for your project and declare these variables:
VITE_AUTH0_DOMAIN
- Fill with the Domain
data from step 2 of Setting up this package sectionVITE_AUTH0_CLIENT_ID
- Fill with the Client ID
data from step 2 of Setting up this package sectionVITE_AUTH0_REDIRECT_URI
- Fill if your app has a redirect URI
( optional )import auth from 'sveltekit-auth0'
auth.initializeAuth0()
to initialize the Auth0
clientYou should now be able to use the main methods for interacting with Auth0
Two other methods are bundled in the default export:
loginWithPopup
- will attempt to log the user in by providing a popup with a login window from Auth0logout
- will log the user outYou would use them as such:
import auth from 'sveltekit-auth0'
auth.loginWithPopup()
// AND
auth.logout()
All other methods can be imported as such:
import { getIsAuthenticatedValue, getIsAuthenticated } from 'sveltekit-auth0'
// And used like
const isAuthenticatedValue = getIsAuthenticatedValue();
// OR
const isAuthenticated = getIsAuthenticated();
// Listen for changes on the value
isAuthenticated.subscribe((value: boolean) => {
// Do something with the value
})
Methods available:
getUser
- will return the ReadablegetUserValue
- will return the User object from Auth0getIsAuthenticated
- will return ReadablegetIsAuthenticatedValue
- will return if the user is authenticated or not at this point in timegetPopupOpen
- will return ReadablegetPopupOpenValue
- will return if the login popup is open or not at this point in timeloginWithPopup
- will attempt to log the user in by providing a popup with a login window from Auth0logout
- will log the user outIf you find any issues, please open up an issue on the repository. You can also post anny feature suggestions or improvements there.