Merge pull request #10 from jamitz440/fix/fodler-tree-initial-render

Refactor imports and add auth clearAll
This commit is contained in:
jamitz440 2025-12-13 21:26:54 +00:00 committed by GitHub
commit c4b47f05ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 28 additions and 5 deletions

View file

@ -1,4 +1,4 @@
import React, { useState, useRef, useEffect, SetStateAction } from "react";
import React, { useState, useRef, useEffect } from "react";
// @ts-ignore
import FolderIcon from "@/assets/fontawesome/svg/folder.svg?react";

View file

@ -1,11 +1,13 @@
import { create } from "zustand";
import { persist } from "zustand/middleware";
import { useNoteStore } from "./notesStore";
import {
deriveKey,
generateMasterKey,
unwrapMasterKey,
wrapMasterKey,
} from "../api/encryption";
import { FolderTree } from "@/pages/Home/components/sidebar/subcomponents/FolderTree";
interface User {
id: number;
@ -30,6 +32,7 @@ interface AuthState {
logout: () => Promise<void>;
checkAuth: () => Promise<void>;
initEncryptionKey: (password: string, salt: string) => Promise<void>;
clearAll: () => void;
}
const API_URL = "http://localhost:8000/api";
@ -115,9 +118,10 @@ export const useAuthStore = create<AuthState>()(
set({
user: null,
encryptionKey: null, // Wipe from memory
encryptionKey: null,
isAuthenticated: false,
});
get().clearAll();
},
checkAuth: async () => {
@ -137,6 +141,22 @@ export const useAuthStore = create<AuthState>()(
get().logout();
}
},
clearAll: () => {
set({
user: null,
encryptionKey: null,
isAuthenticated: false,
rememberMe: false,
});
localStorage.clear();
useNoteStore.setState({
folderTree: null,
selectedFolder: null,
selectedNote: null,
});
},
}),
{
name: "auth-storage",
@ -149,3 +169,6 @@ export const useAuthStore = create<AuthState>()(
},
),
);
if (typeof window !== "undefined") {
(window as any).useAuthStore = useAuthStore;
}

View file

@ -36,15 +36,15 @@ const updateFolder = (
id: number,
folder: FolderTreeNode,
newFolder: FolderUpdate,
) => {
): FolderTreeNode => {
if (folder.id === id) {
return { ...folder, ...newFolder };
}
if (folder.children) {
return {
...folder,
children: folder.children.map((folder) =>
updateFolder(id, folder, newFolder),
children: folder.children.map((child) =>
updateFolder(id, child, newFolder),
),
};
}