How do you make a Term's screen only visible to users once

Hello- I am wondering how I can make my terms and conditions screen only visible to users the first time they sign into the app and not every single time? Thanks for the advice :slight_smile:

In order to achieve this you need to put custom code in the App security and the T&C’s screen.
This will also allow you to force users to accept a new version of terms and conditions.

Setup:

Go to App settings > App security. Click ‘Add new rule’ and choose custom condition. This can be used in conjunction with a regular security rule enforcing any type of login.

Paste the following code in the box.


var termsScreen = 12345; //change to the page id of the T&C screen
var terms = 'terms1'; //change to the name of the terms version in the code pasted below. 
//change to any screen you visit before the login screen like an onboarding screen. 
var onboardingScreen = 12345 

var hasSession = session && session.entries && session.entries.dataSource;
if (hasSession){
   var isAllowed = session.entries.dataSource.data['Latest Terms'] === terms

   if (page.id !== onboardingScreen && page.id !== termsScreen && !isAllowed) {
       error = true;
       navigate = { action: 'screen', page: termsScreen, transition: 'slide.left' };
    }
}

You need to change 3 things as mentioned above. You need the screen id of the T&C’s screen (This can be found by selecting the settings cog next to the screen name), the variable of the terms screen set below, and the id of the onboarding screen.

The following code is needed in the screen JS of the T&C’s screen:


// change to be the same variable set as the terms variable above. They need to match. 
var latestTerms = 'terms1'; 

var userId;
var dataSourceId;

Fliplet.User.getCachedSession().then(function(session) {
  userId = session.entries.dataSource.id;
  dataSourceId = session.entries.dataSource.dataSourceId
});


Fliplet.Hooks.on('beforeFormSubmit', function(response) {
  return Fliplet.DataSources.connect(dataSourceId).then(function(connection) {
    return connection.update(userId, {
      'Latest Terms': latestTerms
    }).then(function(){
      return Fliplet.Session.get()
    })
  });
});

This will force logged in users to accept the terms and conditions and will write against their user profile which version of the terms they accepted (in this example it would be terms1)

If you would like to update the terms and conditions on the screen then you need to change the terms1 variable in both places and push out an in-app update. This will automatically force everyone to accept the new terms and conditions. For e.g. if you set on the screen JS and the app security to be “terms2” everyone will be forced to accept.

Note: Please be careful that both the names match, if they don’t match and you push out an update users will get stuck on the terms screen.