constructor()

in libs/@guardian/identity-auth/src/authState.ts [18:46]


	constructor(emitter: Emitter, tokenManager: TokenManager<AC, IC>) {
		this.#emitter = emitter;
		this.#tokenManager = tokenManager;

		// set default auth state, will be updated if there are existing tokens in storage
		this.#authState = {
			accessToken: undefined,
			idToken: undefined,
			isAuthenticated: false,
		};

		// on init, check if there are existing tokens in storage, and if so, update the auth state
		this.#updateAuthState();

		// subscribe to token manager events on addition
		this.#emitter.on('added', () => {
			this.#updateAuthState();
		});

		// subscribe to token manager events on removal
		this.#emitter.on('removed', () => {
			this.#updateAuthState();
		});

		// subscribe to token manager events on storage
		this.#emitter.on('storage', () => {
			this.#updateAuthState();
		});
	}