import { VueConstructor } from 'vue' ; import { AuthUser , VueAuthStore } from '../../interfaces' ; import { IVueAuthOptions } from '../auth' ; export default class StoreLocalStorage extends VueAuthStore { constructor ( Vue , options ) { super ( Vue , options ) ; this . store = window . localStorage ; this . initVue ( ) ; } public getRoles ( ) { const user = this . getUser ( ) ; return user && this . options . rolesVar && user [ this . options . rolesVar ] ; } public getToken ( ) { return this . store . getItem ( this . options . tokenDefaultName ) ; } public getUser ( ) { return JSON . parse ( this . store . getItem ( this . options . userDefaultName ) ) ; } public setToken ( token ) { if ( token ) { this . store . setItem ( this . options . tokenDefaultName as string , token ) ; } else { this . store . removeItem ( this . options . tokenDefaultName ) ; } } public setUser ( user ) { if ( user && Object . keys ( user ) ) { this . store . setItem ( this . options . userDefaultName as string , JSON . stringify ( user ) ) ; } else { this . store . removeItem ( this . options . userDefaultName ) ; } } }