I am currently creating a log in page that makes a POST request to an API when the user enters their details (A Post request containing the users details will be sent to the server). If this request is successful (Server responds with status 200 and sends back an access token giving the user access to the full API) the user should be routed towards another page. Below you can see the code that deals with the API call and then what should be done when the server response status is 200:
api.authorise(email, password, appid).then((result) => {
if (result.status === 200) {
console.log("Auth Successful");
successfulAuth = true;
<ProjectSelect api={api} data={response.data} />;
return result;
} else {
console.log("Auth Failed")
return result;
}
As you can see above, if the user credentials are valid, I want the user to be routed to the 'ProjectSelect' page with the relevant props. However, with the current code, after the user has successfully logged in nothing changes. I have tried using 'useNavigate' like this:
const nav = useNavigate()
api.authorise(email, password, appid).then((result) => {
if (result.status === 200) {
console.log("Auth Successful");
successfulAuth = true;
nav("/projectselect");
return result;
} else {
console.log("Auth Failed")
return result;
}
But then I cannot pass the 'api' and 'data' props to the 'ProjectSelect' component. I would like to know why the call to the project select component is not working or a better solution to this problem. Thanks in advance.