Skip to content

Commit

Permalink
Redirect to login page after pwd reset
Browse files Browse the repository at this point in the history
When a given user with OTP token is resetting its
password, it was automatically auto-login with
the new credentials. The new solution should
redirect to the login page after a password
reset to allow users to explicitely introduce
the new password.

Fixes: #645
Signed-off-by: Carla Martinez <carlmart@redhat.com>
  • Loading branch information
carma12 authored and miskopo committed Feb 25, 2025
1 parent 9ab3167 commit 15ef911
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions src/login/ResetPasswordPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ import {
MetaResponse,
ResetPasswordPayload,
useResetPasswordMutation,
useUserPasswordLoginMutation,
} from "src/services/rpcAuth";
// Redux
import { useAppDispatch } from "src/store/hooks";
import { setIsLogin } from "src/store/Global/auth-slice";
// Hooks
import useAlerts from "src/hooks/useAlerts";
// Components
Expand All @@ -44,9 +40,6 @@ const ResetPasswordPage = () => {
}
}, []);

// Redux
const dispatch = useAppDispatch();

// Navigate
const navigate = useNavigate();

Expand All @@ -55,7 +48,6 @@ const ResetPasswordPage = () => {

// API calls
const [resetPassword] = useResetPasswordMutation();
const [onUserPwdLogin] = useUserPasswordLoginMutation();

// Main states
const [currentPassword, setCurrentPassword] = React.useState<string>("");
Expand Down Expand Up @@ -122,16 +114,6 @@ const ResetPasswordPage = () => {

const isResetButtonDisabled = evaluateResetButtonDisabled();

// Login function
const onLogin = () => {
onUserPwdLogin({ username: uid, password: newPassword }).then(() => {
dispatch(setIsLogin({ loggedInUser: uid, error: null }));
setBtnSpinning(false);
// Assuming sucessful login. Refresh page
window.location.reload();
});
};

// Clear fields when the reset password operation failed
const clearFields = () => {
setCurrentPassword("");
Expand Down Expand Up @@ -169,8 +151,8 @@ const ResetPasswordPage = () => {
clearFields();
setBtnSpinning(false);
} else {
// Login with the new credentials
onLogin();
// Redirect to login page to allow the user to login with new credentials
navigate("/login");
}
}
});
Expand Down Expand Up @@ -250,7 +232,7 @@ const ResetPasswordPage = () => {
onClick={onResetPwd}
isLoading={spinning}
>
{spinning ? "Resetting and login" : "Reset password and Log in"}
{spinning ? "Resetting" : "Reset password"}
</Button>
</ActionGroup>
</Form>
Expand Down

0 comments on commit 15ef911

Please sign in to comment.