Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
How can I get logged in user id inside react js?
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?
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/...
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/...
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™