16 lines
463 B
TypeScript
16 lines
463 B
TypeScript
type UnauthorizedListener = () => void;
|
|
const unauthorizedListeners: UnauthorizedListener[] = [];
|
|
|
|
export const authEvents = {
|
|
onUnauthorized(listener: UnauthorizedListener) {
|
|
unauthorizedListeners.push(listener);
|
|
return () => {
|
|
const index = unauthorizedListeners.indexOf(listener);
|
|
if (index > -1) unauthorizedListeners.splice(index, 1);
|
|
};
|
|
},
|
|
emitUnauthorized() {
|
|
unauthorizedListeners.forEach(listener => listener());
|
|
}
|
|
};
|