Skip to content

shaloo/auth

Repository files navigation

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: '[email protected]',
      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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •