Skip to content

Commit

Permalink
update android sfa example
Browse files Browse the repository at this point in the history
  • Loading branch information
AyushBherwani1998 committed Dec 4, 2024
1 parent 8e7ce4e commit 0a1a938
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ android {

dependencies {
// IMP START - Installation
implementation 'com.github.web3auth:single-factor-auth-android:2.1.0'
implementation 'org.torusresearch:torus-utils-java:4.0.3'
implementation 'com.github.web3auth:single-factor-auth-android:3.0.0'
// IMP END - Installation
implementation platform('com.google.firebase:firebase-bom:31.0.2')
implementation 'com.google.firebase:firebase-auth-ktx'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,23 @@ class MainActivity : AppCompatActivity() {

val signOutButton = findViewById<Button>(R.id.signOut)
signOutButton.setOnClickListener { signOut(this.applicationContext) }
singleFactorAuth.getSessionData()
val torusKeyCF = singleFactorAuth.initialize(this.applicationContext)
Log.i("Is connected",singleFactorAuth.isConnected().toString())
torusKeyCF.whenComplete { sessionData, error ->
torusKeyCF.whenComplete { _, error ->
if (error != null) {
Log.e("Initialize Error", error.toString())
} else if (sessionData == null) {
Log.e("Initialize", "No active session found")
} else {
this.sessionData = sessionData
torusKey = sessionData.privateKey
publicAddress = sessionData.publicAddress
Log.i("Private Key", torusKey!!.trimIndent())
Log.i("User Info", sessionData.userInfo.toString())
reRender()
this.sessionData = singleFactorAuth.getSessionData()
if(this.sessionData == null) {
Log.i("Session", "No active session found")
} else {
torusKey = sessionData!!.privateKey
publicAddress = sessionData!!.publicAddress
Log.i("Private Key", torusKey!!.trimIndent())
Log.i("User Info", sessionData!!.userInfo.toString())
reRender()
}

}
}

Expand Down Expand Up @@ -142,8 +144,13 @@ class MainActivity : AppCompatActivity() {
private fun signOut(context: Context) {
publicAddress = ""
Firebase.auth.signOut()
singleFactorAuth.logout(context)
reRender()
try {
val logoutCF = singleFactorAuth.logout(context)
logoutCF.get()
reRender()
} catch (error: Exception) {
Log.e("Logout Error", error.toString());
}
}

private fun reRender() {
Expand Down

0 comments on commit 0a1a938

Please sign in to comment.