mirror of
https://github.com/henrywhitaker3/Speedtest-Tracker.git
synced 2025-12-21 21:33:08 +01:00
Removed auth
Doesn't really need user account, no sensitive data held in DB, plus routes that do stuff are rate limited anyway. Shouldn't be accessible to untrusted users (i.e. should be behind a RP that handles user auth)
This commit is contained in:
101
resources/js/index.js
vendored
101
resources/js/index.js
vendored
@@ -15,102 +15,25 @@ export default class Index extends Component {
|
||||
|
||||
this.state = {
|
||||
loading: true,
|
||||
redirectLogin: true,
|
||||
redirectHome: false,
|
||||
token: null,
|
||||
user: null,
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.lookForToken();
|
||||
}
|
||||
|
||||
lookForToken = () => {
|
||||
var token = JSON.parse(localStorage.getItem('token'));
|
||||
if(token == null) {
|
||||
this.setState({
|
||||
loading: false,
|
||||
});
|
||||
} else {
|
||||
this.tryToken(token)
|
||||
}
|
||||
}
|
||||
|
||||
setToken = (token) => {
|
||||
localStorage.setItem('token', JSON.stringify(token));
|
||||
this.setState({
|
||||
loading: true,
|
||||
token: token,
|
||||
});
|
||||
this.tryToken(token);
|
||||
}
|
||||
|
||||
tryToken = (token, reload = true) => {
|
||||
Axios.get('/api/auth/me?token=' + token.access_token)
|
||||
.then((resp) => {
|
||||
this.setState({
|
||||
user: resp.data,
|
||||
loading: false,
|
||||
redirectLogin: false,
|
||||
token: token
|
||||
});
|
||||
if(reload) {
|
||||
this.setState({
|
||||
redirectHome: true
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log('Invalid token');
|
||||
console.log(err);
|
||||
this.setState({
|
||||
redirectLogin: true
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
render() {
|
||||
var loading = this.state.loading;
|
||||
var redirectLogin = this.state.redirectLogin;
|
||||
var redirectHome = this.state.redirectHome;
|
||||
var user = this.state.user;
|
||||
var token = this.state.token;
|
||||
|
||||
return (
|
||||
<div>
|
||||
{loading ?
|
||||
<div>
|
||||
<Loader />
|
||||
</div>
|
||||
:
|
||||
<div>
|
||||
<BrowserRouter>
|
||||
<Route render={(props) => (<ToastContainer />)} />
|
||||
<Switch>
|
||||
<Route exact path="/" render={(props) => (
|
||||
<div>
|
||||
<HomePage user={user} token={token} />
|
||||
</div>
|
||||
)} />
|
||||
<Route exact path="/login" render={(props) => (
|
||||
<div>
|
||||
<Login setToken={this.setToken} />
|
||||
</div>
|
||||
)} />
|
||||
<Route exact path="/error/:code" render={(props) => ( <ErrorPage code={props.match.params.code} /> )} />
|
||||
<Route render={(props) => (<ErrorPage code="404" />)} />
|
||||
</Switch>
|
||||
{redirectLogin &&
|
||||
<Redirect to="/login"></Redirect>
|
||||
}
|
||||
{redirectHome &&
|
||||
<Redirect to="/"></Redirect>
|
||||
}
|
||||
</BrowserRouter>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<BrowserRouter>
|
||||
<Route render={(props) => (<ToastContainer />)} />
|
||||
<Switch>
|
||||
<Route exact path="/" render={(props) => (
|
||||
<div>
|
||||
<HomePage />
|
||||
</div>
|
||||
)} />
|
||||
<Route exact path="/error/:code" render={(props) => ( <ErrorPage code={props.match.params.code} /> )} />
|
||||
<Route render={(props) => (<ErrorPage code="404" />)} />
|
||||
</Switch>
|
||||
</BrowserRouter>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user