title: How to efficiently store and use Authentication in Ionic 3
body: <p>I'm currently developing an <strong>Ionic (3.4)</strong> app for iOS/Android.
  I'm not familiar with authentification processes or with applications.</p>
  
  <p>After using HTTP request in a provider, <strong>I get my object</strong>, the user. But I have absolutely no idea how to store it or to deal with it. What are the good practices:</p>
  
  <ul>
  <li>Am I suppose to just store the object in the provider and call in in every single page I have?</li>
  <li>Am I suppose to store it as a sort of global object in the app?</li>
  <li>Or am I suppose (as bellow) to transfer it as a Navigation variable from one page to another? (I guess that's not the right answer)</li>
  </ul>
  
  <p>And finally, how will the application react on reloading/restarting: how to avoid people to fill the form again and again?</p>
  
  <p>Here is my service:</p>
  
  <pre><code>@Injectable()
  export class UserProvider {
      data = {};
      username: string;
      password: string;
  
      constructor(private _http: Http) {
          console.log('Hello UserProvider Provider');
      }
  
      getUser(username:string, password:string){
  
          let urlSearchParams = new URLSearchParams();
          urlSearchParams.append('username', username);
          urlSearchParams.append('password', password);
          let params = urlSearchParams.toString()
  
          var headers = new Headers();
          headers.append('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
  
          return this._http
          .post("http://api.minesdedouai.fr/user/login", params, {headers:headers} )
          .map(response =&gt; response.json())
  
      }
  
  }
  </code></pre>
  
  <p>I'm aware that a login request is supposed to use some token, but as I said, this is a small student's API, we're not pro and it's working.</p>
  
  <p>And this is the method that uses the service, somewhere in a component (a page).</p>
  
  <pre><code>onLogin(form: NgForm) {
    if (form.valid) {
      this._userProvider.getUser(this.login.username, this.login.password)
      .subscribe((response) =&gt; {
        this.user = response;
        console.log("Authentification Success");
        this.navCtrl.push(TabsPage, {user: this.user});
      },
      (error) =&gt; {
        if (error.status===403){
          console.log("Wrong User")
        }
        else{
          console.log(error);
        }
  
      });
    }
  }
  </code></pre>
  
  <p>Thank you very much</p>