Connect UniPass Wallet
After the initialization is complete, invoke the login
method to get information about the UniPass Account UniPassUserInfo
.
UniPass currently supports customizing login options for login
method, including:
connectType
: indicate the provider used to login UniPass, includinggoogle
,email
andboth
options. The default value isboth
, indicating use any supported way to login UniPass.authorize
: if set totrue
, UniPass will return a auto generatedSign-in With Ethereum
message, and a signature for the message. The default value isfalse
.returnEmail
: if set totrue
, UniPass accountemail
will be returned. The default value isfalse
.forceLogin
: if set totrue
, user will always have to log in even if they have logged in to the site before.
Type definitions
interface UnipassCallBack <T>{
fun success(output: T?)
fun failure(exception: Exception)
}
data class LoginOption (
val connectType: ConnectType? = ConnectType.BOTH,
val authorize: Boolean? = false,
val returnEmail: Boolean? = false,
val forceLogin: Boolean? = false
)
class LoginOutput: BaseOutput(OutputType.Login) {
val userInfo: UserInfo? = null
}
data class UserInfo (
var email: String?,
var address: String,
var newborn: Boolean = false,
val message: String?,
val signature: String?
)
enum class OutputType {
@SerializedName("UP_LOGIN")
Login,
@SerializedName("UP_LOGOUT")
Logout,
@SerializedName("UP_SIGN_MESSAGE")
SignMessage,
@SerializedName("UP_TRANSACTION")
SendTransaction
}
enum class ConnectType(value: String) {
GOOGLE("google"),
EMAIL("email"),
BOTH("both"),
}
Code sample
unipassInstance.login(object : UnipassCallBack<LoginOutput> {
override fun success(output: LoginOutput?) {
Log.d("Unipass Login", "success")
}
override fun failure(error: Exception) {
Log.d("Unipass Login", error.message ?: "Something went wrong")
}
}, LoginOption(ConnectType.BOTH, authorize))
// LoginOption is not required, it is used to customize login option
// Or you can use an overloaded login so that users connect at the type you choose
// connectType default is BOTH
unipassInstance.login(ConnectType.GOOGLE, object : UnipassCallBack<LoginOutput> {
override fun success(output: LoginOutput?) {
Log.d("Unipass Login", "success")
}
override fun failure(error: Exception) {
Log.d("Unipass Login", error.message ?: "Something went wrong")
}
})
newborn
can be used to track new registration count.
Verification for Sign-in With Ethereum
If you set authorize
to true
, you may need to verify the signature of Sign-in With Ethereum, please refer to Sign-in With Ethereum.