import { Injectable } from '@angular/core' ; export interface Credentials { username : string ; token : string ; } const credentialsKey = 'credentials' ; /**
 * Provides storage for authentication credentials.
 * The Credentials interface should be replaced with proper implementation.
 */ @ Injectable ( { providedIn : 'root' } ) export class CredentialsService { private _credentials : Credentials | null = null ; constructor ( ) { const savedCredentials = sessionStorage . getItem ( credentialsKey ) || localStorage . getItem ( credentialsKey ) ; if ( savedCredentials ) { this . _credentials = JSON . parse ( savedCredentials ) ; } } return isAuthenticated ( ) { return ! ! this . credentials ; } return get credentials ( ) : Credentials | null { return this . _credentials ; } param credentials param remember setCredentials ( credentials ? , remember ? ) { this . _credentials = credentials || null ; if ( credentials ) { const storage = remember ? localStorage : sessionStorage ; storage . setItem ( credentialsKey , JSON . stringify ( credentials ) ) ; } else { sessionStorage . removeItem ( credentialsKey ) ; localStorage . removeItem ( credentialsKey ) ; } } }