Skip to content

Commit

Permalink
fix: login bug when both anonymous and auth is enabled
Browse files Browse the repository at this point in the history
Signed-off-by: Raul-Cristian Kele <raulkeleblk@gmail.com>
  • Loading branch information
raulkele committed Jun 16, 2023
1 parent 936590d commit 52171f8
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/components/Login/SignIn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useNavigate } from 'react-router-dom';
import { host } from '../../host';
// utility
import { api, endpoints } from '../../api';
import { isEmpty } from 'lodash';
import { isEmpty, isNil } from 'lodash';

// components
import Button from '@mui/material/Button';
Expand Down Expand Up @@ -142,17 +142,18 @@ export default function SignIn({ isLoggedIn, setIsLoggedIn, wrapperSetLoading =
event.preventDefault();
setRequestProcessing(true);
let cfg = {};
const token = btoa(username + ':' + password);
cfg = {
headers: {
Authorization: `Basic ${token}`
}
};
let token = !isNil(username) && !isNil(password) ? btoa(username + ':' + password) : '-';
if (token !== '-') {
cfg = {

Check warning on line 147 in src/components/Login/SignIn.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Login/SignIn.jsx#L147

Added line #L147 was not covered by tests
headers: {
Authorization: `Basic ${token}`
}
};
}
api
.get(`${host()}/v2/`, abortController.signal, cfg)
.then((response) => {
if (response.status === 200) {
const token = btoa(username + ':' + password);
localStorage.setItem('token', token);
setRequestProcessing(false);
setRequestError(false);
Expand Down

0 comments on commit 52171f8

Please sign in to comment.