Handling sign-in/sign-out differently on mobile and desktop

Not sure how to tackle this:

I have a meteor web application that I’d like to deploy as an iphone app. For desktop users I’d like to keep the sign it and sign out features (via accounts package) including remember feature (if enabled will not sign out the user even if browser is closed). However, for mobile users I’d like to sign in once and never sign them out even if they sign out from a browser session. How do I do that?

I do exactly what you describe in my app :slight_smile:
It’s strange, but as far as I know the Accounts package doesn’t include a “remember me” toggle feature. I hacked together my own using a cookie, it’s not that pretty though.

You can use Meteor.isCordova (returns true or false) to differentiate between browser and Cordova. For my app I actually determine wether to show the “Remember me” toggle based on window width, because I figure that anyone logging in with a mobile browser is also using a private device. I use this event listener to set a Session variable that I can then reference anywhere in my code.

$(function(){
	$(window).resize(function(){
		var width = $(window).width();
		if(width <= 768){ //768px is the treshold I've decided to use between mobile and desktop
			Session.set('mobile',true);
			$('body').addClass('mobile'); //I also add a class to body for CSS
		} else {
			Session.set('mobile',false);
			$('body').removeClass('mobile');
		}
	});
	$(window).trigger('resize');
});

And I have this global helper so I can wrap things in {{#if mobile}} and {{#unless mobile}} handlebars to toggle visibility:

Handlebars.registerHelper('mobile', function(){
	return Session.get('mobile');
});
{{#unless mobile}} <input type="checkbox" id="rememberme"> {{/unless}}

In my login event I just check wether the user is in mobile mode or has “remember me” checked:

if($('#rememberme').prop('checked') || Session.get('mobile')){
    //Set cookie
} else {
    //Delete cookie
}