I have been working on developing an Ionic app that requires creating a session for user login. The goal is to store the user's name upon logging in, so it can be checked later if the user is still logged in. I have created a model class and a user class for this purpose. However, I encountered an issue where the value stored inside Ionic returns null when I try to console log it, as shown in the image below:
https://i.sstatic.net/iQegy.png
I am puzzled by why it logs like '0: 'n', 1: 'o', 2: 'm', 3: 'e'
. My goal is to store the username in the session and log it simultaneously.
Here is how I am implementing this:
import { Storage } from "@ionic/storage";
import { Injectable } from '@angular/core';
import { Usuario } from "./interface/usuario";
@Injectable()
export class Session {
constructor(public storage: Storage){}
create(usuario: Usuario) {
this.storage.set('usuario', usuario);
}
get(): Promise<any> {
return this.storage.get('usuario');
}
remove() {
this.storage.remove('usuario');
}
exist() {
// code snippet
}
}
User Class Definition:
import { Model } from './../models/model';
export class Usuario extends Model{
nome: string;
email: string;
login: string;
senha: string;
}
Model Class Definition:
// code snippet
Here is where I retrieve the data stored in the Usuario object and log it:
ionViewDidLoad() {
// code snippet
}
Edit: This is what happens when I console.log inside create method using storage.get:
https://imgur.com/a/W2rQhd8
create(usuario: Usuario) {
this.storage.set('usuario', usuario);
console.log('[TEST] VALUE BEING PASSED IS ', this.storage.get('usuario'));
}