signInByBiometric method
Implementation
Future<AuthResponse<T>> signInByBiometric({
Object? args,
String? id,
bool notifiable = true,
}) async {
emit(
const AuthResponse.loading(AuthType.biometric),
args: args,
id: id,
notifiable: notifiable,
);
try {
final user = await _cachedAuth;
if (user == null || !user.isBiometric) {
return emit(
AuthResponse.unauthorized(
msg: msg.signInWithBiometric.failure ?? _errorNotifier.value,
type: AuthType.biometric,
),
args: args,
id: id,
notifiable: notifiable,
);
}
final response = await delegate.signInWithBiometric();
if (!response.isSuccessful) {
return _failure(
response.error,
type: AuthType.biometric,
args: args,
id: id,
notifiable: notifiable,
);
}
final provider = user.provider;
var current = Response<Credential>();
final hasCredentials = (user.email ?? user.username ?? '').isNotEmpty &&
(user.password ?? '').isNotEmpty;
if (hasCredentials) {
if (provider == 'EMAIL') {
current = await delegate.signInWithEmailNPassword(
user.email ?? '',
user.password ?? '',
);
} else if (provider == 'USERNAME') {
current = await delegate.signInWithUsernameNPassword(
user.username ?? '',
user.password ?? '',
);
}
}
if (!current.isSuccessful) {
return _failure(
current.error,
type: AuthType.biometric,
args: args,
id: id,
notifiable: notifiable,
);
}
final value = await _update(
id: user.id,
data: {
keys.loggedIn: true,
keys.loggedInTime: EntityHelper.generateTimeMills,
},
);
return emit(
AuthResponse.authenticated(
value,
msg: msg.signInWithBiometric.done,
type: AuthType.biometric,
),
args: args,
id: id,
notifiable: notifiable,
);
} catch (error) {
return _failure(
msg.signInWithBiometric.failure ?? error.toString(),
type: AuthType.biometric,
args: args,
id: id,
notifiable: notifiable,
);
}
}