Storage error when debbuging in Chrome


#1

Hi everyone,

I got an error when getting some informations from the storage.
I store some data on a login page, and then on another one i try to retrive it as follow :

import { Component } from '@angular/core';
import { NavControlle } from 'ionic-angular';
import { Http }       from '@angular/http';
import { ApiCaller }  from './../../providers/api-caller';
import { Storage }    from '@ionic/storage';
import { NextPage } from "../next/next";

@Component({
  providers: [Storage],
  selector: 'page-login',
  templateUrl: 'login.html'
})
export class LoginPage {
  public user = { username: null, password: null, user: null};

  constructor(
  	public navCtrl: NavController, 
	public http: Http, 
	public storage : Storage) 
	{}

  attemptLogin() {
    let caller = new ApiCaller(this.http, this.user.username, this.user.password);
    caller.me()
      .then(user => {
        Promise.all([
          this.storage.set('api-user', this.user.username),
          this.storage.set('api-pass', this.user.password),
          this.storage.set('user', user)
        ]).then(values => {
          this.navCtrl.setRoot(NextPage);
        });

      })
      .catch(err => {
        console.log(err);
      })
    ;
  }
}

This works perfectly but this other one doesn’t :

import { Component }  from '@angular/core';
import { Http }       from '@angular/http';
import { ApiCaller }  from './../../providers/api-caller';
import { NavController } from 'ionic-angular';
import { Storage }    from '@ionic/storage';
import moment from 'moment';

@Component({
  selector: 'page-next',
  templateUrl: 'next.html',
  providers: [Storage],
})
export class NextPage {

  public user: any;

  constructor(
    public navCtrl: NavController,
    public http : Http,
    public storage : Storage) {
    
    this.storage.get('user')
      .then(user => {
        this.user = user;
      })
      .catch(error => console.log(error)); // throws TypeError: Cannot read property 'name' of null
  }
}

This error : TypeError: Cannot read property ‘name’ of null only occurs when I use Chrome with device debug ON using any android device but not when using an apple device, the only difference i can figure is that asyncStorage is used by android and webSQLStorage is used by iOS device.

Can anyone help me ? Thanks :slight_smile: