Skip to content

Commit 62b452b

Browse files
committed
Reject failed login attempts.
Make sure calls to login() return a rejection when there is an error either connecting to the API or invalid credentials. Without this, even if the login API request fails the promise isn't rejected and so in LoginForm.js the .then() statement is called and makes it look like the user is logged in. With this, the promise is rejected and the .catch() is called.
1 parent 5f91569 commit 62b452b

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

react-decoupled/src/components/LoginForm.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const LoginForm = () => {
4141
.catch((error) => {
4242
setSubmitting(false);
4343
setLoggedIn(false);
44-
setResult({ error: true, message: 'Login error' });
44+
setResult({ error: true, message: `Login error: ${error.message}` });
4545
console.log('Login error', error);
4646
});
4747
};

react-decoupled/src/utils/auth.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ export function getAuthClient(config = {}) {
6161
const data = await response.json();
6262
if (data.error) {
6363
console.log('Error retrieving token', data);
64-
return false;
64+
return Promise.reject(new Error(`Error retrieving OAuth token: ${data.error}`));
6565
}
6666
return saveToken(data);
6767
}
6868
catch (err) {
69-
return console.log('API got an error', err);
69+
console.log('API got an error', err);
70+
return Promise.reject(new Error(`API error: ${err}`));
7071
}
7172
};
7273

0 commit comments

Comments
 (0)