Skip to content

Commit e1e1df9

Browse files
committed
Refactored the authentication logic
1 parent 586bccd commit e1e1df9

File tree

1 file changed

+61
-58
lines changed

1 file changed

+61
-58
lines changed

src/containers/Full/Full.js

Lines changed: 61 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ class Full extends Component {
3535
'drivemotors.auth0.com',{
3636
theme:{
3737
logo: 'https://www.drivemotors.com/assets/logos/drive_logo_march_14.svg'
38-
}
39-
38+
},
39+
allowSignUp: false,
40+
allowedConnections: ['Username-Password-Authentication']
4041
}
4142
);
4243
this.lock.on("authenticated", function(authResult) {
@@ -51,6 +52,7 @@ class Full extends Component {
5152
return;
5253
}
5354
console.log(authResult);
55+
console.log(profile);
5456
localStorage.setItem('accessToken', authResult.accessToken);
5557
localStorage.setItem('profile', JSON.stringify(profile));
5658

@@ -69,63 +71,64 @@ class Full extends Component {
6971
const { isAuthenticated } = this.props.auth;
7072
console.log('render');
7173
console.log(this.props.auth.isAuthenticated());
72-
return (<div className="container">
73-
{
74-
isAuthenticated() && (
75-
<div className="app">
76-
<AppHeader fixed>
77-
<FullHeader auth={this.props.auth} />
78-
</AppHeader>
79-
<div className="app-body">
80-
<AppSidebar fixed display="lg">
81-
<AppSidebarHeader />
82-
<AppSidebarForm />
83-
<AppSidebarNav navConfig={navigation} {...this.props} />
84-
<AppSidebarFooter />
85-
<AppSidebarMinimizer />
86-
</AppSidebar>
87-
<main className="main">
88-
<AppBreadcrumb appRoutes={routes}/>
89-
<Container fluid>
90-
<Switch>
91-
{routes.map((route, idx) => {
92-
return route.component ? (<Route key={idx} path={route.path} exact={route.exact} name={route.name} render={props => (
93-
<route.component {...props} />
94-
)} />)
95-
: (null);
96-
},
97-
)}
98-
<Redirect from="/" to="/dashboard" />
99-
</Switch>
100-
</Container>
101-
</main>
102-
<AppAside fixed hidden>
103-
<FullAside />
104-
</AppAside>
105-
</div>
106-
<AppFooter>
107-
<FullFooter />
108-
</AppFooter>
74+
let displayHtml = null;
75+
if (isAuthenticated()){
76+
displayHtml = (<div>
77+
<div className="app">
78+
<AppHeader fixed>
79+
<FullHeader auth={this.props.auth} />
80+
</AppHeader>
81+
<div className="app-body">
82+
<AppSidebar fixed display="lg">
83+
<AppSidebarHeader />
84+
<AppSidebarForm />
85+
<AppSidebarNav navConfig={navigation} {...this.props} />
86+
<AppSidebarFooter />
87+
<AppSidebarMinimizer />
88+
</AppSidebar>
89+
<main className="main">
90+
<AppBreadcrumb appRoutes={routes}/>
91+
<Container fluid>
92+
<Switch>
93+
{routes.map((route, idx) => {
94+
return route.component ? (<Route key={idx} path={route.path} exact={route.exact} name={route.name} render={props => (
95+
<route.component {...props} />
96+
)} />)
97+
: (null);
98+
},
99+
)}
100+
<Redirect from="/" to="/dashboard" />
101+
</Switch>
102+
</Container>
103+
</main>
104+
<AppAside fixed hidden>
105+
<FullAside />
106+
</AppAside>
109107
</div>
110-
)
111-
}
112-
{
113-
!isAuthenticated() && (
114-
<h4>
115-
You are not logged in! Please{' '}
116-
<a
117-
style={{ cursor: 'pointer' }}
118-
// onClick={this.login.bind(this)
119-
onClick={this.login.bind(this)}
120-
>
121-
Log In
122-
</a>
123-
{' '}to continue.
124-
</h4>
125-
)
126-
}
127-
</div>
128-
);
108+
<AppFooter>
109+
<FullFooter />
110+
</AppFooter>
111+
</div>
112+
</div>
113+
);
114+
} else {
115+
displayHtml = (
116+
<div className="container">
117+
<h4>
118+
You are not logged in! Please{' '}
119+
<a
120+
style={{ cursor: 'pointer' }}
121+
// onClick={this.login.bind(this)
122+
onClick={this.login.bind(this)}
123+
>
124+
Log In
125+
</a>
126+
{' '}to continue.
127+
</h4>
128+
</div>
129+
)
130+
}
131+
return displayHtml;
129132
}
130133
}
131134

0 commit comments

Comments
 (0)