diff --git a/build/main.js b/build/main.js index 27ade04..c2bfe88 100644 --- a/build/main.js +++ b/build/main.js @@ -39,7 +39,7 @@ const localStorageAdapter = { * @param {Array.} options.providers Array of arguments that will be passed to the addProvider method. */ export default class Auth { - constructor({ name = 'default', apiKey, redirectUri, providers = [], storage = localStorageAdapter }) { + constructor({ name = 'default', apiKey, redirectUri, providers = [], storage = localStorageAdapter, lazyInit }) { this.refreshTokenRequest = null; this.initialized = false; if (!apiKey) @@ -63,9 +63,11 @@ export default class Auth { const { name, scope } = typeof options === 'string' ? { name: options, scope: undefined } : options; this.providers[name] = scope; } - this._initUser(); + if (!lazyInit) { + this.initUser(); + } } - async _initUser() { + async initUser() { /** * User data if the user is logged in, else its null. * @type {Object|null} diff --git a/src/main.ts b/src/main.ts index 93ce7b7..53ee526 100644 --- a/src/main.ts +++ b/src/main.ts @@ -22,6 +22,7 @@ type AsyncStorage = { type AuthOptions = { apiKey: string; + lazyInit?: boolean; name?: string; providers?: Array; redirectUri?: string; @@ -82,7 +83,7 @@ export default class Auth { storage: AsyncStorage; initialized: boolean = false; - constructor({ name = 'default', apiKey, redirectUri, providers = [], storage = localStorageAdapter }: AuthOptions) { + constructor({ name = 'default', apiKey, redirectUri, providers = [], storage = localStorageAdapter, lazyInit }: AuthOptions) { if (!apiKey) throw Error('The argument "apiKey" is required'); if (!Array.isArray(providers)) throw Error('The argument "providers" must be an array'); @@ -107,10 +108,12 @@ export default class Auth { this.providers[name] = scope; } - this._initUser(); + if (!lazyInit) { + this.initUser(); + } } - async _initUser() { + async initUser() { /** * User data if the user is logged in, else its null. * @type {Object|null}