user3892254 user3892254 - 5 months ago 114
Node.js Question

Access LocalStorage value in ejs file

I am trying to conditionally display some html where I want to check the value passed from my server, against my local storage value. I can't figure out how to get access to this local storage value.



<% for(var i=0; i < list.length; i++) { %>
<%
checkUser = function(passed_in_UID) {
return(passed_in_UID == localStorage.getItem("UID"));
};
%>
<% if(checkUser(list[i].val().UID)) { %>
<p>Show this tag if conditional true</p>
<% } %>
<% } %>





I keep getting internal 500 error because I guess localStorage isn't valid in ejs. How do I grab this value then?

Answer Source

Local Storage is browser specific. EJS runs on the server side (server side rendering), therefor local storage is not accessible from your server. You could use some form of database to store non secret data and use EJS on your server side. But unless somehow you share the data between the two server data is separate from client data.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download