Custom security script error message

Hi - I’m getting an error message with a custom security script: SyntaxError: Unexpected number

I’m trying to redirect users after login to three different screens based on their classification in one column from the datasource. Can anyone help me with the code?

\if ActiveFree then freeMenu
\if ActivePaid then paidMenu
\if Expired then subscription

var freeMenu = 453215;
var subscription = 453456;
var paidMenu 248884;
var hasSession = session && session.entries && session.entries.dataSource;
var isActiveFree = hasSession && session.entries.dataSource.data[‘Access’] === ‘Active Free’;
var isActivePaid = hasSession && session.entries.dataSource.data[‘Access’] === ‘Active Paid’;
var isExpired = hasSession && session.entries.dataSource.data[‘Access’] === ‘Expired’;
var error = false;

if ((isActiveFree && hasSession) ||(isActivePaid && hasSession) ||(isExpired && hasSession)){

error = false;

}

if (!isActiveFree || !isActivePaid || !isExpired){

error = true;

}

if (isActiveFree){

navigate = { action: ‘screen’, page: freeMenu, transition: ‘slide.left’ };

}

if (isActivePaid){

navigate = { action: ‘screen’, page: paidMenu, transition: ‘slide.left’ };

}

if (isActivePaid){

navigate = { action: ‘screen’, page: subscription, transition: ‘slide.left’ };

}

Hi Jay, you are missing ‘=’ sign after paidMenu.
So your line of code should be:
var paidMenu = 248884;

Kind regards.

Thank you. That allowed me to save the script without error. However, when I enable security to test in preview mode, I get the following error:

Error
Hook for app #9429 failed with error: SyntaxError: Expecting Unicode escape sequence \uXXXX

HTTP ERROR 400

What am I doing wrong?

var freeMenu = 453215;
var subscription = 453456;
var paidMenu = 248884;
var hasSession = session && session.entries && session.entries.dataSource;
var isActiveFree = hasSession && session.entries.dataSource.data['Access'] === 'Active Free';
var isActivePaid = hasSession && session.entries.dataSource.data['Access'] === 'Active Paid';
var isExpired = hasSession && session.entries.dataSource.data['Access'] === 'Expired';
var error = false;

if ((isActiveFree && hasSession) ||(isActivePaid && hasSession) ||(isExpired && hasSession)){

error = false;

}

if (!isActiveFree || !isActivePaid || !isExpired){
error = true;
}

if (isActiveFree){

navigate = { action: 'screen', page: freeMenu, transition: 'slide.left' };

}

if (isActivePaid){

navigate = { action: 'screen', page: paidMenu, transition: 'slide.left' };

}

if (isActivePaid){

navigate = { action: 'screen', page: subscription, transition: 'slide.left' };
}

Hi Jay, this snippet does not have syntax error, but you might have logic or redirect errors. Thanks

Hello Veljko – thank you so much for your help.

With the script below, I’m getting the following error message when I enable security in the preview mode:

Error: Hook for app #9429 failed with error: ReferenceError:Fliplet is not defined. HTTP ERROR 400

Hi Jay,
We will need more information to be able to help you.
Can you please send us a screenshot of where did you paste this code snippet?

Thanks


Hi, Jay!
You need to paste only this code:

var freeMenu = 453215;
var subscription = 453456;
var paidMenu = 248884;
var hasSession = session && session.entries && session.entries.dataSource;
var isActiveFree = hasSession && session.entries.dataSource.data['Access'] === 'Active Free';
var isActivePaid = hasSession && session.entries.dataSource.data['Access'] === 'Active Paid';
var isExpired = hasSession && session.entries.dataSource.data['Access'] === 'Expired';
var error = false;

if ((isActiveFree && hasSession) ||(isActivePaid && hasSession) ||(isExpired && hasSession)){

error = false;

}

if (!isActiveFree || !isActivePaid || !isExpired){
error = true;
}

if (isActiveFree){

navigate = { action: 'screen', page: freeMenu, transition: 'slide.left' };

}

if (isActivePaid){

navigate = { action: 'screen', page: paidMenu, transition: 'slide.left' };

}

if (isActivePaid){

navigate = { action: 'screen', page: subscription, transition: 'slide.left' };
}

as a custom condition for App security. So simply you need to remove the first 4 lines of your code including calling customRedirect function on line 4. Also, don’t forget to remove the closing function bracket ‘}’ on the last line of your code.

Best regards

Hi – thank you for the assistance. I’m still getting an error message using the code below.

Hi Jay, can you please send to us the screenshot of the error you are getting now? Thanks

Jennifer Whetzel
207-838-1340

| Veljko Popovic Veljko
February 22 |

  • | - |

Hi Jay, can you please send to us the screenshot of the error you are getting now? Thanks

Hi Jay, to be able to help you, please send as a screenshot of the code from the Security rules box. Thanks

Hello!

Here’s a document showing what I’m trying to do, the latest code I tried as well as the screenshots of the code inside the app and the error message:

https://docs.google.com/document/d/1fqRyzPmJsfvZ8o10emgRVHin4LUez3oRMIwkdkSBDzY/edit?usp=sharing

Would it help to give you access to the app?