Best Database? Help

Hi everyone,

In my ionic app I want to add a login form.
I’m thinking about use a db alocated in a web with all the credentials, so the user has to be online to login.
But I want to storage the login locally , so the user doesn’t have to login every single time the app is open.

Please help me, what is the best way to do this?
I searched in the web but I can’t find anything objective.

I am new in Ionic, but i think you can use firebase for online DB and eigther local storage or sqlLite for local storage.

Hi @hermanho237, I’m new too. I want to know the best way to do this, I saw SQLite, PouchDB, Firebase, so many ways to do, but i can’t figure out the best way, I need a little help to start, to choose the best tools and how to do it.

You want to store the credentials locally? I suggest SQLite then.

Hi @maxx0r, my point is to have a db online with the credentials of the users (username, password…).
When the user, login for the first time he has to be online to do it, because his credentials are storaged in a db online… but then I want the app keeps his credentials storaged locallly, so next time you open the app you login automatically and you don’t need to have an internet connection.
I want to put the db with users data online because it’s the same db I want to use in a website to make the logins.

Allright. What the general way of doing this is, is giving the user a token after logging in and using that for communications. Your app can check if there’s a token, of clear it when logging out (or when the token is invalidated by the server)

So basically I use the firebase to connect the db online to my app, and then I save the credentials in tokens?
Do you know a good tutorial that can help me ?
I have no clue how to process this, as I said I’m new with ionic and mobile apps, make the db connect to my website I can do it…
I have experience with PHP and SQL…

PS: Is there a way to do what I want based in php?

Something like that? It’s based on user/password authorization. The server issues a token which you use on communication

As i earlier said, you will probablly have to use Firebase for online storage, and SQLlite or HTML5 local storage for local storage of your USER data.

1 Like

It really depends on the larger context of the app, how much and what type of data you plan to store in total, to tell you “what is best”. If it is just the login credentials, a simple local storage key/value pair works great; any thing else is pretty much overkill. If this is a training app, use the database you want to learn for future work.

1 Like

Well, I’m using php + mysql, I’m facing a problem with $state.go, after introducing the right credentials I received the error: $state.go is not a function

`app.controller(‘controllerForm’, function($scope, $http, $state, $stateParams ) {

  $scope.rsJSON = [ ];

  $scope.entrar = function() {
    consultarUsuario($http,$scope);
      
  };

});
/app.controller(‘consultarUsuario’, function($scope, $http, $state, $stateParams ){/

function consultarUsuario($http,$scope, $state, $stateParams ){
var req = {
method: ‘POST’,
url: ‘http://localhost/test/index.php’,
headers: {
‘Content-Type’: undefined
},
data: { usuario : $scope.txtUsuario , contrasena : $scope.txtContrasena },
dataType: “jsonp”
}

$http(req)
    .success(function(data, $scope, $state, $stateParams ) {
      console.log('Hello ' + data.USUARIO);


   if (typeof(data.USUARIO) == "undefined"){
            alert("Wrong user/password");
       }else{
        
          alert("Right!!!");
          $state.go('app.ink');
       }
    
       
    })
    .error(function(data) {
        console.log('Error: ' + data);
    }); };`

Any Help with this?
Thanks

It’s just to keep the login credentials, use an external db storaged in a web server it’s the objective, because the same login credentials will be used to login in a website too, and if an user change the password, it’s automatically updated for the app and the web.

So for the app, based on my point the best solution is use a local storage?
in the future, the app will store the car shop until the user clean it.
It’s safe doing with local storage too?

Before you worry about where to store your data, I think you need to take the time to understand the various tiers. When you think php think “server”. Ionic is a client tool; it and php are apples and oranges. Other than basic logic processing, your php knowledge is only relevant on what is done on the server; javascript is a very different beast than php (I know of where I speak, Im a c# guy so I feel your pain). When you think ionic think “client”, “angular/javascript”. I suggest you take the time to write some ionic test apps that talk to your php/server resources, there are lots of youtube examples.
Then, regarding storing your data: my basic rule-of-thumb is to keep in the client only the data elements that it has to have; I try to design the app to keep this amount of data at a minimum, and often use key/value local storage pairs. Everything else goes onto the server. Some favor architectures that make use of local storage mechanisms such as Firebase, sqlite, etc. Is one necessarily better than the other? No, but the real question is “which is better for your app?”. And only you can make that decision.

1 Like

Thanks for your advice!

Sure, I hope you found it helpful. Good luck, and remember to have fun!