From b829d3e5cca5b0f2ad4038e5834f0558f42a8204 Mon Sep 17 00:00:00 2001 From: Archit Date: Wed, 2 Oct 2024 22:37:41 +0530 Subject: [PATCH] custom storage scope --- src/handlers/interfaces.ts | 11 ++++++----- src/login.ts | 8 ++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/handlers/interfaces.ts b/src/handlers/interfaces.ts index 0bb5a88..30cc6e0 100644 --- a/src/handlers/interfaces.ts +++ b/src/handlers/interfaces.ts @@ -400,11 +400,6 @@ export interface CreateHandlerParams { web3AuthNetwork: TORUS_NETWORK_TYPE; } -export interface RedirectResultParams { - replaceUrl?: boolean; - clearLoginDetails?: boolean; -} - export type SingleLoginParams = SubVerifierDetails; export interface AggregateLoginParams { @@ -415,6 +410,12 @@ export interface AggregateLoginParams { export type LoginDetails = { method: TORUS_METHOD_TYPE; args: SingleLoginParams | AggregateLoginParams }; +export interface RedirectResultParams { + replaceUrl?: boolean; + clearLoginDetails?: boolean; + storageData?: LoginDetails; +} + export interface RedirectResult { method: TORUS_METHOD_TYPE; result?: TorusLoginResponse | TorusAggregateLoginResponse | unknown; diff --git a/src/login.ts b/src/login.ts index 5f4fa49..382157d 100644 --- a/src/login.ts +++ b/src/login.ts @@ -318,7 +318,11 @@ class CustomAuth { return this.getTorusKey(verifier, verifierId, aggregateVerifierParams, aggregateIdToken, extraVerifierParams); } - async getRedirectResult({ replaceUrl = true, clearLoginDetails = true }: RedirectResultParams = {}): Promise { + async getRedirectResult({ + replaceUrl = true, + clearLoginDetails = true, + storageData = undefined, + }: RedirectResultParams = {}): Promise { await this.init({ skipInit: true }); const url = new URL(window.location.href); const hash = url.hash.substring(1); @@ -337,7 +341,7 @@ class CustomAuth { log.info(instanceId, "instanceId"); - const loginDetails = await this.storageHelper.retrieveLoginDetails(instanceId); + const loginDetails = storageData || (await this.storageHelper.retrieveLoginDetails(instanceId)); const { args, method, ...rest } = loginDetails || {}; log.info(args, method);