register method
Future<RegisterResponse>
register({
- String? username,
- String? password,
- String? deviceId,
- String? initialDeviceDisplayName,
- bool? inhibitLogin,
- bool? refreshToken,
- AuthenticationData? auth,
- AccountKind? kind,
- void onInitStateChanged()?,
override
Checks to see if a username is available, and valid, for the server. Returns the fully-qualified Matrix user ID (MXID) that has been registered. You have to call checkHomeserver first to set a homeserver.
Implementation
@override
Future<RegisterResponse> register({
String? username,
String? password,
String? deviceId,
String? initialDeviceDisplayName,
bool? inhibitLogin,
bool? refreshToken,
AuthenticationData? auth,
AccountKind? kind,
void Function(InitState)? onInitStateChanged,
}) async {
final response = await super.register(
kind: kind,
username: username,
password: password,
auth: auth,
deviceId: deviceId,
initialDeviceDisplayName: initialDeviceDisplayName,
inhibitLogin: inhibitLogin,
refreshToken: refreshToken ?? onSoftLogout != null,
);
// Connect if there is an access token in the response.
final accessToken = response.accessToken;
final deviceId_ = response.deviceId;
final userId = response.userId;
final homeserver = this.homeserver;
if (accessToken == null || deviceId_ == null || homeserver == null) {
throw Exception(
'Registered but token, device ID, user ID or homeserver is null.',
);
}
final expiresInMs = response.expiresInMs;
final tokenExpiresAt = expiresInMs == null
? null
: DateTime.now().add(Duration(milliseconds: expiresInMs));
await init(
newToken: accessToken,
newTokenExpiresAt: tokenExpiresAt,
newRefreshToken: response.refreshToken,
newUserID: userId,
newHomeserver: homeserver,
newDeviceName: initialDeviceDisplayName ?? '',
newDeviceID: deviceId_,
onInitStateChanged: onInitStateChanged,
);
return response;
}