Skip to content

Commit aef2dea

Browse files
add docs for sfa android v3
1 parent 3dac7df commit aef2dea

File tree

8 files changed

+91
-53
lines changed

8 files changed

+91
-53
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
title: SFA Android SDK - v2.0.0 to v3.0.0
3+
description: "SFA Android SDK - v2.0.0 to v3.0.0 | Documentation - Web3Auth"
4+
sidebar_label: v2.0.0 to v3.0.0
5+
---
6+
7+
This migration guide provides steps for upgrading from version v2.0.0 to v3.0.0 of the SFA Android
8+
SDK. The guide outlines significant changes and enhancements.
9+
10+
## Breaking Changes
11+
12+
### initialize Method Changes
13+
14+
In v3, the `initialize` method will now return void upon successful initialization instead of
15+
returning `SessionData`. After successful initialization, you can use the
16+
[getSessionData](/docs/sdk/sfa/sfa-android/usage/#get-session-data) method to check if the user is
17+
logged in or not.
18+
19+
```kotlin
20+
val initializeCF = singleFactoreAuth.initialize(this.applicationContext)
21+
22+
// remove-next-line
23+
initializeCF.whenComplete { sessionData, error ->
24+
// add-next-line
25+
initializeCF.whenComplete {_, error ->
26+
if (error != null) {
27+
// Handle error
28+
}
29+
// remove-start
30+
else if (sessionData != null) {
31+
// User is logged in
32+
} else {
33+
// User is not logged in
34+
}
35+
// remove-end
36+
// add-start
37+
let sessionData = singleFactorAuth.getSessionData()
38+
if(sessionData != null) {
39+
// User is logged in
40+
} else {
41+
// User is not logged in
42+
}
43+
// add-end
44+
}
45+
```

docs/sdk/sfa/sfa-android/initialize.mdx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ description: "Web3Auth Single Factor Auth Android SDK - Initialize | Documentati
77
import TabItem from "@theme/TabItem";
88
import Tabs from "@theme/Tabs";
99

10+
import Instantiation from "@site/src/common/sdk/sfa/android/_sfa-android-instantiation.mdx";
1011
import Initialization from "@site/src/common/sdk/sfa/android/_sfa-android-initialization.mdx";
11-
import SessionManagement from "@site/src/common/sdk/sfa/android/_sfa-android-session-management.mdx";
1212

1313
Once you have installed the Web3Auth SDK, the next crucial step is to initialize it. This step
1414
requires passing various parameters that align with your project preferences. It's important to note
@@ -29,13 +29,12 @@ Web3Auth network, client id, and other parameters during initialization.
2929

3030
## Create Instance
3131

32-
<Initialization />
32+
<Instantiation />
3333

3434
## Initialize
3535

36-
To initialize the SDK, you can use the `initialize` method. We have included Session Management in
37-
this SDK, so you can use the method to get the `SessionData` without re-logging in the user. If a
38-
user has an active session, it will return the `SessionData`, otherwise, it will throw an error for
39-
inactive session.
36+
To initialize the SDK, you can use the `initialize` method. This method helps you initialize the SDK
37+
with existing session. After successful initialization, you can use the
38+
[getSessionData](./usage/#get-session-data) method to check if the user is logged in or not.
4039

41-
<SessionManagement />
40+
<Initialization />

sidebars.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,6 +1647,7 @@ const sidebars: SidebarsConfig = {
16471647
type: "category",
16481648
label: "Migration Guides",
16491649
items: [
1650+
"migration-guides/sfa-android-v2-to-v3",
16501651
"migration-guides/sfa-android-v1.2.0-to-v2.0.0",
16511652
"migration-guides/sfa-android-v0.4.0-to-v1",
16521653
"migration-guides/sfa-android-v0.1.0-to-v0.3.0",
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
```kotlin
22
import android.content.Context
3-
import com.web3auth.singlefactorauth.SingleFactorAuth
4-
import com.web3auth.singlefactorauth.types.Web3AuthOptions
5-
import org.torusresearch.fetchnodedetails.types.Web3AuthNetwork
6-
7-
// You can get the client id for your Web3Auth project from Web3Auth dashboard.
8-
val web3AuthOptions = Web3AuthOptions(
9-
"YOUR_WEB3AUTH_CLIENT_ID",
10-
Web3AuthNetwork.SAPPHIRE_MAINNET
11-
)
123

134
val context: Context = "YOUR_APPLICATION_CONTEXT"
5+
val sessionDataCF = singleFactorAuth.initialize(context)
146

15-
val singleFactorAuth = SingleFactorAuth(web3AuthOptions, context)
7+
sessionDataCF.whenComplete {sessionData, error ->
8+
if(error != null) {
9+
// Something went wrong
10+
// Initiate the login flow again
11+
} else {
12+
// You can use the SessionData to check if the user is
13+
//logged in or not
14+
}
15+
}
1616
```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
```kotlin
2+
import android.content.Context
3+
import com.web3auth.singlefactorauth.SingleFactorAuth
4+
import com.web3auth.singlefactorauth.types.Web3AuthOptions
5+
import org.torusresearch.fetchnodedetails.types.Web3AuthNetwork
6+
7+
// You can get the client id for your Web3Auth project from Web3Auth dashboard.
8+
val web3AuthOptions = Web3AuthOptions(
9+
"YOUR_WEB3AUTH_CLIENT_ID",
10+
Web3AuthNetwork.SAPPHIRE_MAINNET
11+
)
12+
13+
val context: Context = "YOUR_APPLICATION_CONTEXT"
14+
15+
val singleFactorAuth = SingleFactorAuth(web3AuthOptions, context)
16+
```

src/common/sdk/sfa/android/_sfa-android-session-management.mdx

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/common/versions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const pnpUnityVersion = `5.x.x`;
77
export const pnpUnrealVersion = `4.1.x`;
88

99
export const sfaWebVersion = `9.2.x`;
10-
export const sfaAndroidVersion = `2.1.0`;
10+
export const sfaAndroidVersion = `3.0.0`;
1111
export const sfaIOSVersion = `9.0.2`;
1212
export const sfaRNVersion = `2.0.x`;
1313
export const sfaFlutterVersion = `5.2.0`;

src/pages/guides/sfa-android-firebase.mdx

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import TabItem from "@theme/TabItem";
1616
import Tabs from "@theme/Tabs";
1717

1818
import Install from "@site/src/common/sdk/sfa/android/_sfa-android-install.mdx";
19+
import Instantiation from "@site/src/common/sdk/sfa/android/_sfa-android-instantiation.mdx";
1920
import Initialization from "@site/src/common/sdk/sfa/android/_sfa-android-initialization.mdx";
20-
import SessionManagement from "@site/src/common/sdk/sfa/android/_sfa-android-session-management.mdx";
2121

2222
<SEO
2323
title=" Integrate Firebase with Web3Auth Android SFA SDK"
@@ -75,26 +75,23 @@ For the prerequisites, and other mandatory configuration of the SDK, please head
7575

7676
### Initialization
7777

78-
After successfully installing the package, the next step is to initialize `SingleFactorAuth` in your
79-
Android app. This sets up the necessary configurations using Web3Auth network and prepares the SDK.
80-
[Learn more about SingleFactorAuth Initialization](/docs/sdk/sfa/sfa-android/initialize).
78+
After successfully installing the package, the next step is to instantiate `SingleFactorAuth` in
79+
your Android app. This sets up the necessary configurations using Web3Auth network and prepares the
80+
SDK. [Learn more about SingleFactorAuth Initialization](/docs/sdk/sfa/sfa-android/initialize).
8181

82-
<Initialization />
83-
84-
### Session Management
82+
<Instantiation />
8583

86-
To check whether the user is authenticated, you can use the `initialize` method. For a user already
87-
authenticated, the result would be a non-nullable `SFAKey`. You can navigate to different views
88-
based on the result.
84+
Once you have successfully instantiated `SingleFactorAuth`, you can use the `initialize` method to
85+
initialize the SDK with existing valid session.
8986

90-
<SessionManagement />
87+
<Initialization />
9188

9289
### Authentication
9390

9491
If the user is not authenticated, you should utilize the `connect` method. For the guide, we will
9592
add Email Password login using Firebase. The `connect` method is pretty straightforward in
9693
SingleFactorAuth and takes `LoginParams` as input. After successfully logging in, the method will
97-
return the `SFAKey`.
94+
return the `SessionData`.
9895

9996
Learn more about [SingleFactorAuth LoginParams](/docs/sdk/sfa/sfa-android/usage#parameters). To more
10097
about Firebase login methods, please
@@ -131,8 +128,8 @@ auth.signInWithEmailAndPassword("[email protected]", "Android@Web3Auth")
131128
)
132129

133130
try {
134-
// Save the SFAKey for future use to interact with Blockchain.
135-
sfaKey = singleFactorAuth.connect(
131+
// Save the SessionData for future use to interact with Blockchain.
132+
sessionData = singleFactorAuth.connect(
136133
loginParams,
137134
this.applicationContext,
138135
86400
@@ -145,7 +142,7 @@ auth.signInWithEmailAndPassword("[email protected]", "Android@Web3Auth")
145142
e.printStackTrace()
146143
}
147144

148-
publicAddress = sfaKey?.publicAddress.toString()
145+
publicAddress =sessionData?.publicAddress.toString()
149146

150147
println("""Private Key: ${sfaKey?.privateKey?.toString(16)}""".trimIndent())
151148
println("""Public Address: $publicAddress""".trimIndent())

0 commit comments

Comments
 (0)