Notorious Preying Mantis

    @arcana/auth
    TypeScript icon, indicating that this package has built-in type declarations

    0.0.8 • Public • Published

    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,SocialLoginType } from '@arcana/auth';

    Initialise

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

    Initiate social login

    await auth.loginWithSocial(SocialLoginType.google);

    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 { X, Y } = await auth.getPublicKey({
      verifier: <loginType>,
      id: <email | username>,
    });

    Check if user already logged in

    const loggedIn = auth.isLoggedIn();
    if (!loggedIn) {
      await auth.loginWithSocial(SocialLoginType.google);
    }
    const userInfo = auth.getUserInfo()

    Clear login session

    await auth.logout();

    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);
      });
    }
    • Skip redirectUri in params if the it is same as login page.

    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.

    Keywords

    none

    Install

    npm i @arcana/auth

    DownloadsWeekly Downloads

    47

    Version

    0.0.8

    License

    ISC

    Unpacked Size

    2.16 MB

    Total Files

    39

    Last publish

    Collaborators

    • karthik-aracana
    • ajithranka
    • shrinath-newfang
    • makyl
    • punaifang
    • sauravnk30
    • adminarcana