()
| 139 | } |
| 140 | |
| 141 | async init(): Promise<void> { |
| 142 | // get sessionNamespace from the redirect result. |
| 143 | const params = getHashQueryParams(this.options.replaceUrlOnRedirect); |
| 144 | if (params.sessionNamespace) this.options.sessionNamespace = params.sessionNamespace; |
| 145 | |
| 146 | const storageKey = |
| 147 | this.options.sessionKey || (this.options.sessionNamespace ? `${this._storageBaseKey}_${this.options.sessionNamespace}` : this._storageBaseKey); |
| 148 | |
| 149 | // We dont need to set the sessionTime here, because the session would be created by auth service. |
| 150 | this.sessionManager = new AuthSessionManager({ |
| 151 | storageKeyPrefix: storageKey, |
| 152 | apiClientConfig: { baseURL: this.options.citadelServerUrl }, |
| 153 | storage: this.options.storage, |
| 154 | accessTokenProvider: this.options.accessTokenProvider, |
| 155 | cookieOptions: this.options.cookieOptions, |
| 156 | }); |
| 157 | |
| 158 | if (this.options.network === WEB3AUTH_NETWORK.TESTNET || this.options.network === WEB3AUTH_NETWORK.SAPPHIRE_DEVNET) { |
| 159 | // using console log because it shouldn't be affected by loglevel config |
| 160 | // eslint-disable-next-line no-console |
| 161 | console.log( |
| 162 | `%c WARNING! You are on ${this.options.network}. Please set network: 'mainnet' or 'sapphire_mainnet' in production`, |
| 163 | "color: #FF0000" |
| 164 | ); |
| 165 | } |
| 166 | |
| 167 | if (this.options.buildEnv !== BUILD_ENV.PRODUCTION) { |
| 168 | // using console log because it shouldn't be affected by loglevel config |
| 169 | // eslint-disable-next-line no-console |
| 170 | console.log(`%c WARNING! You are using build env ${this.options.buildEnv}. Please set buildEnv: 'production' in production`, "color: #FF0000"); |
| 171 | } |
| 172 | |
| 173 | if (params.error) { |
| 174 | this.dappState = params.state; |
| 175 | throw LoginError.loginFailed(params.error); |
| 176 | } |
| 177 | |
| 178 | if (params.sessionId) { |
| 179 | await this.sessionManager.setTokens({ |
| 180 | sessionId: add0x(params.sessionId), |
| 181 | accessToken: params.accessToken || "", |
| 182 | refreshToken: params.refreshToken || "", |
| 183 | idToken: params.idToken || "", |
| 184 | }); |
| 185 | } |
| 186 | |
| 187 | // Get session id from the auth session manager |
| 188 | const sessionId = await this.sessionManager.getSessionId(); |
| 189 | if (sessionId) { |
| 190 | const data = await this._authorizeSession(); |
| 191 | // Fill state with correct info from session |
| 192 | // If session is invalid all the data is unset here. |
| 193 | if (data && Object.keys(data).length > 0) { |
| 194 | this.updateState(data); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | if (this.options.sdkMode === SDK_MODE.IFRAME) { |
no test coverage detected