Skip to content

Commit

Permalink
Updated:
Browse files Browse the repository at this point in the history
-Logout Behaviour
-PW reset popup message
-Text for pw reset button
  • Loading branch information
Lee-Wei-Jie committed Aug 25, 2024
1 parent 2570acb commit f3abbfe
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/main/resources/.h2.server.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#H2 Server Properties
#Sun Aug 18 23:12:35 SGT 2024
#Sun Aug 25 19:54:40 SGT 2024
0=JHipster H2 (Disk)|org.h2.Driver|jdbc\:h2\:file\:./target/h2db/db/scaleup|scaleup
webAllowOthers=true
webPort=8092
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const PasswordResetFinishPage = () => {
data-cy="confirmResetPassword"
/>
<Button color="success" type="submit" data-cy="submit">
Validate new password
Update to new password
</Button>
</ValidatedForm>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,17 @@ export const PasswordResetSlice = createSlice({
.addCase(handlePasswordResetFinish.fulfilled, () => ({
...initialState,
loading: false,
//password reset state set to success
resetPasswordSuccess: true,
successMessage: "Your password couldn't be reset. Remember a password request is only valid for 24 hours.",
//successMessage: "Your password couldn't be reset. Remember a password request is only valid for 24 hours.",
//scrape 24h thinggy? since cant demo
successMessage: 'Your password reset have been completed successfully',
}))
.addMatcher(isPending(handlePasswordResetInit, handlePasswordResetFinish), state => {
state.loading = true;
})
//A matcher function to handle actions that have been rejected
//resets the state to initialState, sets loading to false, and marks the operation as failed with a relevant flag (resetPasswordFailure)
.addMatcher(isRejected(handlePasswordResetInit, handlePasswordResetFinish), () => ({
...initialState,
loading: false,
Expand Down
48 changes: 39 additions & 9 deletions src/main/webapp/app/modules/login/logout.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,50 @@
import React, { useLayoutEffect } from 'react';
import React, { useLayoutEffect, useState, useEffect } from 'react';

import { useAppDispatch, useAppSelector } from 'app/config/store';
import { logout } from 'app/shared/reducers/authentication';

// export const Logout = () => {
// const authentication = useAppSelector(state => state.authentication);
// const dispatch = useAppDispatch();

// useLayoutEffect(() => {
// dispatch(logout());
// if (authentication.logoutUrl) {
// window.location.href = authentication.logoutUrl;
// } else if (!authentication.isAuthenticated) {
// window.location.href = '/';
// }
// });

// return (
// <div className="p-5">
// <h4>Logged out successfully!</h4>
// </div>
// );
// };

export const Logout = () => {
const [isRedirecting, setIsRedirecting] = useState(false);
const authentication = useAppSelector(state => state.authentication);
const dispatch = useAppDispatch();

useLayoutEffect(() => {
dispatch(logout());
if (authentication.logoutUrl) {
window.location.href = authentication.logoutUrl;
} else if (!authentication.isAuthenticated) {
window.location.href = '/';
}
});
useEffect(() => {
const performLogout = async () => {
dispatch(logout());
setIsRedirecting(true); // Set flag to indicate redirection in progress

// Introduce a delay to handle the error boundary clean-up
await new Promise(resolve => setTimeout(resolve, 100)); // Adjust delay as needed

if (authentication.logoutUrl) {
window.location.href = authentication.logoutUrl;
} else if (!authentication.isAuthenticated) {
window.location.href = '/';
}
};

performLogout();
}, [dispatch, authentication]);

return (
<div className="p-5">
Expand Down

0 comments on commit f3abbfe

Please sign in to comment.