ExpressOIDC Node to React API call

Hi,

I have a webapp with Node and React app. From Node, I have integrated ExpressOIDC with all the confg. Everything is working, getting the UserInfo and all the details. But when I try to make a fetch call(API call/ Ajax call) in REACT, I am getting userInfo undefined. But when I hit the API directly from Browser I am getting the userDetails.

What am I missing here?

Hi @ACe

Can you provide a snippet of code that you use in React to call userinfo?

Hi Dragos,

Here is the React Code:

function fetchuserInfo() {
return fetch(‘http://localhost:4000/userInfo’);
}

function* userSaga(action) {
try {
const response = yield call(fetchuserInfo);
} catch (error) {
console.log(“Error”, error);
}
}

Node js Code:

app.get(’/userInfo’, (req, res) => {
console.log(req.userContext);
console.log("Authenticated: ", req.isAuthenticated());
if (req.isAuthenticated()) {
res.send(req.userContext)
} else {
res.send(‘No User Info’)
}
});

req.userContext is always undefined, when I try to hit from REACT.

How should I need to Authenticate the Request coming from React app?

Should I need to use @okta/jwt-verifier > validate through token?

Hi @ACe

Based on the code provided, it seems that fetchuserInfo() does not resolve the fetch() promise.

Regarding authenticating the request, yes, you can use @okta/jwt-verifier in order to verify the bearer token locally and allow the user to access the resources requested.

Thanks, for the feedback.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.