pl-fe: Invalidate router context on log out

Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
nicole mikołajczyk
2026-02-01 11:43:23 +01:00
parent 1b0e4a77e0
commit 99dfb7136a

View File

@ -1,3 +1,5 @@
import { router } from 'pl-fe/features/ui/router';
import { import {
AUTH_LOGGED_OUT, AUTH_LOGGED_OUT,
AUTH_ACCOUNT_REMEMBER_SUCCESS, AUTH_ACCOUNT_REMEMBER_SUCCESS,
@ -19,6 +21,7 @@ const initialState: Me = null;
const handleForbidden = (state: Me, error: { response: PlfeResponse }) => { const handleForbidden = (state: Me, error: { response: PlfeResponse }) => {
if (([401, 403] as any[]).includes(error.response?.status)) { if (([401, 403] as any[]).includes(error.response?.status)) {
router.invalidate();
return false; return false;
} else { } else {
return state; return state;
@ -29,12 +32,15 @@ const me = (state: Me = initialState, action: AuthAction | MeAction): Me => {
switch (action.type) { switch (action.type) {
case ME_FETCH_SUCCESS: case ME_FETCH_SUCCESS:
case ME_PATCH_SUCCESS: case ME_PATCH_SUCCESS:
router.invalidate();
return action.me.id; return action.me.id;
case VERIFY_CREDENTIALS_SUCCESS: case VERIFY_CREDENTIALS_SUCCESS:
case AUTH_ACCOUNT_REMEMBER_SUCCESS: case AUTH_ACCOUNT_REMEMBER_SUCCESS:
router.invalidate();
return state || action.account.id; return state || action.account.id;
case ME_FETCH_SKIP: case ME_FETCH_SKIP:
case AUTH_LOGGED_OUT: case AUTH_LOGGED_OUT:
router.invalidate();
return false; return false;
case ME_FETCH_FAIL: case ME_FETCH_FAIL:
return handleForbidden(state, action.error as any); return handleForbidden(state, action.error as any);