fix: introduce fix for token management
This commit is contained in:
@@ -15,7 +15,7 @@ function AccountDropdownMenu(props) {
|
||||
const navigate = useNavigate();
|
||||
const { open, onClose, anchorEl, id } = props;
|
||||
const logout = async () => {
|
||||
authentication.updateToken('');
|
||||
authentication.removeToken();
|
||||
await apolloClient.clearStore();
|
||||
onClose();
|
||||
navigate(URLS.LOGIN);
|
||||
|
@@ -22,7 +22,7 @@ function DeleteAccountDialog(props) {
|
||||
|
||||
const handleConfirm = React.useCallback(async () => {
|
||||
await deleteCurrentUser();
|
||||
authentication.updateToken('');
|
||||
authentication.removeToken();
|
||||
await apolloClient.clearStore();
|
||||
navigate(URLS.LOGIN);
|
||||
}, [deleteCurrentUser, currentUser]);
|
||||
|
@@ -12,17 +12,20 @@ import { LOGIN } from 'graphql/mutations/login';
|
||||
import Form from 'components/Form';
|
||||
import TextField from 'components/TextField';
|
||||
import useFormatMessage from 'hooks/useFormatMessage';
|
||||
|
||||
function LoginForm() {
|
||||
const isCloud = useCloud();
|
||||
const navigate = useNavigate();
|
||||
const formatMessage = useFormatMessage();
|
||||
const authentication = useAuthentication();
|
||||
const [login, { loading }] = useMutation(LOGIN);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (authentication.isAuthenticated) {
|
||||
navigate(URLS.DASHBOARD);
|
||||
}
|
||||
}, [authentication.isAuthenticated]);
|
||||
|
||||
const handleSubmit = async (values) => {
|
||||
const { data } = await login({
|
||||
variables: {
|
||||
@@ -32,6 +35,7 @@ function LoginForm() {
|
||||
const { token } = data.login;
|
||||
authentication.updateToken(token);
|
||||
};
|
||||
|
||||
return (
|
||||
<Paper sx={{ px: 2, py: 4 }}>
|
||||
<Typography
|
||||
@@ -107,4 +111,5 @@ function LoginForm() {
|
||||
</Paper>
|
||||
);
|
||||
}
|
||||
|
||||
export default LoginForm;
|
||||
|
@@ -25,27 +25,9 @@ const queryClient = new QueryClient({
|
||||
});
|
||||
|
||||
export default function AutomatischQueryClientProvider({ children }) {
|
||||
const { token, initialize } = useAuthentication();
|
||||
|
||||
React.useEffect(
|
||||
function updateTokenInHttpClient() {
|
||||
if (!initialize) return;
|
||||
|
||||
if (token) {
|
||||
api.defaults.headers.Authorization = token;
|
||||
} else {
|
||||
delete api.defaults.headers.Authorization;
|
||||
}
|
||||
|
||||
initialize();
|
||||
},
|
||||
[initialize, token],
|
||||
);
|
||||
|
||||
return (
|
||||
<QueryClientProvider client={queryClient}>
|
||||
{children}
|
||||
|
||||
<ReactQueryDevtools />
|
||||
</QueryClientProvider>
|
||||
);
|
||||
|
Reference in New Issue
Block a user