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,
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.accessToken ?? ""),
multiFactorInfo: multiFactorInfo,
multiFactorSession: multiFactorSession,
timeout: timeout,
onComplete: (credential) async {
if (onComplete != null) {
emit(
const AuthResponse.message(
"Verification done!",
provider: Provider.phone,
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) {
signInByOtp(
authenticator.otp(
token: verId,
smsCode: code,
),
);
} else {
emit(
const AuthResponse.failure(
"Verification token or otp code not valid!",
provider: Provider.phone,
type: AuthType.otp,
),
args: args,
id: id,
notifiable: notifiable,
);
}
}
},
onCodeSent: (String verId, int? forceResendingToken) {
emit(
const AuthResponse.message(
"Code sent to your device!",
provider: Provider.phone,
type: AuthType.otp,
),
args: args,
id: id,
notifiable: notifiable,
);
if (onCodeSent != null) onCodeSent(verId, forceResendingToken);
},
onFailed: (exception) {
emit(
AuthResponse.failure(
exception.msg,
provider: Provider.phone,
type: AuthType.otp,
),
args: args,
id: id,
notifiable: notifiable,
);
if (onFailed != null) onFailed(exception);
},
onCodeAutoRetrievalTimeout: (String verId) {
emit(
const AuthResponse.failure(
"Auto retrieval code timeout!",
provider: Provider.phone,
type: AuthType.otp,
),
args: args,
id: id,
notifiable: notifiable,
);
if (onCodeAutoRetrievalTimeout != null) {
onCodeAutoRetrievalTimeout(verId);
}
},
);
return emit(
const AuthResponse.loading(
Provider.phone,
AuthType.otp,
),
args: args,
id: id,
notifiable: notifiable,
);
} catch (error) {
return emit(
AuthResponse.failure(
msg.signOut.failure ?? error,
provider: Provider.phone,
type: AuthType.otp,
),
args: args,
id: id,
notifiable: notifiable,
);
}
}