-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exception when calling credentials::username_password
#112
Comments
Hi @adamski have you created this user from the Device Sync UI or registered this user before the login call? |
@leemaguire Your question helped me to figure out part of what was going wrong. I wanted to call a custom authentication function, and was calling the wrong method. Now I am calling the correct function, and getting the expected response, however on failure (if the credentials are not found) the exception seems to be "considered fatal" and is not able to be caught:
(Here the string "Authentication failed with reason: Invalid email or password" comes from the custom function) Note: it works perfectly when supplied with the correct credentials. This is the updated code section: auto app = realm::App (realmConfig);
realm::user user;
try
{
std::future_status status;
realm::bson::BsonDocument credentials = {
{"username", "[email protected]"},
{"password", "password1"}};
auto userFuture = app.login (realm::App::credentials::function(credentials));
do
{
switch (status = userFuture.wait_for (50ms); status)
{
case std::future_status::deferred:
std::cout << "deferred\n";
break;
case std::future_status::timeout:
std::cout << "timeout\n";
break;
case std::future_status::ready:
std::cout << "ready!\n";
break;
}
} while (status != std::future_status::ready);
user = userFuture.get();
std::cout << "result is " << user.identifier() << '\n';
}
catch (std::exception& e)
{
std::cout << "Error logging in: " << e.what() << std::endl;
} |
Is it because it's an async function that I'm not able to catch the exception? I'm not familiar with futures and exceptions |
@adamski what version are you using? I can capture the error in the catch block using your code. |
I found the cause of the issue: The exception type needs to be catch (const realm::app_error& e) |
0.4.0 |
@adamski we still have to normalize our exceptions. In the meantime I would recommend catching with the (...) syntax and reading from the last exception ptr from the std library. |
Hi Team, I used exactly the same code above and in my case, I get the below error irrespective of what kind of authentication method I use, such as anonymous, username/password, api key, etc. ` Error logging in: non-zero custom status code considered fatal I think I spent lots of time going back and forth to sync settings, and nothing worked. Any help on this will be greatly appreciated. Thanks, |
I am trying out username/password authentication.
I am getting the following exception (not caught by the try/catch block):
Here is my code:
I'm not sure what's going wrong.
The text was updated successfully, but these errors were encountered: