RE: How can I get logged in user id inside react js?

Jeff Fabiny, modified 6 Years ago. New Member Posts: 4 Join Date: 7/9/19 Recent Posts
Specifically, how can I get a logged in user ID inside the componentDidMount() function? In the init.jsp, it looks like I can do something like <%=user.getUserId()%>, but is there a way to pass this into the react function?
thumbnail
Christoph Rabel, modified 6 Years ago. Liferay Legend Posts: 1555 Join Date: 9/24/09 Recent Posts
Well, there are multiple options.
1) You could call: Liferay.ThemeDisplay.getUserId();
2) You write it in a javascript variable in your JSP
3) You use a rest call to provide you with data like the userId and further infos
We usually don't care about the userId in our js application at all. We let the backend handle the user. We just use restcalls and the backend determines the user and returns ok/not allowed/need authentication/...