forked from p15670423/monkey
cc: Remove authentication code related to standard environment
This commit is contained in:
parent
8ef07bdca0
commit
ffd421bed6
|
@ -67,7 +67,6 @@ class AppComponent extends AuthComponent {
|
|||
loading: true,
|
||||
completedSteps: completedSteps,
|
||||
islandMode: undefined,
|
||||
noAuthLoginAttempted: undefined
|
||||
};
|
||||
this.interval = undefined;
|
||||
this.setMode();
|
||||
|
@ -77,45 +76,44 @@ class AppComponent extends AuthComponent {
|
|||
if (this.state.isLoggedIn === false) {
|
||||
return
|
||||
}
|
||||
this.auth.loggedIn()
|
||||
.then(res => {
|
||||
if (this.state.isLoggedIn !== res) {
|
||||
this.setState({
|
||||
isLoggedIn: res
|
||||
});
|
||||
}
|
||||
|
||||
if (!res) {
|
||||
this.auth.needsRegistration()
|
||||
.then(result => {
|
||||
this.setState({
|
||||
needsRegistration: result
|
||||
});
|
||||
})
|
||||
}
|
||||
let res = this.auth.loggedIn();
|
||||
|
||||
if (res) {
|
||||
this.setMode()
|
||||
.then(() => {
|
||||
if (this.state.islandMode === null) {
|
||||
return
|
||||
}
|
||||
this.authFetch('/api')
|
||||
.then(res => res.json())
|
||||
.then(res => {
|
||||
let completedSteps = CompletedSteps.buildFromResponse(res.completed_steps);
|
||||
// This check is used to prevent unnecessary re-rendering
|
||||
if (_.isEqual(this.state.completedSteps, completedSteps)) {
|
||||
return;
|
||||
}
|
||||
this.setState({completedSteps: completedSteps});
|
||||
this.showInfectionDoneNotification();
|
||||
});
|
||||
}
|
||||
)
|
||||
|
||||
}
|
||||
if (this.state.isLoggedIn !== res) {
|
||||
this.setState({
|
||||
isLoggedIn: res
|
||||
});
|
||||
}
|
||||
|
||||
if (!res) {
|
||||
this.auth.needsRegistration()
|
||||
.then(result => {
|
||||
this.setState({
|
||||
needsRegistration: result
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
if (res) {
|
||||
this.setMode()
|
||||
.then(() => {
|
||||
if (this.state.islandMode === null) {
|
||||
return
|
||||
}
|
||||
this.authFetch('/api')
|
||||
.then(res => res.json())
|
||||
.then(res => {
|
||||
let completedSteps = CompletedSteps.buildFromResponse(res.completed_steps);
|
||||
// This check is used to prevent unnecessary re-rendering
|
||||
if (_.isEqual(this.state.completedSteps, completedSteps)) {
|
||||
return;
|
||||
}
|
||||
this.setState({completedSteps: completedSteps});
|
||||
this.showInfectionDoneNotification();
|
||||
});
|
||||
}
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
setMode = () => {
|
||||
|
|
|
@ -48,12 +48,11 @@ class LoginPageComponent extends React.Component {
|
|||
this.redirectToRegistration()
|
||||
}
|
||||
})
|
||||
this.auth.loggedIn()
|
||||
.then(res => {
|
||||
if (res) {
|
||||
this.redirectToHome();
|
||||
}
|
||||
});
|
||||
|
||||
if (this.auth.loggedIn()) {
|
||||
this.redirectToHome();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
render() {
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
import decode from 'jwt-decode';
|
||||
|
||||
export default class AuthService {
|
||||
NO_AUTH_CREDS = '1234567890!@#$%^&*()_nothing_up_my_sleeve_1234567890!@#$%^&*()';
|
||||
|
||||
SECONDS_BEFORE_JWT_EXPIRES = 20;
|
||||
AUTHENTICATION_API_ENDPOINT = '/api/auth';
|
||||
REGISTRATION_API_ENDPOINT = '/api/registration';
|
||||
|
@ -16,7 +14,7 @@ export default class AuthService {
|
|||
};
|
||||
|
||||
jwtHeader = () => {
|
||||
if (this._loggedIn()) {
|
||||
if (this.loggedIn()) {
|
||||
return 'Bearer ' + this._getToken();
|
||||
}
|
||||
};
|
||||
|
@ -68,7 +66,7 @@ export default class AuthService {
|
|||
'Content-Type': 'application/json'
|
||||
};
|
||||
|
||||
if (this._loggedIn()) {
|
||||
if (this.loggedIn()) {
|
||||
headers['Authorization'] = 'Bearer ' + this._getToken();
|
||||
}
|
||||
|
||||
|
@ -101,19 +99,7 @@ export default class AuthService {
|
|||
})
|
||||
};
|
||||
|
||||
async loggedIn() {
|
||||
let token = this._getToken();
|
||||
if ((token === null) || (this._isTokenExpired(token))) {
|
||||
await this.attemptNoAuthLogin();
|
||||
}
|
||||
return this._loggedIn();
|
||||
}
|
||||
|
||||
attemptNoAuthLogin() {
|
||||
return this._login(this.NO_AUTH_CREDS, this.NO_AUTH_CREDS);
|
||||
}
|
||||
|
||||
_loggedIn() {
|
||||
loggedIn() {
|
||||
const token = this._getToken();
|
||||
return ((token !== null) && !this._isTokenExpired(token));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue