add logout button

This commit is contained in:
jeffvli
2026-07-18 21:31:47 -07:00
parent d960603268
commit a51299e818
4 changed files with 67 additions and 11 deletions
+18
View File
@@ -12,6 +12,7 @@ export interface AuthSlice extends AuthState {
addServer: (args: ServerListItemWithCredential) => void;
deleteServer: (id: string) => void;
getServer: (id: string) => null | ServerListItemWithCredential;
logout: () => void;
setCurrentServer: (server: null | ServerListItemWithCredential) => void;
setMusicFolderId: (musicFolderId: string[] | undefined) => void;
updateServer: (id: string, args: Partial<ServerListItemWithCredential>) => void;
@@ -48,6 +49,23 @@ export const useAuthStore = createWithEqualityFn<AuthSlice>()(
if (server) return server;
return null;
},
logout: () => {
set((state) => {
const currentServer = state.currentServer;
if (!currentServer) {
return;
}
const server = state.serverList[currentServer.id];
if (server) {
server.credential = '';
server.ndCredential = undefined;
server.savePassword = false;
}
state.currentServer = null;
});
},
setCurrentServer: (server) => {
set((state) => {
state.currentServer = server;