Login endpoint now returns the user profile.
This commit is contained in:
@@ -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>
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user