<p>You could loop through the users and compare them.</p>

<pre><code>{% set authorized = false %}
{% for user in entry.authorizedUsers %}
    {% if user == currentUser %}
        {% set authorized = true %}
    {% endif %}
{% endfor %}

{% if not authorized %}
    {% redirect 403 %}
{% endif %}
</code></pre>

CC BY-SA 3.0
2015-01-10T23:39:34.963Z
Ahha! I didn't know about redirect tag, will give that a shot, thanks
GlennJ
CC BY-SA 3.0
2015-01-10T23:52:34.947Z
Glad to help. Let me know if that first option works. I'm curious myself. Also, you can redirect anywhere with the `redirect` method (I just chose 403 as an example), or display alternate content if you like. You may also have to check if there is a currentUser at all, using `{% if currentUser %}... {% endif %}`
Douglas McDonald
CC BY-SA 3.0
2015-01-11T00:20:39.330Z
Pretty sure Twig doesn't have an `in_array`.  It does have an `in`, so you could do `{% if not currentUser in entry.authorizedUsers %}`, but I doubt that will work when comparing whole objects to each other. Would probably need to just do the comparison on authorId, but honestly your 2nd solution seems better.
Brad Bell
CC BY-SA 3.0
2015-01-11T18:56:35.503Z
@Brad.... thanks. I was looking at a [post on the twig stack exchange](http://stackoverflow.com/questions/7460481/twig-in-array-or-similar-possible-within-if-statement) and misread it. As you say, still may not work.
Douglas McDonald
CC BY-SA 3.0
2015-01-10T21:08:37.683Z
2015-01-11T19:22:28.877Z
2015-01-11T19:22:28.877Z
Douglas McDonald
<p>I would like to protect the viewing of an _entry.html page so that only a user related to that entry can view it.</p>

<entry><authentication>
Protect entry so that only a "relatedTo" user can see it
# Protect entry so that only a "relatedTo" user can see it

(Asked by: username_0 on 2015-01-10)

I would like to protect the viewing of an \_entry.html page so that only a user related to that entry can view it.

**Tags:** entry, authentication

---

## 1 answers

### Answer by username_1 on 2015-01-10. Score: 2

You could loop through the users and compare them.
{% set authorized = false %}
{% for user in entry.authorizedUsers %}
    {% if user == currentUser %}
        {% set authorized = true %}
    {% endif %}
{% endfor %}

{% if not authorized %}
    {% redirect 403 %}
{% endif %}

> **Comments:**
> **username_0**: Ahha! I didn't know about redirect tag, will give that a shot, thanks  
> **username_1**: Glad to help. Let me know if that first option works. I'm curious myself. Also, you can redirect anywhere with the `redirect` method (I just chose 403 as an example), or display alternate content if you like. You may also have to check if there is a currentUser at all, using `{% if currentUser %}... {% endif %}`  
> **username_2**: Pretty sure Twig doesn't have an `in_array`.  It does have an `in`, so you could do `{% if not currentUser in entry.authorizedUsers %}`, but I doubt that will work when comparing whole objects to each other. Would probably need to just do the comparison on authorId, but honestly your 2nd solution seems better.  
> **username_1**: @Brad.... thanks. I was looking at a [post on the twig stack exchange](http://stackoverflow.com/questions/7460481/twig-in-array-or-similar-possible-within-if-statement) and misread it. As you say, still may not work.  

---

