Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ft 166112943 admin can log into art #242

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"history": "^4.7.2",
"jest-enzyme": "^7.0.1",
"jest-mock": "^23.2.0",
"jsonwebtoken": "^8.2.2",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.10",
"moment": "^2.22.2",
"moxios": "^0.4.0",
Expand Down
13 changes: 3 additions & 10 deletions src/_components/RoutesComponent.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React, { Component } from 'react';
import { Route, Switch } from 'react-router-dom';
import jwt from 'jsonwebtoken';
import { get } from 'lodash';

import Authenticate from './AccessControl/AuthenticateComponent';
import AssetTypes from '../components/AssetTypes/AssetTypesComponent';
Expand Down Expand Up @@ -35,20 +33,15 @@ class RoutesComponent extends Component {
checkAuthentication = () => {
const token = localStorage.getItem('art-prod-web-token');

if (!token) {
return false;
}

const decodedToken = jwt.decode(token);

return get(decodedToken, 'admin', false);
return !!token;
};

render() {
return (
<div>
<Switch>
<Authenticate
exact
isAuthenticated={this.checkAuthentication()}
path="/dashboard"
component={Dashboard}
Expand Down Expand Up @@ -202,4 +195,4 @@ class RoutesComponent extends Component {
}
}

export default (RoutesComponent);
export default(RoutesComponent);
10 changes: 10 additions & 0 deletions src/components/LoginComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,22 @@ class LoginComponent extends React.Component {
if (validAndelaEmail(result.user.email)) {
result.user.getIdToken().then((idToken) => {
const decodedToken = jwt.decode(idToken);
const isAdmin = decodedToken.admin;

if (get(decodedToken, 'admin', false)) {
localStorage.setItem('art-prod-web-token', idToken);
setAuthorizationConfig();
}

/**
* This method is to ensure that a normal admin can log in
* As long as a user has an Admin property set to true they
* can log in
*/
if (isAdmin) {
localStorage.setItem('art-prod-web-token', idToken);
}

this.props.history.push('/dashboard');
});
} else {
Expand Down