signInByBiometric method
Implementation
Future<AuthResponse<T>> signInByBiometric({
Object? args,
String? id,
bool notifiable = true,
}) async {
emit(
const AuthResponse.loading(
Provider.biometric,
AuthType.biometric,
),
args: args,
id: id,
notifiable: notifiable,
);
try {
final user = await _auth;
if (user == null || !user.isBiometric) {
return emit(
AuthResponse.unauthorized(
msg: msg.signInWithBiometric.failure ?? errorText,
provider: Provider.biometric,
type: AuthType.biometric,
),
args: args,
id: id,
notifiable: notifiable,
);
}
final response = await delegate.signInWithBiometric();
if (!response.isSuccessful) {
return emit(
AuthResponse.failure(
response.error,
provider: Provider.biometric,
type: AuthType.biometric,
),
args: args,
id: id,
notifiable: notifiable,
);
}
final token = user.accessToken;
final provider = Provider.from(user.provider);
var current = Response<Credential>();
if ((user.email ?? user.username ?? "").isNotEmpty &&
(user.password ?? '').isNotEmpty) {
if (provider.isEmail) {
current = await delegate.signInWithEmailNPassword(
user.email ?? "",
user.password ?? "",
);
} else if (provider.isUsername) {
current = await delegate.signInWithUsernameNPassword(
user.username ?? "",
user.password ?? "",
);
}
} else if ((token ?? user.idToken ?? "").isNotEmpty) {
current = await delegate.signInWithCredential(Credential(
uid: user.id,
providerId: provider.id,
idToken: user.idToken,
accessToken: token,
));
}
if (!current.isSuccessful) {
return emit(
AuthResponse.failure(
current.error,
provider: Provider.biometric,
type: AuthType.biometric,
),
args: args,
id: id,
notifiable: notifiable,
);
}
final value = await _update(id: user.id, updates: {
AuthKeys.i.loggedIn: true,
AuthKeys.i.loggedInTime: EntityHelper.generateTimeMills,
});
return emit(
AuthResponse.authenticated(
value,
msg: msg.signInWithBiometric.done,
provider: Provider.biometric,
type: AuthType.biometric,
),
args: args,
id: id,
notifiable: notifiable,
);
} catch (error) {
return emit(
AuthResponse.failure(
msg.signInWithBiometric.failure ?? error,
provider: Provider.biometric,
type: AuthType.biometric,
),
args: args,
id: id,
notifiable: notifiable,
);
}
}