Skip to content

Commit

Permalink
Merge pull request #166 from VasylievYurii/fix(hack)-errors-on-logout
Browse files Browse the repository at this point in the history
errors on logout
  • Loading branch information
VasylievYurii authored Nov 21, 2023
2 parents 4736eb3 + 5fc80b8 commit ff2d8e4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 29 deletions.
52 changes: 26 additions & 26 deletions src/components/App/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,38 @@ import { selectMealsIsLoading } from '../../redux/selectors.js';
function App() {
const location = useLocation();
const dispatch = useDispatch();
const { isRefreshing } = useAuth();
const { isRefreshing, isLoggedIn } = useAuth();
const { profile } = useSelector((state) => state.profile);
const auth = useSelector(selectUserAuthenticated);
// const auth = useSelector(selectUserAuthenticated);
const workoutIsLoading = useSelector(selectWorkoutsIsLoading);
const profileIsLoading = useSelector(selectUserProfileIsLoading);
const productIsLoading = useSelector(selectProductsIsLoading);
const mealsIsLoading = useSelector(selectMealsIsLoading);

let isFilled = true;

if (auth) {
const profileArray = profile
? [
profile.height,
profile.currentWeight,
profile.desiredWeight,
profile.blood,
profile.sex,
profile.levelActivity,
profile.birthday,
]
: [];

for (let item of profileArray) {
if (item) {
isFilled = true;
} else {
isFilled = false;
break;
}
}
}
let isFilled = isLoggedIn && profile ? true : false;

// if (isLoggedIn && profile) {
// const profileArray = profile
// ? [
// profile.height,
// profile.currentWeight,
// profile.desiredWeight,
// profile.blood,
// profile.sex,
// profile.levelActivity,
// profile.birthday,
// ]
// : [];

// for (let item of profileArray) {
// if (item) {
// isFilled = true;
// } else {
// isFilled = false;
// break;
// }
// }
// }

useEffect(() => {
dispatch(refreshUser());
Expand Down
4 changes: 2 additions & 2 deletions src/components/PrivateRoute/PrivateRoute.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { useAuth } from '../../hooks/useAuth';

const PrivateRoute = ({ component: Component, redirectTo = '/signin' }) => {
const { isLoggedIn, isRefreshing } = useAuth();
const shouldRedirect = !isLoggedIn && !isRefreshing;
return shouldRedirect ? <Navigate to={redirectTo} /> : Component;
const shouldRedirect = !isLoggedIn ;
return shouldRedirect ? <Navigate to={redirectTo} replace /> : Component;
};

export default PrivateRoute;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import welcomeMobile2x from '../../assets/backgroundImages/welcome-mobile@2x.jpg
import signMobile from '../../assets/backgroundImages/sign-mobile.jpg';
import signMobile2x from '../../assets/backgroundImages/sign-mobile@2x.jpg';

const getBackgroundImage = (pathname, highResolution = false) => {
const getBackgroundImage = (pathname="", highResolution = false) => {
if (pathname.includes('/welcome')) {
return `url(${highResolution ? welcomeMobile2x : welcomeMobile})`;
} else if (pathname.includes('/signup') || pathname.includes('/signin')) {
Expand Down
8 changes: 8 additions & 0 deletions src/redux/auth/authSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ const authSlice = createSlice({
state.error = null;
})
// ---------------Log Out------------------
.addCase(logOutUser.pending, (state) => {
state.isLoggedIn = false;
state.isLoading = true;
state.authenticated = false;
state.userData = null;
state.token = null;
state.error = null;
})
.addCase(logOutUser.fulfilled, (state) => {
state.isLoggedIn = false;
state.isLoading = false;
Expand Down

0 comments on commit ff2d8e4

Please sign in to comment.