signInByPhone method
Future<AuthResponse<T> >
signInByPhone(
- PhoneAuthenticator authenticator, {
- Object? multiFactorInfo,
- Object? multiFactorSession,
- Duration timeout = const Duration(minutes: 2),
- void onComplete(
- Credential credential
- void onFailed(
- AuthException exception
- void onCodeSent()?,
- void onCodeAutoRetrievalTimeout(
- String verId
- Object? args,
- String? id,
- bool notifiable = true,
inherited
Implementation
Future<AuthResponse<T>> signInByPhone(
PhoneAuthenticator authenticator, {
Object? multiFactorInfo,
Object? multiFactorSession,
Duration timeout = const Duration(minutes: 2),
void Function(Credential credential)? onComplete,
void Function(AuthException exception)? onFailed,
void Function(String verId, int? forceResendingToken)? onCodeSent,
void Function(String verId)? onCodeAutoRetrievalTimeout,
Object? args,
String? id,
bool notifiable = true,
}) async {
try {
delegate.verifyPhoneNumber(
phoneNumber: authenticator.phone,
forceResendingToken: int.tryParse(authenticator.resendToken ?? ''),
multiFactorInfo: multiFactorInfo,
multiFactorSession: multiFactorSession,
timeout: timeout,
onComplete: (credential) async {
if (onComplete != null) {
emit(
const AuthResponse.message(
'Verification done!',
type: AuthType.otp,
),
args: args,
id: id,
notifiable: notifiable,
);
onComplete(credential);
} else {
final verId = credential.verificationId;
final code = credential.smsCode;
if (verId != null && code != null) {
await signInByOtp(
OtpAuthenticator.phone(
token: verId,
code: code,
phone: authenticator.phone,
),
args: args,
id: id,
notifiable: notifiable,
);
} else {
emit(
const AuthResponse.failure(
'Verification token or otp code not valid!',
type: AuthType.otp,
),
args: args,
id: id,
notifiable: notifiable,
);
}
}
},
onCodeSent: (verId, forceResendingToken) {
emit(
const AuthResponse.message(
'Code sent to your device!',
type: AuthType.otp,
),
args: args,
id: id,
notifiable: notifiable,
);
onCodeSent?.call(verId, forceResendingToken);
},
onFailed: (exception) {
emit(
AuthResponse.failure(
exception.msg,
type: AuthType.otp,
),
args: args,
id: id,
notifiable: notifiable,
);
onFailed?.call(exception);
},
onCodeAutoRetrievalTimeout: (verId) {
emit(
const AuthResponse.failure(
'Auto retrieval code timeout!',
type: AuthType.otp,
),
args: args,
id: id,
notifiable: notifiable,
);
onCodeAutoRetrievalTimeout?.call(verId);
},
);
return emit(
const AuthResponse.loading(AuthType.otp),
args: args,
id: id,
notifiable: notifiable,
);
} catch (error) {
return _failure(
msg.signOut.failure ?? error.toString(),
type: AuthType.otp,
args: args,
id: id,
notifiable: notifiable,
);
}
}