Skip to content

Commit

Permalink
Merge pull request #441 from glific/logout-cleanup
Browse files Browse the repository at this point in the history
logout component clean up
  • Loading branch information
DigneshGujarathi authored Sep 7, 2020
2 parents 2ed1bdd + c8be4e1 commit 9945bdb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
5 changes: 3 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ import { Collection } from './containers/Collection/Collection';
import { GroupList } from './containers/Group/GroupList/GroupList';
import { GroupContact } from './containers/Group/GroupContact/GroupContact';
import { Group } from './containers/Group/Group';
import { LogoutService, checkAuthStatusService } from './services/AuthService';
import { checkAuthStatusService } from './services/AuthService';
import { FlowEditorContainer } from './components/floweditor/FlowEditorContainer/FlowEditorContainer';
import { ContactProfile } from './containers/Profile/Contact/ContactProfile';
import { OrganisationSettings } from './containers/OrganisationSettings/OrganisationSettings';
import { UserProfile } from './containers/Profile/User/UserProfile';
import { MyAccount } from './containers/MyAccount/MyAccount';
import { BlockContactList } from './containers/BlockContact/BlockContactList/BlockContactList';
import { Logout } from './containers/Auth/Logout/Logout';

const App = () => {
const [authenticated, setAuthenticated] = useState(true);
Expand Down Expand Up @@ -93,7 +94,7 @@ const App = () => {
<Route path="/settings" exact component={OrganisationSettings} />
<Route path="/blocked-contacts" exact component={BlockContactList} />

<Route path="/logout" exact component={LogoutService} />
<Route path="/logout" exact component={Logout} />

<Route
exact
Expand Down
10 changes: 10 additions & 0 deletions src/containers/Auth/Logout/Logout.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import { render } from '@testing-library/react';

import { Logout } from './Logout';

describe('<Logout />', () => {
test('it should mount', () => {
render(<Logout />);
});
});
12 changes: 12 additions & 0 deletions src/containers/Auth/Logout/Logout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React, { useContext } from 'react';

import { SessionContext } from '../../../context/session';

export interface LogoutProps {}

export const Logout: React.SFC<LogoutProps> = () => {
const { setAuthenticated } = useContext(SessionContext);
localStorage.removeItem('glific_session');
setAuthenticated(false);
return null;
};
11 changes: 0 additions & 11 deletions src/services/AuthService.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
import React, { useContext } from 'react';
import axios from 'axios';

import { SessionContext } from '../context/session';
import { RENEW_TOKEN, REACT_APP_GLIFIC_AUTHENTICATION_API } from '../common/constants';

export interface LogoutServiceProps {}

export const LogoutService: React.SFC<LogoutServiceProps> = () => {
const { setAuthenticated } = useContext(SessionContext);
localStorage.removeItem('glific_session');
setAuthenticated(false);
return null;
};

export const renewAuthToken = () => {
const session = localStorage.getItem('glific_session');
// if session object does not exist then just return false
Expand Down

0 comments on commit 9945bdb

Please sign in to comment.