feat: Implement the /user/me endpoint
This commit is contained in:
1
frontend/index.html
Normal file
1
frontend/index.html
Normal file
@@ -0,0 +1 @@
|
||||
<!DOCTYPE html><html> <head> <title>Lateinicus</title> <meta charset="UTF-8"> <meta name="viewport" content="minimum-scale=1, initial-scale=1, width=device-width, shrink-to-fit=no"> <link rel="stylesheet" href="/app/src.33f51c10.css"> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500"> <script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin=""></script> <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin=""></script> </head> <body> <div id="app"></div> <script src="/app/src.02f6e325.js"></script> </body> </html>
|
||||
6
frontend/shit.sh
Normal file
6
frontend/shit.sh
Normal file
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
rm -rf dist/
|
||||
|
||||
./node_modules/.bin/parcel build --out-dir dist/app src/index.html
|
||||
chmod 705 dist dist/app
|
||||
chmod 604 dist/app/*
|
||||
@@ -36,15 +36,37 @@ interface IProps {
|
||||
// TODO: Replace the sessionStorage with localStorage?
|
||||
export default class Application extends React.Component<IProps> {
|
||||
componentDidMount() {
|
||||
// TODO: Ask the server if our session is still valid
|
||||
// TODO: When asking the server if our session is still valid, a spinner
|
||||
// should be shown
|
||||
if (getSessionToken(window) !== null) {
|
||||
// TODO: We still need to fetch the user data
|
||||
this.props.setAuthenticated(true);
|
||||
const token = getSessionToken(window);
|
||||
if (token !== null && !this.props.authenticated) {
|
||||
this.checkAuthStatus(token).then(user => {
|
||||
this.props.setUser(user);
|
||||
this.props.setAuthenticated(true);
|
||||
}).catch(err => {
|
||||
this.props.setAuthenticated(false);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
checkAuthStatus = (token: string): Promise<IUser> => {
|
||||
return new Promise((res, rej) => {
|
||||
fetch(`${BACKEND_URL}/api/user/me`, {
|
||||
headers: new Headers({
|
||||
"Content-Type": "application/json",
|
||||
"Token": token,
|
||||
}),
|
||||
}).then(resp => resp.json(), err => rej(err))
|
||||
.then(data => {
|
||||
if (data.error === "0") {
|
||||
res(data.data);
|
||||
} else {
|
||||
rej(data);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getLevels = (): Promise<ILevel[]> => {
|
||||
return new Promise((res, rej) => {
|
||||
fetch(`${BACKEND_URL}/api/levels`, {
|
||||
|
||||
@@ -68,7 +68,6 @@ const initialState: IState = {
|
||||
didLogin: false,
|
||||
|
||||
// Is the user authenticated?
|
||||
// TODO: Set this to false
|
||||
authenticated: false,
|
||||
|
||||
user: {
|
||||
|
||||
Reference in New Issue
Block a user