feature-libs/asm/components/services/asm-component.service.ts
Methods |
constructor(authService: AuthService, csAgentAuthService: CsAgentAuthService, winRef: WindowRef)
|
||||||||||||
|
Parameters :
|
| isCustomerEmulationSessionInProgress |
isCustomerEmulationSessionInProgress()
|
|
Returns :
Observable<boolean>
|
| logoutCustomer |
logoutCustomer()
|
|
Returns :
void
|
| logoutCustomerSupportAgentAndCustomer |
logoutCustomerSupportAgentAndCustomer()
|
|
Returns :
void
|
| unload |
unload()
|
|
We're currently only removing the persisted storage in the browser to ensure the ASM experience isn't loaded on the next visit. There are a few optimizations we could think of:
Returns :
void
|
import { Injectable } from '@angular/core';
import {
ASM_ENABLED_LOCAL_STORAGE_KEY,
CsAgentAuthService,
} from '@spartacus/asm/root';
import { AuthService, WindowRef } from '@spartacus/core';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root',
})
export class AsmComponentService {
constructor(
protected authService: AuthService,
protected csAgentAuthService: CsAgentAuthService,
protected winRef: WindowRef
) {}
logoutCustomerSupportAgentAndCustomer(): void {
this.csAgentAuthService.logoutCustomerSupportAgent();
}
logoutCustomer(): void {
this.authService.logout();
}
isCustomerEmulationSessionInProgress(): Observable<boolean> {
return this.csAgentAuthService.isCustomerEmulated();
}
/**
* We're currently only removing the persisted storage in the browser
* to ensure the ASM experience isn't loaded on the next visit. There are a few
* optimizations we could think of:
* - drop the `asm` parameter from the URL, in case it's still there
* - remove the generated UI from the DOM (outlets currently do not support this)
*/
unload() {
if (this.winRef.localStorage) {
this.winRef.localStorage.removeItem(ASM_ENABLED_LOCAL_STORAGE_KEY);
}
}
}