Skip to content

Commit

Permalink
Posible solución a pantalla en blanco
Browse files Browse the repository at this point in the history
  • Loading branch information
samuop committed Sep 26, 2024
1 parent fd97683 commit aac02cd
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions FrontAdmin/src/Context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const AuthProvider = ({ children }: { children: ReactNode }) => {
console.log('Token refreshed');
const data = await response.json();
console.log(data);
Cookies.set('access_token', data.access);
Cookies.set('tokennn', data.access);
Cookies.set('refresh_token', data.refresh);
Cookies.set('access_expiration', data.access_expiration);
Cookies.set('refresh_expiration', data.refresh_expiration);
Expand Down Expand Up @@ -67,22 +67,40 @@ const AuthProvider = ({ children }: { children: ReactNode }) => {
await FetchLogin(password, account);
setRolUser(JSON.parse(localStorage.getItem('userRol') || '[]'));
setIsAuthenticated(true);

const accessExpiration = Cookies.get('access_expiration');
if (accessExpiration) {
TokenRefresh(accessExpiration);
}
};

const onLogout = () => {
Cookies.remove('access_token');
Cookies.remove('refresh_token');
Cookies.remove('access_expiration');
Cookies.remove('refresh_expiration');
Cookies.remove('username');
Cookies.remove('dni');
localStorage.removeItem('userRol');
console.log('logout');

// Verificar y eliminar cookies
const cookiesToRemove = [
'tokennn',
'refresh_token',
'access_expiration',
'refresh_expiration',
'username',
'dni'
];

cookiesToRemove.forEach(cookie => {
if (Cookies.get(cookie)) {
Cookies.remove(cookie, { path: '/', domain: window.location.hostname });
console.log(`Cookie ${cookie} eliminada`);
} else {
console.log(`Cookie ${cookie} no encontrada`);
}
});

// Eliminar item de localStorage
localStorage.removeItem('userRol');
setIsAuthenticated(false);

// Limpiar timeout de refresh
if (refreshTimeout) {
clearTimeout(refreshTimeout);
}
Expand Down

0 comments on commit aac02cd

Please sign in to comment.