From ca94d2576113265033f4296da8a64db0bdfa443a Mon Sep 17 00:00:00 2001 From: Lakhan Samani Date: Sat, 16 Dec 2023 16:53:24 +0530 Subject: [PATCH] Add migration guide --- README.md | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index ba2afea..1556a57 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,10 @@ It supports: - [CommonJS(cjs)](https://flaviocopes.com/commonjs/) build for NodeJS version that don't support ES Modules - [ESM (ES Modules)](https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/) build for modern javascript standard, i.e. ES Modules +# Migration from 1.x -> 2.x + +`2.x` version of `@authorizerdev/authorizer-js` has a uniform response structure that will help your applications to get right error codes and success response. Methods here have `{data, errors}` as response object for methods of this library + All the above versions require `Authorizer` instance to be instantiated and used. Instance constructor requires an object with the following keys | Key | Description | @@ -18,7 +22,7 @@ All the above versions require `Authorizer` instance to be instantiated and used ```js const authRef = new Authorizer({ - authorizerURL: "https://app.herokuapp.com", + authorizerURL: 'https://app.herokuapp.com', redirectURL: window.location.origin, }); ``` @@ -38,22 +42,22 @@ const authRef = new Authorizer({ const authorizerRef = new authorizerdev.Authorizer({ authorizerURL: `AUTHORIZER_URL`, redirectURL: window.location.origin, - clientID: "YOUR_CLIENT_ID", // can be obtained from authorizer dashboard + clientID: 'YOUR_CLIENT_ID', // can be obtained from authorizer dashboard }); // use the button selector as per your application - const logoutBtn = document.getElementById("logout"); - logoutBtn.addEventListener("click", async function () { + const logoutBtn = document.getElementById('logout'); + logoutBtn.addEventListener('click', async function () { await authorizerRef.logout(); - window.location.href = "/"; + window.location.href = '/'; }); async function onLoad() { - const res = await authorizerRef.authorize({ - response_type: "code", + const { data, errors } = await authorizerRef.authorize({ + response_type: 'code', use_refresh_token: false, }); - if (res && res.access_token) { + if (data && data.access_token) { // get user profile using the access token const user = await authorizerRef.getProfile({ Authorization: `Bearer ${res.access_token}`, @@ -80,17 +84,17 @@ yarn add @authorizerdev/authoirzer-js - Step 2: Import and initialize the authorizer instance ```js -const { Authorizer } = require("@authorizerdev/authoirzer-js"); +const { Authorizer } = require('@authorizerdev/authoirzer-js'); const authRef = new Authorizer({ - authorizerURL: "https://app.heroku.com", - redirectURL: "http://app.heroku.com/app", + authorizerURL: 'https://app.heroku.com', + redirectURL: 'http://app.heroku.com/app', }); async function main() { await authRef.login({ - email: "foo@bar.com", - password: "test", + email: 'foo@bar.com', + password: 'test', }); } ``` @@ -108,17 +112,17 @@ yarn add @authorizerdev/authorizer-js - Step 2: Import and initialize the authorizer instance ```js -import { Authorizer } from "@authorizerdev/authorizer-js"; +import { Authorizer } from '@authorizerdev/authorizer-js'; const authRef = new Authorizer({ - authorizerURL: "https://app.heroku.com", - redirectURL: "http://app.heroku.com/app", + authorizerURL: 'https://app.heroku.com', + redirectURL: 'http://app.heroku.com/app', }); async function main() { await authRef.login({ - email: "foo@bar.com", - password: "test", + email: 'foo@bar.com', + password: 'test', }); } ```