Ionic + Facebook + JWT + Passport.js, is it a good fit?

Hello,

I am trying to build an ionic app that is using the above for authentication purposes, and I nearly have it done but I am hitting a wall and I am looking for some advice.

My flow goes as follows:
Have a link in the client side of my app that triggers the function ng-click=“fbPopup(‘http://myserverip:3000/auth/facebook’)”

That function opens a window for fb to open in
$scope.fbPopup =function(url){
var win = window.open(url,‘popUpWindow’,‘centerscreen=true’); }

Then on my node server running on port:3000 I authenticate the user, create a JWT and send it back:
router.get(’/auth/facebook’, passport.authenticate(‘facebook’, {scope: config.facebookScope, session: false}));
router.get(’/auth/facebook/callback’, function(req, res, next) {
passport.authenticate(‘facebook’, function(err, token, info) {
console.log(‘token=’+token);
res.send(’< html>< head>< script type=“text/javascript”>localStorage.test = “’+token+’”; window.close();< /script>< /head>< /html>’);
console.log(‘fb callback’);
})(req, res, next)
});

My problem is, if I try this on my phone, as in ‘ionic run android’ - I get the error “Scripts may close only the windows that were opened by it”, and the popup window that loaded FB doesn’t close. Although I can see that in this window (that is now blank), the value of localStorage.test is correct.

And if I try and run it in my browser, as in ‘ionic serve’, it does close the FB window but the value of localStorage.test is undefined. I have to go from localhost:8100 to localhost:3000 before I can see the JWT set at localStorage.test. I fear this will happen when I get my FB window to disappear in the installed version on my phone?

How can I get the JWT to be stored in the localStorage of the users phone, and be accessible to my ionic app?
Is localStorage something that I should be using in conjunction with ionic?
Does Window.close() work with ionic? Am I using it incorrectly above?

Thanks very much!