Login with UID

Last Updated on : 2024-10-15 09:43:19download

Login with a user ID (UID) is implemented with the API method that integrates with registration and login. This applies to existing accounts. A UID uniquely identifies a user and it is maintained in your user account system.

You might often misunderstand that UID refers to the UID in the Tuya system. In fact, the UID should be the unique user identifier in your system. By using the UID, you can establish a connection between your own system database and Tuya’s database.

API description

Automatically enables login if an account is registered, or enables registration and login if the account is not registered.

- (void)loginOrRegisterWithCountryCode:(NSString *)countryCode
                                   uid:(NSString *)uid
                              password:(NSString *)password
                            createHome:(BOOL)createHome
                               success:(nullable ThingSuccessID)success
                               failure:(nullable ThingFailureError)failure;

Parameters

Parameter Description
countryCode The country code, such as 86.
uid The UID that uniquely identifies a user, without format requirements.
password 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.
createHome Specifies whether to create a default home.
success The success callback.
failure The failure callback. An error message is returned.

Example

ObjC:

[[ThingSmartUser sharedInstance] loginOrRegisterWithCountryCode:@"your_country_code" uid:@"your_uid" password:@"your_password" createHome:YES success:^(id result) {
        NSLog(@"loginOrRegisterWithCountryCode success: %@", result);
} failure:^(NSError *error) {
        NSLog(@"loginOrRegisterWithCountryCode failure: %@", error);
}];

Swift:

ThingSmartUser.sharedInstance()?.loginOrRegisterWithCountryCode("your_country_code", uid: "your_uid", password: "your_password", createHome: true, success: { (result) in
		print("loginOrRegisterWithCountryCode success: \(result)")
}, failure: { (error) in
		if let e = error {
    		print("loginOrRegisterWithCountryCode failure: \(e)")
    }
})