Message Boards
How to pass the user information from the portal to the React application?
How to pass the user information from the portal to the React application?
Junior Member Posts: 50 Join Date: 4/24/15 Recent PostsWe have a separate application built using React. This application is deployed as a widget on the Liferay server. We are creating the users in the Liferay platform. How can we pass the user information to the React application?
RE: How to pass the user information from the portal to the React applicati
Junior Member Posts: 50 Join Date: 4/24/15 Recent PostsCan anyone tell me if we can pass the user credentials from the Liferay to the React application running as a widget in the Liferay platform.
If we cannot and there is no workaround, then I have to change my functional requirements.
RE: How to pass the user information from the portal to the React applicati
Liferay Legend Posts: 1554 Join Date: 9/24/09 Recent PostsYou have multiple options. If you have a portlet or a fragment that contains your React app, you can insert the information there. Store it in a data attribute, in a global variable, ...
I usually fetch all relevant information through rest calls. If you just need the username or something like that (I believe, the username is also available in the Liferay JS object), it is a bit overkill. But since javascript apps usually need more data and need to communicate with the backend anyway, it usually pays off.
You can either create a simple rest service using the rest template in the IDE (note: You can find a lot of info here in the forum about authentication and the necessary annotations), try the rest builder and for some applications the /api/jsonws services could even be sufficient.
RE: RE: How to pass the user information from the portal to the React appli
Junior Member Posts: 50 Join Date: 4/24/15 Recent PostsThanks. I will check the documentation
RE: How to pass the user information from the portal to the React applicati
New Member Posts: 14 Join Date: 3/29/12 Recent PostsWhat do you need the user credentials for? Generally you would need the credentials to make authenticated requests to Liferay services. If that's the case you can use the `Liferay.Service` function available via JavaScript to handle the authenticated request. When a user is logged in `Liferay.Service` has access to the users credentials and automatically passes this with the request. Is this what you are looking for, or do you need something else?
RE: RE: How to pass the user information from the portal to the React appli
Junior Member Posts: 50 Join Date: 4/24/15 Recent PostsI would like to have the user credentials in the React application to display certain features based on the user login.