English
English
简体中文
Contact Us
Register
Log In

Login with UID

Last Updated on : 2022-12-15 10:38:15download

Login with a user ID (UID) is implemented with the API method that integrates with registration and login. It automatically enables login if an account is registered, or enables registration and login if the account is not registered.

API description

TuyaHomeSdk.getUserInstance().loginOrRegisterWithUid(String countryCode, String uid, String passwd, ILoginCallback callback);

// Allows users to create a default home.
TuyaHomeSdk.getUserInstance().loginOrRegisterWithUid(String countryCode, String uid, String passwd, boolean isCreateHome, IUidLoginCallback callback);

Parameters

Parameter Description
countryCode The country code, such as 86.
uid The UID of the user.
passwd The random identifier that matches the account ID. Only one identifier is assigned to each account ID. This identifier is not the user’s actual password.
isCreateHome Specifies whether to create a default home.
callback The callback.

Example

// Enables login with the UID.
TuyaHomeSdk.getUserInstance().loginOrRegisterWithUid("86", "1234", "123456", new ILoginCallback() {
    @Override
    public void onSuccess(User user) {
        Toast.makeText(mContext, "Logged in successfully. Username:" , Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onError(String code, String error) {
        Toast.makeText(mContext, "code: " + code + "error:" + error, Toast.LENGTH_SHORT).show();
    }
});