Skip to content

Commit

Permalink
Merge pull request #1007 from Web3Auth/sfa-android-v3
Browse files Browse the repository at this point in the history
[SFA Android] Update docs for v3
  • Loading branch information
AyushBherwani1998 authored Dec 12, 2024
2 parents 2a62336 + a6f1dbc commit 52b6f1a
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 53 deletions.
45 changes: 45 additions & 0 deletions docs/migration-guides/sfa-android-v2-to-v3.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
title: SFA Android SDK - v2.0.0 to v3.0.0
description: "SFA Android SDK - v2.0.0 to v3.0.0 | Documentation - Web3Auth"
sidebar_label: v2.0.0 to v3.0.0
---

This migration guide provides steps for upgrading from version v2.0.0 to v3.0.0 of the SFA Android
SDK. The guide outlines significant changes and enhancements.

## Breaking Changes

### initialize Method Changes

In v3, the `initialize` method will now return void upon successful initialization instead of
returning `SessionData`. After successful initialization, you can use the
[getSessionData](/docs/sdk/sfa/sfa-android/usage/#get-session-data) method to check if the user is
logged in or not.

```kotlin
val initializeCF = singleFactoreAuth.initialize(this.applicationContext)

// remove-next-line
initializeCF.whenComplete { sessionData, error ->
// add-next-line
initializeCF.whenComplete {_, error ->
if (error != null) {
// Handle error
}
// remove-start
else if (sessionData != null) {
// User is logged in
} else {
// User is not logged in
}
// remove-end
// add-start
let sessionData = singleFactorAuth.getSessionData()
if(sessionData != null) {
// User is logged in
} else {
// User is not logged in
}
// add-end
}
```
13 changes: 6 additions & 7 deletions docs/sdk/sfa/sfa-android/initialize.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ description: "Web3Auth Single Factor Auth Android SDK - Initialize | Documentati
import TabItem from "@theme/TabItem";
import Tabs from "@theme/Tabs";

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

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

## Create Instance

<Initialization />
<Instantiation />

## Initialize

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

<SessionManagement />
<Initialization />
1 change: 1 addition & 0 deletions sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1647,6 +1647,7 @@ const sidebars: SidebarsConfig = {
type: "category",
label: "Migration Guides",
items: [
"migration-guides/sfa-android-v2-to-v3",
"migration-guides/sfa-android-v1.2.0-to-v2.0.0",
"migration-guides/sfa-android-v0.4.0-to-v1",
"migration-guides/sfa-android-v0.1.0-to-v0.3.0",
Expand Down
20 changes: 10 additions & 10 deletions src/common/sdk/sfa/android/_sfa-android-initialization.mdx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
```kotlin
import android.content.Context
import com.web3auth.singlefactorauth.SingleFactorAuth
import com.web3auth.singlefactorauth.types.Web3AuthOptions
import org.torusresearch.fetchnodedetails.types.Web3AuthNetwork

// You can get the client id for your Web3Auth project from Web3Auth dashboard.
val web3AuthOptions = Web3AuthOptions(
"YOUR_WEB3AUTH_CLIENT_ID",
Web3AuthNetwork.SAPPHIRE_MAINNET
)

val context: Context = "YOUR_APPLICATION_CONTEXT"
val sessionDataCF = singleFactorAuth.initialize(context)

val singleFactorAuth = SingleFactorAuth(web3AuthOptions, context)
sessionDataCF.whenComplete {sessionData, error ->
if(error != null) {
// Something went wrong
// Initiate the login flow again
} else {
// You can use the SessionData to check if the user is
//logged in or not
}
}
```
16 changes: 16 additions & 0 deletions src/common/sdk/sfa/android/_sfa-android-instantiation.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
```kotlin
import android.content.Context
import com.web3auth.singlefactorauth.SingleFactorAuth
import com.web3auth.singlefactorauth.types.Web3AuthOptions
import org.torusresearch.fetchnodedetails.types.Web3AuthNetwork

// You can get the client id for your Web3Auth project from Web3Auth dashboard.
val web3AuthOptions = Web3AuthOptions(
"YOUR_WEB3AUTH_CLIENT_ID",
Web3AuthNetwork.SAPPHIRE_MAINNET
)

val context: Context = "YOUR_APPLICATION_CONTEXT"

val singleFactorAuth = SingleFactorAuth(web3AuthOptions, context)
```
20 changes: 0 additions & 20 deletions src/common/sdk/sfa/android/_sfa-android-session-management.mdx

This file was deleted.

2 changes: 1 addition & 1 deletion src/common/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const pnpUnityVersion = `5.x.x`;
export const pnpUnrealVersion = `4.1.x`;

export const sfaWebVersion = `9.2.x`;
export const sfaAndroidVersion = `2.1.0`;
export const sfaAndroidVersion = `3.0.0`;
export const sfaIOSVersion = `9.0.2`;
export const sfaRNVersion = `2.0.x`;
export const sfaFlutterVersion = `5.2.0`;
Expand Down
27 changes: 12 additions & 15 deletions src/pages/guides/sfa-android-firebase.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import TabItem from "@theme/TabItem";
import Tabs from "@theme/Tabs";

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

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

### Initialization

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

<Initialization />

### Session Management
<Instantiation />

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

<SessionManagement />
<Initialization />

### Authentication

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

Learn more about [SingleFactorAuth LoginParams](/docs/sdk/sfa/sfa-android/usage#parameters). To more
about Firebase login methods, please
Expand Down Expand Up @@ -131,8 +128,8 @@ auth.signInWithEmailAndPassword("android@firebase.com", "Android@Web3Auth")
)

try {
// Save the SFAKey for future use to interact with Blockchain.
sfaKey = singleFactorAuth.connect(
// Save the SessionData for future use to interact with Blockchain.
sessionData = singleFactorAuth.connect(
loginParams,
this.applicationContext,
86400
Expand All @@ -145,7 +142,7 @@ auth.signInWithEmailAndPassword("android@firebase.com", "Android@Web3Auth")
e.printStackTrace()
}

publicAddress = sfaKey?.publicAddress.toString()
publicAddress =sessionData?.publicAddress.toString()

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

0 comments on commit 52b6f1a

Please sign in to comment.