Skip to content

Commit

Permalink
Add migration guide
Browse files Browse the repository at this point in the history
  • Loading branch information
lakhansamani committed Dec 16, 2023
1 parent 8866c61 commit ca94d25
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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,
});
```
Expand All @@ -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}`,
Expand All @@ -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: "[email protected]",
password: "test",
email: '[email protected]',
password: 'test',
});
}
```
Expand All @@ -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: "[email protected]",
password: "test",
email: '[email protected]',
password: 'test',
});
}
```
Expand Down

0 comments on commit ca94d25

Please sign in to comment.