Prevent users from browsing a Cordova app through the browser

Say you have a Cordova app published on the App Store. The codebase is deployed to mobile.myapp.com so that the installed apps can automatically get updated through hot code pushes.

How do you prevent people from accessing the app through a browser by pointing to this given URL?


Right now, i have this line in the /lib folder that does the trick:

if (Meteor.isClient && !Meteor.isCordova) { window.location.href = 'http://myapp.com'; }

I guess I could also do that with a server-side redirect by looking at user-agents.

Isn’t there a built-in way to do that though?

2 Likes

You can get a request server-side and return an error if the user-agent isn’t phonegap.
That code may be outdated

If you are using iron router maybe a redirect in the onBeforeAction in your client code?

Router.configure({
	onBeforeAction: function () {
		if (!Meteor.isCordova) {
			this.redirect("http://redirecturl");
		} else {
			this.next();
		}
	}
});

Thanks for the replies. I am doing this through a client-side redirect with iron:router. For those interested, I wrapped it up and published it as a package. https://atmospherejs.com/gwendall/iron-router-cordova-only

2 Likes

I’m now wondering if there is no way to force the Meteor.isCordova() to true from the browser. This looks like the kind of things that have to be controled from the server side.

This is also the case for the server I think. One could still change his user-agent to whatever the one is for Cordova clients.

1 Like

You’re right

In any case I find your package really useful