Skip to main content


Create and initialize a Openlogin instance


This is the main class of anything related to Openlogin Using ES6,

import OpenLogin from "@toruslabs/openlogin";

Then, create a new instance of OpenLogin.

const openlogin = new OpenLogin(options);

The OpenLogin constructor takes an object with OpenLoginOptions as input.


  • options - OpenLoginOptions: The options of the constructor

    • clientId - string : Your project id which you can get from developer dashboard

    • network - enum: Environment to run openlogin (testnet, mainnet, development)

    • _iframeUrl- string: Url of openlogin iframe, you can pass custom iframe url here else it will be added based on network value.For testnet iframe url is and for mainnet it is If you are passing valid network value then network value will be given precedence over iframe url.

    • uxMode - enum(optional): popup and redirect uxmode are supported. By default it is set to redirect


  • Object: The openlogin instance with all its methods and events.


type OpenLoginOptions = {  clientId: string;  network: OPENLOGIN_NETWORK_TYPE;  _iframeUrl?: string;  redirectUrl?: string;  loginUrl?: string;  webAuthnUrl?: string;  logoutUrl?: string;  uxMode?: UX_MODE_TYPE;  replaceUrlOnRedirect?: boolean;  originData?: OriginData;};
const OPENLOGIN_NETWORK = {  MAINNET: "mainnet",  TESTNET: "testnet",  DEVELOPMENT: "development",};
const UX_MODE = {  POPUP: "popup",  REDIRECT: "redirect",}
type OriginData = {    [P in string]: string;};


const openlogin = new OpenLogin({  clientId: "YOUR_PROJECT_ID",  network: "testnet",  // if network is testnet then default iframeUrl is  // for mainnet it is  //_iframeUrl: "", // or you can directly specify iframeUrl of openlogin app  redirectUrl: "" // your app url where user will be redirected  uxMode: "redirect" // default is redirect , popup mode is also supported});


Initialize the OpenLogin object after creation. Init sync up the state of user login session in to openlogin class and it also injects a iframe in to DOM. If init will be called after user is logged in , it will add the user private key to privKey state variable of openlogin object.

await openlogin.init();


  • Promise<void> : Returns a promise which resolves to void