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,
|
loading: true,
|
||||||
completedSteps: completedSteps,
|
completedSteps: completedSteps,
|
||||||
islandMode: undefined,
|
islandMode: undefined,
|
||||||
noAuthLoginAttempted: undefined
|
|
||||||
};
|
};
|
||||||
this.interval = undefined;
|
this.interval = undefined;
|
||||||
this.setMode();
|
this.setMode();
|
||||||
|
@ -77,45 +76,44 @@ class AppComponent extends AuthComponent {
|
||||||
if (this.state.isLoggedIn === false) {
|
if (this.state.isLoggedIn === false) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.auth.loggedIn()
|
|
||||||
.then(res => {
|
|
||||||
if (this.state.isLoggedIn !== res) {
|
|
||||||
this.setState({
|
|
||||||
isLoggedIn: res
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!res) {
|
let res = this.auth.loggedIn();
|
||||||
this.auth.needsRegistration()
|
|
||||||
.then(result => {
|
|
||||||
this.setState({
|
|
||||||
needsRegistration: result
|
|
||||||
});
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (res) {
|
if (this.state.isLoggedIn !== res) {
|
||||||
this.setMode()
|
this.setState({
|
||||||
.then(() => {
|
isLoggedIn: res
|
||||||
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 (!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 = () => {
|
setMode = () => {
|
||||||
|
|
|
@ -48,12 +48,11 @@ class LoginPageComponent extends React.Component {
|
||||||
this.redirectToRegistration()
|
this.redirectToRegistration()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
this.auth.loggedIn()
|
|
||||||
.then(res => {
|
if (this.auth.loggedIn()) {
|
||||||
if (res) {
|
this.redirectToHome();
|
||||||
this.redirectToHome();
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
import decode from 'jwt-decode';
|
import decode from 'jwt-decode';
|
||||||
|
|
||||||
export default class AuthService {
|
export default class AuthService {
|
||||||
NO_AUTH_CREDS = '1234567890!@#$%^&*()_nothing_up_my_sleeve_1234567890!@#$%^&*()';
|
|
||||||
|
|
||||||
SECONDS_BEFORE_JWT_EXPIRES = 20;
|
SECONDS_BEFORE_JWT_EXPIRES = 20;
|
||||||
AUTHENTICATION_API_ENDPOINT = '/api/auth';
|
AUTHENTICATION_API_ENDPOINT = '/api/auth';
|
||||||
REGISTRATION_API_ENDPOINT = '/api/registration';
|
REGISTRATION_API_ENDPOINT = '/api/registration';
|
||||||
|
@ -16,7 +14,7 @@ export default class AuthService {
|
||||||
};
|
};
|
||||||
|
|
||||||
jwtHeader = () => {
|
jwtHeader = () => {
|
||||||
if (this._loggedIn()) {
|
if (this.loggedIn()) {
|
||||||
return 'Bearer ' + this._getToken();
|
return 'Bearer ' + this._getToken();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -68,7 +66,7 @@ export default class AuthService {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this._loggedIn()) {
|
if (this.loggedIn()) {
|
||||||
headers['Authorization'] = 'Bearer ' + this._getToken();
|
headers['Authorization'] = 'Bearer ' + this._getToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,19 +99,7 @@ export default class AuthService {
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
async loggedIn() {
|
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() {
|
|
||||||
const token = this._getToken();
|
const token = this._getToken();
|
||||||
return ((token !== null) && !this._isTokenExpired(token));
|
return ((token !== null) && !this._isTokenExpired(token));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue