Login endpoint now returns the user profile.

This commit is contained in:
2022-04-06 22:53:20 -05:00
parent f98b003808
commit b575fc7fde
8 changed files with 51 additions and 30 deletions

View File

@@ -1,30 +1,34 @@
import React from "react";
import { Navigate } from "react-router-dom";
import { globalContext } from "../context";
import context from "../globals";
import { apiClient } from "../utils/httpClients";
export default class AuthenticationGuard extends React.Component {
constructor(props) {
super(props);
}
static contextType = context;
async componentDidMount() {
if (!this.context.user) {
let userDataResponse = await apiClient.get("/user/");
if (userDataResponse.status === 200) {
this.context.user = userDataResponse.data;
this.context.setUser(userDataResponse.data);
}
}
}
static contextType = globalContext;
render() {
if (!this.context.user) {
return (
<Navigate to="/signup" replace="true" />
);
}
return;
return (
<context.Consumer>
{val => {
if (!val.user) {
console.log(val);
return <Navigate to="/signup" replace="true" />;
}
}}
</context.Consumer>
);
}
}