Ensure that the userID is saved after both login and signup events

This commit is contained in:
Vishnu Mohandas 2020-08-01 04:28:30 +05:30
parent 8b600143c7
commit b1b67913bd

View file

@ -22,10 +22,7 @@ class UserAuthenticator {
"password": password,
}).then((response) {
if (response.statusCode == 200 && response.data != null) {
Configuration.instance.setUsername(username);
Configuration.instance.setPassword(password);
Configuration.instance.setUserID(response.data["id"]);
Configuration.instance.setToken(response.data["token"]);
_saveConfiguration(username, password, response);
Bus.instance.fire(UserAuthenticatedEvent());
return true;
} else {
@ -44,9 +41,7 @@ class UserAuthenticator {
"password": password,
}).then((response) {
if (response.statusCode == 200 && response.data != null) {
Configuration.instance.setUsername(username);
Configuration.instance.setPassword(password);
Configuration.instance.setToken(response.data["token"]);
_saveConfiguration(username, password, response);
Bus.instance.fire(UserAuthenticatedEvent());
return true;
} else {
@ -61,4 +56,11 @@ class UserAuthenticator {
throw e;
});
}
void _saveConfiguration(String username, String password, Response response) {
Configuration.instance.setUsername(username);
Configuration.instance.setPassword(password);
Configuration.instance.setUserID(response.data["id"]);
Configuration.instance.setToken(response.data["token"]);
}
}