fix(snjs): notify http service of refresh session

This commit is contained in:
Karol Sójko
2023-01-18 14:38:26 +01:00
parent 76937ba68c
commit 271db1c3dc
4 changed files with 35 additions and 8 deletions

View File

@@ -22,6 +22,10 @@ import {
UNSUPPORTED_KEY_DERIVATION,
UNSUPPORTED_PROTOCOL_VERSION,
Challenge,
InternalEventHandlerInterface,
InternalEventInterface,
ApiServiceEvent,
SessionRefreshedData,
} from '@standardnotes/services'
import { Base64String } from '@standardnotes/sncrypto-common'
import { ClientDisplayableError, SessionBody } from '@standardnotes/responses'
@@ -67,7 +71,10 @@ export enum SessionEvent {
* server credentials, such as the session token. It also exposes methods for registering
* for a new account, signing into an existing one, or changing an account password.
*/
export class SNSessionManager extends AbstractService<SessionEvent> implements SessionsClientInterface {
export class SNSessionManager
extends AbstractService<SessionEvent>
implements SessionsClientInterface, InternalEventHandlerInterface
{
private user?: Responses.User
private isSessionRenewChallengePresented = false
@@ -94,6 +101,12 @@ export class SNSessionManager extends AbstractService<SessionEvent> implements S
})
}
async handleEvent(event: InternalEventInterface): Promise<void> {
if (event.type === ApiServiceEvent.SessionRefreshed) {
this.httpService.setSession((event.payload as SessionRefreshedData).session)
}
}
override deinit(): void {
;(this.protocolService as unknown) = undefined
;(this.diskStorageService as unknown) = undefined