Skip to content

Commit

Permalink
💫 feat: save token to local storage (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
nandiheath authored Mar 13, 2021
1 parent 0e344e7 commit eefeb7a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/components/templates/app/AuthApp.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { useAppState } from 'components/hooks/ReduxStateHook';
import { useAppState, useAuthState } from 'components/hooks/ReduxStateHook';
import FullPageLoading from 'components/molecules/FullPageLoading';
import AxiosInterceptor from 'libraries/axios';
import React, { useEffect } from 'react';
import { useDispatch } from 'react-redux';
import { doInitBackgroundLoad } from 'states/auth/actions';
import { useGRPCWrapper } from '../GRPCWrapper';
import { setAuthState } from '../../../libraries/localstorage';

/**
* Will check the token from local storage and check if the user is logged in.
Expand All @@ -14,12 +15,20 @@ export default ({ children }: React.PropsWithChildren<{}>) => {
const dispatch = useDispatch();
const grpcWrapper = useGRPCWrapper();
const { isInitialLoading } = useAppState();
const authState = useAuthState();

useEffect(() => {
// skip loading for maintenance mode
dispatch(doInitBackgroundLoad(grpcWrapper));
}, []);

// Store the authState once the token is updated
useEffect(() => {
if (authState.token) {
setAuthState(authState);
}
}, [authState.token]);

return isInitialLoading ? (
<FullPageLoading />
) : (
Expand Down

0 comments on commit eefeb7a

Please sign in to comment.