MobiLoud allows you to display a login screen when the app is opened, requiring users to log in before they can access the app content.
In order to dismiss the login screen after a successful login, you can use the “login” native function.
By calling the nativeFunctions.login() function the app will immediately dismiss the login screen and reload the app, updating all the content for the user who is now logged in.
Here is an example of how to use the login native function:
<script type="text/javascript">
// Get the user agent and convert it to lowercase for case-insensitive comparison
var userAgent = navigator.userAgent.toLowerCase();
// Set the user ID
var userId = "1";
// Log the user in directly if the user agent contains 'canvas'
function loginApp() {
try {
// Check if the user agent contains the string "canvas"
if (userAgent.indexOf('canvas') > -1) {
nativeFunctions.login();
}
} catch (ex) {
console.log(ex.message);
}
}
</script>
<button onClick="loginApp()">Log me in</button>
Keep in mind that dismissing the login screen and updating the content is all that the app does in this case, cookies and sessions should still be managed by your website.
You will also want to trigger the “logout” event when a page is loaded and the user is logged out, so the app can display the login screen again.