Retrieve user information
You can use the getUserInfo method to retrieve various details about the user, such as their sign-in method, whether multi-factor authentication (MFA) is enabled, profile image, name, and other relevant information.
Call getUserInfo() after initialize() or connectTo() completes successfully.
It throws an Error (No user found, please login again!) if no session has been restored or created, and returns null after logout().
Usage
val userInfo = web3Auth.getUserInfo()
getUserInfoAsync()
getUserInfoAsync() returns the same UserInfo as a CompletableFuture<UserInfo>.
If the in-memory profile has no idToken, it fills idToken from the stored Auth session before completing.
Use it when you need the idToken after restoring a session with initialize().
web3Auth.getUserInfoAsync().whenComplete { userInfo, error ->
if (error == null) {
Log.d("MainActivity_Web3Auth", "User: ${userInfo.email}")
} else {
Log.d("MainActivity_Web3Auth", error.message ?: "No user found")
}
}
getUserInfoAsync() completes exceptionally with No user found, please login again! if there's no active session.
UserInfo Fields
| Field | Type | Description |
|---|---|---|
email | String | Email address of the user. Empty string if not available. |
name | String | Display name of the user. Empty string if not available. |
profileImage | String | URL of the user's profile image. Empty string if not available. |
authConnectionId | String | The auth connection ID (verifier name) used to sign in. |
groupedAuthConnectionId | String | The grouped auth connection ID if aggregate verifiers are used. Empty string if not applicable. |
userId | String | The user's unique ID within the auth connection (for example, email for email-based, sub for OAuth). |
authConnection | String | The auth connection type used (for example, "google", "custom"). |
dappShare | String | dapp share for custom verifiers. Empty string for default verifiers. |
idToken | String | JWT issued by Web3Auth after authentication. May be empty after initialize(); use getUserInfoAsync() or getIdentityToken(). |
oAuthIdToken | String | JWT issued by the OAuth provider. Only present for custom verifiers. |
oAuthAccessToken | String | Access token issued by the OAuth provider. Only present for custom verifiers. |
isMfaEnabled | Boolean? | Whether the user has MFA enabled. null if the information is not available in the session. |
Interface
data class UserInfo(
var email: String = "",
var name: String = "",
var profileImage: String = "",
var groupedAuthConnectionId: String = "",
var authConnectionId: String = "",
var userId: String = "",
var authConnection: String = "",
var dappShare: String = "",
var idToken: String = "",
var oAuthIdToken: String = "",
var oAuthAccessToken: String = "",
var isMfaEnabled: Boolean? = null
)