cordova.plugins.SecureKeyStore.get(function (res) {
if ( res ) {
auth = JSON.parse(res);
if ( auth.username && auth.password ) {
app.request.setup({
headers: {
'Authorization': 'Basic '+Base64.encode(auth.username+':'+auth.password)
}
});
app.router.navigate('/current-orders/');
}
}
}, function (error) {
auth = {};
app.router.navigate('/auth/login/');
}, "auth");
console.log('fallback to failed auth');
as you can see, usually I put a fallback on the bottom, just in case the SecureKeyStore.get didn’t run properly.
similarly, I don’t use “else” for if ( res ). Because I don’t like to put tons of if/else everywhere. It much easier and cleaner to navigate out of the view and stop the rest of the code.
Question is more about coding structuring. In F7 if navigate launched there is no way to stop/prevent it. You need to structure your logic to make all the checks before calling navigate