Skip to content

Commit

Permalink
fix: clear user settings after signout (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
alarv authored Dec 2, 2024
1 parent 7787705 commit 582b6e1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/app/dashboard/components/UserAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export default function UserAvatar({ session }: { session: Session | null }) {
const updateUserSettings = useUserSettingsStore(
(state) => state.updateUserSettings,
);
const clearUserSettings = useUserSettingsStore(
(state) => state.clearUserSettings,
);
const unauthenticatedMenuItems: MenuItem[] = [
{
key: 'signin',
Expand Down Expand Up @@ -58,7 +61,7 @@ export default function UserAvatar({ session }: { session: Session | null }) {
key: 'signout',
onPress: async () => {
await signOut();
updateUserSettings({}, false);
clearUserSettings();
const logoutUrl = new URL(
`${process.env.NEXT_PUBLIC_AUTH_KEYCLOAK_ISSUER}/protocol/openid-connect/logout`,
);
Expand Down
5 changes: 4 additions & 1 deletion src/app/stores/userSettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { devtools, persist } from 'zustand/middleware';
import type {} from '@redux-devtools/extension';
import { UserSettingsDto } from '@/app/api.types'; // required for devtools typing
import { logger } from '@/logger';
import toast from 'react-hot-toast';

const log = logger.child({ module: 'error' });

Expand All @@ -13,6 +12,7 @@ interface UserSettingsState {
updatedSettings: Partial<UserSettingsDto>,
persist?: boolean,
) => void;
clearUserSettings: () => void;
}

export const useUserSettingsStore = create<UserSettingsState>()(
Expand Down Expand Up @@ -52,6 +52,9 @@ export const useUserSettingsStore = create<UserSettingsState>()(
}));
}
},
clearUserSettings: () => {
set({ userSettings: {} });
},
}),
{
name: 'user-settings-storage',
Expand Down

0 comments on commit 582b6e1

Please sign in to comment.