Skip to content

Instantly share code, notes, and snippets.

@rafbgarcia
Created February 5, 2018 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafbgarcia/0af25d0b1d784665576047f62332f47e to your computer and use it in GitHub Desktop.
Save rafbgarcia/0af25d0b1d784665576047f62332f47e to your computer and use it in GitHub Desktop.
import { Injectable } from '@angular/core'
import { Storage } from '@ionic/storage'
@Injectable()
export default class Motoboy {
constructor(
public storage: Storage
) {}
current() {
return this.storage.get("motoboy").then(motoboy => motoboy || {})
}
isLoggedIn(motoboy):boolean {
return motoboy && motoboy.token
}
async set(changes = {}) {
const motoboy = await this.current()
await this.storage.set("motoboy", {...motoboy, ...changes})
}
logout() {
this.storage.remove("motoboy")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment