# What is the best way to write a custom security rule

**URL:** <https://community.fliplet.com/t/what-is-the-best-way-to-write-a-custom-security-rule/588>\
**Category:** Get Help\
**Created:** [October 18, 2023, 7:41pm UTC](https://community.fliplet.com/t/what-is-the-best-way-to-write-a-custom-security-rule/588 "2023-10-18T19:41:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmoralesrodriguez](https://dub1.discourse-cdn.com/flex017/user_avatar/community.fliplet.com/cmoralesrodriguez/32/339_2.png) [@cmoralesrodriguez](https://community.fliplet.com/u/cmoralesrodriguez)\
**Post date:** [October 18, 2023, 7:41pm UTC](https://community.fliplet.com/t/what-is-the-best-way-to-write-a-custom-security-rule/588/1 "2023-10-18T19:41:07Z")

</div>

We have used the following 2 codes snippets in our custom screen security condition, within the app settings of two different apps. I’m wondering if there is one that is better? Which one should we be using?

var loginSSO = #####;  
var loginEmail = ####;

var isAllowed =  
(session && session.entries && session.entries.dataSource) ||  
(session && session.entries && session.entries.saml2) ||  
( page.id === loginSSO ||  
page.id === loginEmail);

if (page.id !== loginSSO && !isAllowed) {  
error = true;  
navigate = { action: ‘screen’, page: loginSSO, transition: ‘slide.left’ };  
}

var loginSSO = ####;  
var IoginEmail = ####;

var isAllowed =  
(session && session.entries && session.entries.dataSource) ||  
(session && session.entries && session.entries.saml2) ||  
(page.id === loginSSO ||  
page.id === IoginEmail);

if (!isAllowed) {  
error = true;  
navigate = { action: ‘screen’, page: loginSSO, transition: ‘slide.left’ };  
}

---

<div class="post-metadata">

**Author:** ![Deb](https://dub1.discourse-cdn.com/flex017/user_avatar/community.fliplet.com/deb/32/159_2.png) [@Deb](https://community.fliplet.com/u/Deb)\
**Post date:** [October 19, 2023, 8:53am UTC](https://community.fliplet.com/t/what-is-the-best-way-to-write-a-custom-security-rule/588/2 "2023-10-19T08:53:27Z")

</div>

Hi Catalina,

I would use the first version over the second. The reason is that the first one will ensure you are not stuck on an infinite loop if you visit the SSO screen.

Thanks,  
Deb
