Here is the code in my base.html header
<script>
var auth_status = "{{ user.is_authenticated }}"
</script>
{% block scripts %} {% endblock %}
The rest of the scripts in my site are in the block scripts.
In a child template (within the script block and within script tags) I have this code,
if (auth_status) {
//something
}
The error at hand is auth_status is always True, when it should be on and off depending on if the user is logged in. Request_context is being passed to the template so that should not be the error.
Thanks
if (user_is_authenticated) { do stuff; }can be a security issue if you actually rely on the value of this JS variable. An user could modify the value of the JS variable before execution.request.user.is_authenticated()in python code. It's OK to use{% if user.authenticated %}in template code, as this will be computed server-side, that is, before the HTML is sent to the client. The generic rule of thumb is that anything that gets to the client can be altered, anything that never gets to them can't. (At least, not in this way ;) )