Skip to content

Commit

Permalink
fix(web): do not redirect to login until really needed (#1340)
Browse files Browse the repository at this point in the history
## Problem

There is an extra redirection to /login route during the short period
the login request is being performed. The user does not stuck in the
login page because it redirects to the root route as soon as isLoggedIn
is set, but it produces both,

* A not needed redirection.
* A quick login screen flickering.

## Solution

Do not set the isLoggedIn value until it is really known.


## Testing

- Tested manually
  • Loading branch information
dgdavid authored Jun 14, 2024
2 parents 4cd7aa4 + bfcbb9b commit c503c2e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions web/package/agama-web-ui.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Fri Jun 14 07:37:58 UTC 2024 - David Diaz <[email protected]>

- Do not redirect to login page until really needed
(gh#openSUSE/agama#1340).

-------------------------------------------------------------------
Fri Jun 14 05:34:52 UTC 2024 - Imobach Gonzalez Sosa <[email protected]>

Expand Down
2 changes: 1 addition & 1 deletion web/src/Protected.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { AppProviders } from "./context/app";
export default function Protected() {
const { isLoggedIn } = useAuth();

if (isLoggedIn !== true) {
if (isLoggedIn === false) {
return <Navigate to="/login" />;
}

Expand Down
2 changes: 1 addition & 1 deletion web/src/context/auth.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const AuthErrors = Object.freeze({
* @param {React.ReactNode} [props.children] - content to display within the provider
*/
function AuthProvider({ children }) {
const [isLoggedIn, setIsLoggedIn] = useState(false);
const [isLoggedIn, setIsLoggedIn] = useState(undefined);
const [error, setError] = useState(null);

const login = useCallback(async (password) => {
Expand Down

0 comments on commit c503c2e

Please sign in to comment.