@bitblit/ratchet-warden-common
Version:
Typescript library to simplify using simplewebauthn and secondary auth methods over GraphQL
52 lines • 1.86 kB
JavaScript
import { BehaviorSubject } from 'rxjs';
import { WardenUtils } from '../common/util/warden-utils.js';
import { Logger } from '@bitblit/ratchet-common/logger/logger';
export class WardenDelegatingCurrentUserProvidingUserServiceEventProcessingProvider {
wrapped;
serveExpiredCredentials;
_currentUserSubject = new BehaviorSubject(null);
constructor(wrapped, serveExpiredCredentials = false) {
this.wrapped = wrapped;
this.serveExpiredCredentials = serveExpiredCredentials;
}
fetchCurrentLoggedInJwtToken() {
let val = this?._currentUserSubject?.getValue();
if (!this.serveExpiredCredentials && val && WardenUtils.wrapperIsExpired(val)) {
Logger.info('Current wrapper in the subject is expired - autostripping');
this.currentUserSubject.next(null);
val = null;
}
return val?.jwtToken;
}
get currentUserSubject() {
return this._currentUserSubject;
}
onAutomaticLogout() {
if (this.wrapped) {
this.wrapped.onAutomaticLogout();
}
}
onAutomaticTokenRefresh(refreshUser) {
if (this?.wrapped?.onAutomaticTokenRefresh) {
this.wrapped.onAutomaticTokenRefresh(refreshUser);
}
}
onLoginFailure(reason) {
if (this?.wrapped?.onLoginFailure) {
this.wrapped.onLoginFailure(reason);
}
}
onLogout() {
if (this?.wrapped?.onLogout) {
this.wrapped.onLogout();
}
this.currentUserSubject.next(null);
}
onSuccessfulLogin(newUser) {
if (this?.wrapped?.onSuccessfulLogin) {
this.wrapped.onSuccessfulLogin(newUser);
}
this.currentUserSubject.next(newUser);
}
}
//# sourceMappingURL=warden-delegating-current-user-providing-user-service-event-processing-provider.js.map