Add back persisted state

This commit is contained in:
Valtteri Karesto
2021-11-19 16:27:48 +02:00
parent d79d013238
commit 19741add40
2 changed files with 12 additions and 12 deletions

View File

@@ -5,7 +5,6 @@ import { getToken } from "next-auth/jwt"
export default function middleware(req: NextRequest, ev: NextFetchEvent) {
if (req.nextUrl.pathname === "/") {
console.log('kissa', ev);
return Response.redirect("/develop");
}

View File

@@ -40,17 +40,18 @@ let initialState = {
}
}
// if (typeof window !== 'undefined') {
// try {
// localStorageState = localStorage.getItem('hooksIdeState');
// } catch (err) {
// console.log(`localStorage state broken`);
// localStorage.removeItem('hooksIdeState');
// }
// }
// if (localStorageState) {
// initialState = JSON.parse(localStorageState);
// }
// Check if there's a persited state in localStorage
if (typeof window !== 'undefined') {
try {
localStorageState = localStorage.getItem('hooksIdeState');
} catch (err) {
console.log(`localStorage state broken`);
localStorage.removeItem('hooksIdeState');
}
}
if (localStorageState) {
initialState = JSON.parse(localStorageState);
}
// Initialize state
export const state = proxy<IState>(initialState);