Skip to content

Commit 76ca316

Browse files
Merge pull request #103 from Web3Auth/feat/minor-fix
feat: handle invalid sessionId
2 parents 18fd358 + 7caf665 commit 76ca316

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

app/src/main/java/com/web3auth/app/MainActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener {
206206
println("ed25519PrivKey: " + web3Auth.getEd25519PrivKey())
207207
println("Web3Auth UserInfo" + web3Auth.getUserInfo())
208208
} else {
209+
//handle retry login
209210
Log.d("MainActivity_Web3Auth", error.message ?: "Something went wrong")
210211
}
211212
}

core/src/main/java/com/web3auth/core/Web3Auth.kt

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu
176176
web3AuthResponse = resp
177177
initializeCf.complete(null)
178178
} else {
179+
SessionManager.deleteSessionIdFromStorage()
180+
sessionManager.setSessionId("")
179181
initializeCf.completeExceptionally(error)
180182
}
181183
}
@@ -343,15 +345,15 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu
343345
val sessionResponse: CompletableFuture<String> =
344346
sessionManager.authorizeSession(origin, context)
345347
sessionResponse.whenComplete { response, error ->
346-
if (response.contains("Error")) {
348+
if (error != null) {
347349
sessionCompletableFuture.completeExceptionally(
348350
Exception(
349351
Web3AuthError.getError(
350352
ErrorCode.NOUSERFOUND
351353
)
352354
)
353355
)
354-
} else if (error == null) {
356+
} else {
355357
val tempJson = JSONObject(response)
356358
web3AuthResponse = gson.fromJson(tempJson.toString(), Web3AuthResponse::class.java)
357359
if (web3AuthResponse?.error?.isNotBlank() == true) {
@@ -371,14 +373,6 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu
371373
} else {
372374
sessionCompletableFuture.complete(web3AuthResponse)
373375
}
374-
} else {
375-
sessionCompletableFuture.completeExceptionally(
376-
Exception(
377-
Web3AuthError.getError(
378-
ErrorCode.NOUSERFOUND
379-
)
380-
)
381-
)
382376
}
383377
}
384378
return sessionCompletableFuture

0 commit comments

Comments
 (0)