Fakultas Ilmu Komputer UI

Commit 440a3b36 authored by Zamil Majdy's avatar Zamil Majdy
Browse files

[#140654507] #10 Fix login logic

parent 4855d770
......@@ -7,7 +7,6 @@ import Login from './Login';
import VacancyPage from './VacancyPage';
import CompanyRegister from './CompanyRegister';
import Server from './lib/Server';
// import Register from './CompanyRegister'
export const Profile = () => (
<Segment>
......@@ -22,12 +21,17 @@ export default class App extends React.Component {
super(props);
/* istanbul ignore next */
this.handleAuth = this.handleAuth.bind(this);
this.handleHome = this.handleHome.bind(this);
}
handleAuth = (nextState, replace) => (
Server.isLoggedIn() || replace({ pathname: '/login' })
);
handleHome= (nextState, replace) => (
Server.isLoggedIn() ? replace({ pathname: '/lowongan' }) : replace({ pathname: '/login' })
);
render = () => (
<Router history={browserHistory}>
......@@ -39,7 +43,8 @@ export default class App extends React.Component {
<Route path="/lowongan" component={VacancyPage} />
<Route path="/users" component={Profile} />
</Route>
<Redirect from="*" to={Server.isLoggedIn() ? '/lowongan' : '/login'} />
<Route path="/home" onEnter={this.handleHome} />
<Redirect from="*" to="/home" />
</Router>
);
}
......
......@@ -26,10 +26,7 @@ export default class TopMenu extends React.Component {
<Menu.Menu position="right">
<Menu.Item as={Link} to="/lowongan" name="home" onClick={this.handleItemClick} />
<Menu.Item as={Link} to="/profile" name="profil" onClick={this.handleItemClick} />
{Server.isLoggedIn() ?
<Menu.Item as={Link} onClick={this.logout} name="logout" /> :
<Menu.Item as={Link} to="/login" name="login" />
}
<Menu.Item as={Link} onClick={this.logout} name="logout" />
</Menu.Menu>
</Menu>
);
......
......@@ -44,7 +44,7 @@ export default class Server {
if (response.status === 204) {
return response;
}
return response;
return response.hasOwnProperty(response) ? response.json() : response;
});
/* istanbul ignore next */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment