Skip to content

Commit

Permalink
Fix for StatefulAuthProvider's change in behavior (#1932)
Browse files Browse the repository at this point in the history
  • Loading branch information
sourishkrout authored Jan 28, 2025
1 parent 7109023 commit f2ad564
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/extension/signedIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ConnectSerializer } from './serializer'
import { Kernel } from './kernel'
import { RunmeEventInputType } from './__generated-platform__/graphql'
import getLogger from './logger'
import { StatefulAuthProvider } from './provider/statefulAuth'
import { StatefulAuthProvider, StatefulAuthSession } from './provider/statefulAuth'
import AuthSessionChangeHandler from './authSessionChangeHandler'

export interface CellRun {
Expand All @@ -22,20 +22,24 @@ export interface CellRun {
}
}

const log = getLogger('LoggedIn')
const log = getLogger('SignedIn')

export class SignedIn implements Disposable {
#subscriptions: Subscription[] = []
readonly #cellRuns = new Subject<CellRun>()

constructor(protected readonly kernel: Kernel) {
const signedIn$ = new Observable<boolean>((observer) => {
const nextSession = (p?: Promise<StatefulAuthSession | undefined>) => {
return p?.then((session) => observer.next(!!session)).catch(() => observer.next(false))
}

AuthSessionChangeHandler.instance.addListener(() => {
StatefulAuthProvider.instance
.currentSession()
.then((session) => observer.next(!!session))
.catch(() => observer.next(false))
return nextSession(StatefulAuthProvider.instance.currentSession())
})

// initial value
nextSession(StatefulAuthProvider.instance.currentSession())
})

const cellRuns$ = this.#cellRuns.pipe(
Expand Down

0 comments on commit f2ad564

Please sign in to comment.