@authorizerdev/authorizer-js
    TypeScript icon, indicating that this package has built-in type declarations

    0.2.0 • Public • Published

    Authorizer.js

    @authorizerdev/authorizer-js is universal javaScript SDK for Authorizer API. It supports:

    All the above versions require Authorizer instance to be instantiated and used. Instance constructor requires an object with the following keys

    Key Description
    authorizerURL Authorizer server endpoint
    redirectURL URL to which you would like to redirect the user in case of successful login

    Example

    const authRef = new Authorizer({
    	authorizerURL: 'https://app.herokuapp.com',
    	redirectURL: window.location.origin,
    });

    UMD

    • Step 1: Load Javascript using CDN
    <script src="https://unpkg.com/@authorizerdev/authorizer-js/lib/authorizer.min.js"></script>
    • Step 2: Use the library to instantiate Authorizer instance and access various methods
    <script type="text/javascript">
    	const authorizerRef = new authorizerdev.Authorizer({
    		authorizerURL: `AUTHORIZER_URL`,
    		redirectURL: window.location.origin,
    	});
    
    	// use the button selector as per your application
    	const logoutBtn = document.getElementById('logout');
    	logoutBtn.addEventListener('click', async function () {
    		await authorizerRef.logout();
    		window.location.href = '/';
    	});
    
    	async function onLoad() {
    		const res = await authorizerRef.browserLogin();
    		if (res && res.user) {
    			// you can use user information here, eg:
    			/**
    			const userSection = document.getElementById('user');
    			const logoutSection = document.getElementById('logout-section');
    			logoutSection.classList.toggle('hide');
    			userSection.innerHTML = `Welcome, ${res.user.email}`;
    			*/
    		}
    	}
    	onLoad();
    </script>

    CommonJS

    • Step 1: Install dependencies
    npm i --save @authorizerdev/authorizer-js
    OR
    yarn add @authorizerdev/authoirzer-js
    • Step 2: Import and initialize the authorizer instance
    const { Authorizer } = require('@authorizerdev/authoirzer-js');
    
    const authRef = new Authorizer({
    	authorizerURL: 'https://app.heroku.com',
    	redirectURL: 'http://app.heroku.com/app',
    });
    
    async function main() {
    	await authRef.login({
    		email: 'foo@bar.com',
    		password: 'test',
    	});
    }

    ES Modules

    • Step 1: Install dependencies
    npm i --save @authorizerdev/authorizer-js
    OR
    yarn add @authorizerdev/authoirzer-js
    • Step 2: Import and initialize the authorizer instance
    import { Authorizer } from '@authorizerdev/authoirzer-js';
    
    const authRef = new Authorizer({
    	authorizerURL: 'https://app.heroku.com',
    	redirectURL: 'http://app.heroku.com/app',
    });
    
    async function main() {
    	await authRef.login({
    		email: 'foo@bar.com',
    		password: 'test',
    	});
    }

    Keywords

    none

    Install

    npm i @authorizerdev/authorizer-js

    DownloadsWeekly Downloads

    65

    Version

    0.2.0

    License

    MIT

    Unpacked Size

    105 kB

    Total Files

    12

    Last publish

    Collaborators

    • lakhansamani