npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jrstudio/auth-core

v1.0.0

Published

Arcana Auth SDK to build end-user login / signup for dApps easily, using popular Social Authentication: Google, Twitter, Discord, Twitch, Reddit and GitHub.

Downloads

16

Readme

codecov

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: '[email protected]',
      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',
  discord = 'discord',
  twitch = 'twitch',
  github = 'github',
  twitter = 'twitter',
  passwordless = 'passwordless',
}

Exported types


interface KeystoreInput {
  id: string;
  verifier: LoginType;
}

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

interface GetInfoOutput {
  loginType: SocialLoginType;
  userInfo: 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

  • origin - Base url of your app.