Skip to content

Commit

Permalink
Merge pull request #103 from Web3Auth/feat/minor-fix
Browse files Browse the repository at this point in the history
feat: handle invalid sessionId
  • Loading branch information
chaitanyapotti authored Dec 2, 2024
2 parents 18fd358 + 7caf665 commit 76ca316
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
1 change: 1 addition & 0 deletions app/src/main/java/com/web3auth/app/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener {
println("ed25519PrivKey: " + web3Auth.getEd25519PrivKey())
println("Web3Auth UserInfo" + web3Auth.getUserInfo())
} else {
//handle retry login
Log.d("MainActivity_Web3Auth", error.message ?: "Something went wrong")
}
}
Expand Down
14 changes: 4 additions & 10 deletions core/src/main/java/com/web3auth/core/Web3Auth.kt
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu
web3AuthResponse = resp
initializeCf.complete(null)
} else {
SessionManager.deleteSessionIdFromStorage()
sessionManager.setSessionId("")
initializeCf.completeExceptionally(error)
}
}
Expand Down Expand Up @@ -343,15 +345,15 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu
val sessionResponse: CompletableFuture<String> =
sessionManager.authorizeSession(origin, context)
sessionResponse.whenComplete { response, error ->
if (response.contains("Error")) {
if (error != null) {
sessionCompletableFuture.completeExceptionally(
Exception(
Web3AuthError.getError(
ErrorCode.NOUSERFOUND
)
)
)
} else if (error == null) {
} else {
val tempJson = JSONObject(response)
web3AuthResponse = gson.fromJson(tempJson.toString(), Web3AuthResponse::class.java)
if (web3AuthResponse?.error?.isNotBlank() == true) {
Expand All @@ -371,14 +373,6 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu
} else {
sessionCompletableFuture.complete(web3AuthResponse)
}
} else {
sessionCompletableFuture.completeExceptionally(
Exception(
Web3AuthError.getError(
ErrorCode.NOUSERFOUND
)
)
)
}
}
return sessionCompletableFuture
Expand Down

0 comments on commit 76ca316

Please sign in to comment.