validate method
Authenticate the user with an email/phone and password
Implementation
Future<BagelUser?> validate(String emailOrPhone, String password) async {
String url = '$authEndpoint/user/verify';
Map body = {"password": password};
String _emailOrPhone = emailOrPhone.trim().toLowerCase();
if (_emailOrPhone.contains('@'))
body["email"] = _emailOrPhone;
else
body["phone"] = _emailOrPhone;
try {
Response res = await dio.post(url, data: body);
_storeTokens(res.data);
if (_emailOrPhone.contains('@'))
return await _setUser(res.data["user_id"], email: _emailOrPhone);
else
return await _setUser(res.data["user_id"], phone: _emailOrPhone);
} catch (e) {
if (e is DioException) throw (e.response.toString());
}
return null;
}