Update login flow

This commit is contained in:
jeffvli
2022-10-26 16:04:39 -07:00
parent 146a03cb3c
commit cf17ce6e9d
3 changed files with 14 additions and 23 deletions
+6 -17
View File
@@ -8,6 +8,7 @@ export interface AuthState {
currentServer?: Server;
permissions: {
isAdmin: boolean;
username: string;
};
refreshToken: string;
serverCredentials: {
@@ -37,10 +38,6 @@ export interface AuthSlice extends AuthState {
setCurrentServer: (server: Server) => void;
}
const persistedState = JSON.parse(
localStorage.getItem('authentication') || '{}'
);
export const useAuthStore = create<AuthSlice>()(
persist(
devtools(
@@ -92,12 +89,13 @@ export const useAuthStore = create<AuthSlice>()(
logout: () => {
return set({
accessToken: undefined,
permissions: { isAdmin: false },
permissions: { isAdmin: false, username: '' },
refreshToken: undefined,
});
},
permissions: {
isAdmin: false,
username: '',
},
refreshToken: '',
serverCredentials: [],
@@ -105,20 +103,11 @@ export const useAuthStore = create<AuthSlice>()(
serverPermissions: '',
serverUrl: '',
setCurrentServer: (server: Server) => {
const prev = JSON.parse(
localStorage.getItem('authentication') || '{}'
);
localStorage.setItem(
'authentication',
JSON.stringify({
...prev,
state: { ...prev.state, currentServer: server },
})
);
return set({ currentServer: server });
},
}))
})),
{ name: 'authentication' }
),
{ name: 'authentication' }
{ name: 'store_authentication' }
)
);