Reputation: 223
I am using a passport for authenticating the user. After successful authentication, I would like to show the username and id in one of the react components for now. There could be more places where I need to access user information in the future.
How should I accessing user profile information in independent react components?
I tried storing the user information in a cookie. Accessing the cookie in every component seems to be messy.
app.post('/login/callback', auth.authenticate('saml', { failureRedirect: '/', failureFlash: true }), function (req, res) {
// stores the cookie information
res.cookie('cookie1', req.user.id, { secure: true, signed: true, expires: new Date(Date.now() + 3600) });
res.redirect('/');
}
);
I would like to access the user principal globally across all the react components.
Upvotes: 10
Views: 17935
Reputation: 1225
There are multiple options for Global State management.
Upvotes: 12