Files
2 min
File Structure
default/storefront/assets/scripts/custom/
├── custom.js # Main entry point - import init.js here
└── sso-manager/
├── config.js # Configuration file
├── sso-manager.js # Core SSOManager class
└── init.js # Extended class with lifecycle hooks
Files
import { SSOManager } from './sso-manager';
import { extendStorefrontHook } from "../utils/extend-storefront-hook";
/**
* Extended SSOManager class with project-specific login/logout hooks
* @extends SSOManager
*/
class ExtendedSSOManager extends SSOManager {
/**
* Hooks to execute project-specific logic after successful login
* @type {{ app: () => Promise<void>, web: () => Promise<void> }}
*/
onLogin = {
app: async () => {
// do some project/environment specific stuff right after login in app
},
web: async () => {
// do some project/environment specific stuff right after login in web
}
}
/**
* Hooks to execute project-specific logic after successful logout
* @type {{ app: () => Promise<void>, web: () => Promise<void> }}
*/
onLogout = {
app: async () => {
// do some project/environment specific stuff right after logout in app
},
web: async () => {
// do some project/environment specific stuff right after logout in web
}
}
}
/**
* Global singleton instance of ExtendedSSOManager
* @type {ExtendedSSOManager | null}
*/
export let ssoManager = null;
/**
* Initialize SSO Manager automatically when Purple Service is ready
* Creates the singleton instance of ExtendedSSOManager on Purple Service initialization
* This ensures SSO functionality is available as soon as the application is ready
*/
extendStorefrontHook('onPurpleServiceInit', () => {
if (!ssoManager) {
ssoManager = new ExtendedSSOManager();
}
});