Logout a user and take them to a login screen
PRE-REQUISITES
For the following code examples to work, you will need to add the fliplet-session library to your app. To add it follow these steps:
- When in Fliplet Studio’s Edit screen, open the Developer Options from the right hand menu
- With the Developer Options open, click the Libraries button in the top right corner
- In the search field, type in ‘fliplet-session’
- Click it to add it to the list
- Click Save
You can run some code to logout a user. The code differs slightly depending on the way the user was originally logged in. If the user has logged in with the ‘Login’, ‘Verification: Email’ or ‘Verification: SMS’ components (that use a data source). You can log out with the following code:
JavaScript
Fliplet.Session.logout('dataSource')
.then(function () {
// logs out a user that logged in with a SAML2 Login component
});
However, if a user has logged in with a ‘SAML2 Login’ or a ‘Fliplet Login’ component then you’ll need to change the code slightly.
JavaScript
Fliplet.Session.logout('SAML2')
.then(function () {
// logs out a user that logged in with a SAML2 Login component
});
Fliplet.Session.logout('flipletLogin')
.then(function () {
// logs out a user that logged in with a Fliplet Login component
});
After you’ve logged out a user you may want to redirect them to a login screen. In the example below, we log a user out and then redirect them to another screen (with a screen ID of 85764).
JavaScript
Fliplet.Session.logout('dataSource')
.then(function () {
// add custom code here to be run after log out
// below we navigate a user to a new screen
Fliplet.Navigate.screen(85764);
});