1.0.10 • Published 4 days ago

@arcana/auth v1.0.10

Weekly downloads
-
License
MIT
Repository
-
Last release
4 days ago

Arcana Auth

Arcana SDK to perform logins on your app.

Installation

Using NPM/Yarn

npm install --save @arcana/auth
yarn add @arcana/auth

Using CDN

<script src="https://cdn.jsdelivr.net/npm/@arcana/auth"></script>
<script src="https://unpkg.com/@arcana/auth"></script>

Usage

Import

const { AuthProvider, SocialLoginType } = window.arcana.auth;
// or
import { AuthProvider } from '@arcana/auth';

Initialise

const auth = await AuthProvider.init({
   appId: `${appId}`,
   flow: 'redirect', /* can be 'popup' or 'redirect' */
   redirectUri:''    /* can be ignored for redirect flow if same as login page */
});

Initiate social login

await auth.loginWithSocial(SocialLoginType.google);

Initiate passwordless login

const result = await auth.loginWithOtp(`${emailAddress}`, PasswordlessOptions);

PasswordlessOptions:

  • { withUI: true } - the user is redirected to email-sent or error page
  • { withUI: false } - gets a json response back with no redirection
  • defaults to { withUI: true }

Get login status

const loggedIn = auth.isLoggedIn(); /* boolean response */

The user info is saved in memory after successful login, before unload event of the page it gets stored in session-storage and is refetched to memory and removed from session-storage after successful page reload.

Get user info

const userInfo = auth.getUserInfo();
/* 
  UserInfo: {
    loginType: 'google',
    userInfo: {
      id: 'abc@example.com',
      name: 'ABC DEF',
      email: '',
      picture: ''
    },
    privateKey: ''
  }
*/

Get public key

const publicKey = await auth.getPublicKey({
  verifier: SocialLoginType.google,
  id: `${email}`,
}, PublickeyOutput); 

PublickeyOutput:

  • value can be 'point', 'compressed' or 'uncompressed'
  • point output will be an object with { x: string, y: string }
  • compressed output will be a string like 0x03...
  • uncompressed output will be a string like 0x04...
  • defaults to uncompressed

Clear login session

await auth.logout();

Typescript Usage

Exported enums

enum PublicKeyOutput {
  point = 'point',
  compressed = 'compressed',
  uncompressed = 'uncompressed',
}

enum SocialLoginType {
  google = 'google',
  reddit = 'reddit',
  discord = 'discord',
  twitch = 'twitch',
  github = 'github',
  twitter = 'twitter',
  passwordless = 'passwordless',
}

Exported types

interface InitParams {
  appId: string;
  network?: 'dev' | 'testnet'; /* defaults to testnet  */
  flow?: 'popup' | 'redirect'; /* defaults to redirect */
  debug?: boolean;             /* defaults to false    */
}

interface UserInfo {
  loginType: SocialLoginType;
  userInfo: {
    id: string;
    email?: string;
    name?: string;
    picture?: string;
  };
  privateKey: string;
}

interface PasswordlessOptions {
  withUI?: boolean;
}

Flow modes

Redirect

login.js

window.onload = async () => {
  const auth = await AuthProvider.init({
    appId: `${appId}`,
    flow: 'redirect',
    redirectUri:'path/to/redirect' 
  });

  googleLoginBtn.addEventListener('click', async () => {
    await auth.loginWithSocial(SocialLoginType.google);
  });
}

redirect.js

window.onload = async () => {
  const auth = await AuthProvider.init({
    appId: `${appId}`,
    flow: 'redirect',
    redirectUri:'path/to/redirect' 
  });

  
  if(auth.isLoggedIn()) {
    const info = auth.getUserInfo();
  }
}
  • Skip redirectUri in params if the it is same as login page. For example:

    index.js

    window.onload = async () => {
      const auth = await AuthProvider.init({
        appId: `${appId}`,
        flow: 'redirect',
      });
    
      if(auth.isLoggedIn()) {
        /* already logged in, get user info and use */
        const info = auth.getUserInfo();
      } else {
        /* add handler to handle login function */
        googleLoginBtn.addEventListener('click', async () => {
          await auth.loginWithSocial(SocialLoginType.google);
        });
      }
    }

Popup

login.js

window.onload = async () => {
  const auth = await AuthProvider.init({
    appId: `${appId}`,
    redirectUri:'path/to/redirect' 
  });

  googleLoginBtn.addEventListener('click', async () => {
    await auth.loginWithSocial(SocialLoginType.google);
    if(auth.isLoggedIn()) {
      const info = auth.getUserInfo();
      // Store info and redirect accordingly
    }
  });
}

redirect.js

window.onload = async () => {
  AuthProvider.handleRedirectPage(<origin>);
};

Variables

  • SocialLoginType - discord, twitter, github, google, twitch, reddit
  • origin - Base url of your app.
1.0.11-beta.5

4 days ago

1.0.11-beta.4

22 days ago

1.0.11-beta.2

1 month ago

1.0.11-beta.3

29 days ago

1.0.11-beta.1

2 months ago

1.0.10-rc.1

3 months ago

1.0.10

3 months ago

1.0.9

3 months ago

1.0.9-rc.1

4 months ago

1.0.9-beta.4

4 months ago

1.0.9-beta.3

5 months ago

1.0.9-beta.2

5 months ago

1.0.8

7 months ago

1.0.7

9 months ago

1.0.6

10 months ago

1.0.9-beta.1

7 months ago

1.0.6-beta.5

10 months ago

1.0.6-beta.4

10 months ago

1.0.8-beta.1

8 months ago

1.0.6-beta.1

10 months ago

1.0.6-beta.3

10 months ago

1.0.6-beta.2

10 months ago

1.0.8-beta.3

8 months ago

1.0.8-beta.2

8 months ago

1.0.5

10 months ago

1.0.5-beta.5

11 months ago

1.0.5-beta.6

10 months ago

1.0.5-beta.3

11 months ago

1.0.5-beta.4

11 months ago

1.0.5-beta.1

11 months ago

1.0.5-beta.2

11 months ago

1.0.4

11 months ago

1.0.4-alpha.beta.0

11 months ago

1.0.4-beta.0

11 months ago

1.0.4-beta.1

1 year ago

1.0.4-beta.2

11 months ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.3

1 year ago

1.0.3-beta.1

1 year ago

1.0.2-beta.1

1 year ago

1.0.0

1 year ago

0.3.0

1 year ago

0.3.0-beta.6

1 year ago

0.3.0-beta.4

1 year ago

0.3.0-beta.5

1 year ago

1.0.0-beta.1

1 year ago

0.1.2-beta.16

2 years ago

0.1.2-beta.17

2 years ago

0.1.2-beta.18

1 year ago

0.1.2-beta.19

1 year ago

0.3.0-beta.2

1 year ago

0.3.0-beta.3

1 year ago

0.1.2

1 year ago

0.3.0-beta.1

1 year ago

0.1.3

1 year ago

0.2.3-beta.1

1 year ago

0.2.3-beta.2

1 year ago

0.2.0-beta.2

1 year ago

0.2.3-beta.3

1 year ago

0.2.0-beta.1

1 year ago

0.2.1-beta.1

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.2.2

1 year ago

0.1.2-beta.15

2 years ago

0.1.2-beta.3

2 years ago

0.1.2-beta.11

2 years ago

0.1.2-beta.6

2 years ago

0.1.2-beta.12

2 years ago

0.1.2-beta.7

2 years ago

0.1.2-beta.13

2 years ago

0.1.2-beta.4

2 years ago

0.1.2-beta.14

2 years ago

0.1.2-beta.5

2 years ago

0.1.2-beta.10

2 years ago

0.1.2-beta.8

2 years ago

0.1.2-beta.9

2 years ago

0.1.2-beta.2

2 years ago

0.0.9-beta.13

2 years ago

0.1.2-beta.1

2 years ago

0.0.9-beta9

2 years ago

0.0.9-beta8

2 years ago

0.0.9-beta7

2 years ago

0.0.9-beta5

2 years ago

0.0.9-beta.11

2 years ago

0.0.9-beta.12

2 years ago

0.1.0

2 years ago

0.1.1

2 years ago

0.0.9-beta10

2 years ago

0.0.9-beta4

2 years ago

0.0.9-beta3

2 years ago

0.0.9-beta2

2 years ago

0.0.9-beta1

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago