Added profile data but clears after refresh
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
// utils/localStorageHandler.js
|
||||
import { getCookie, deleteCookie } from "cookies-next";
|
||||
|
||||
const handleLocalStorageChanges = () => {
|
||||
const storedUserProfile = localStorage.getItem('cmc-profile');
|
||||
const storedToken = getCookie('cmc-token');
|
||||
|
||||
window.onstorage = (e) => {
|
||||
if (e.key === 'userProfile' && e.newValue !== storedUserProfile) {
|
||||
// User profile data in 'localStorage' has changed
|
||||
|
||||
// Delete the 'userProfile' from 'localStorage'
|
||||
localStorage.removeItem("cmc-profile");
|
||||
|
||||
// Delete the 'cmc-token' cookie
|
||||
deleteCookie('cmc-token');
|
||||
|
||||
// Redirect to the login page
|
||||
window.location.href = '/auth/login';
|
||||
|
||||
// Reload the page
|
||||
window.location.reload();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export default handleLocalStorageChanges;
|
||||
Reference in New Issue
Block a user