OLAF SDK for JS facilitates seamless integration of OLAF.sh into your apps, offering features such as:
- 🗃️ secure credential storage,
- 🔐 effortless login and logout processes,
- 👤 and convenient access to user information, styles and permissions.
// via npm
npm install @olafsh/olaf-sdk-js
// via yarn
yarn add @olafsh/olaf-sdk-js
SDK can be imported either via CommonJS or ES Modules methods.
const OLAFSDK = require('@olafsh/olaf-sdk-js');
const sdk = new OLAFSDK();
import OLAFSDK from "@olafsh/olaf-sdk-js";
const sdk = new OLAFSDK();
Warning
The SDK requires a browser to perform the authentication process, hence it CAN NOT be used in a NodeJS environment.
Check examples/ directory for more usages.
// Fetch configuration for your app from olaf.sh platform
await sdk.fetchConfig()
// Set language for sign in on olaf.sh platform
sdk.setLanguage('en');
// Perform a login with redirect
await sdk.loginWithRedirect();
// OPTIONAL: Build authorize url for manual redirect
const authorizeUrl = await sdk.buildAuthorizeUrl();
// Handle login callback from olaf.sh platform
// HINT: It's usually the best to done this on a different route
await sdk.handleRedirectCallback()
// Check current authentication status
console.log(await sdk.isAuthenticated);
// Get access token
const accessToken = sdk.accessToken;
// OPTIONAL: Get user details
const user = await sdk.me();
// Perform a logout
await sdk.logout();
All source code is located in /src
.
The source code is compiled via npm run build
command to /lib
directory.
# Clone project
git clone [email protected]:olafsh/olaf-sdk-js.git
# Compile changes
npm run build
# Run test
npm run test