Skip to content

Commit 213432f

Browse files
committed
bug(setting): Fix issue with empty session in cache.
Because: - There's no guarantee that session is in the cache. - If there's no session in the cache we'd hit a run time error This Commit: - Handles the case that session is missing. - Creates empty string fallback for token getter - Creates false fallback for verified getter
1 parent f567141 commit 213432f

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

packages/fxa-settings/src/models/Session.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,22 @@ export class Session implements SessionData {
6969
}
7070
}
7171

72-
private get data() {
73-
const { session } = this.apolloClient.cache.readQuery<{
72+
private get data(): Session | undefined {
73+
const result = this.apolloClient.cache.readQuery<{
7474
session: Session;
7575
}>({
7676
query: GET_SESSION_VERIFIED,
77-
})!;
78-
return session;
77+
});
78+
79+
return result?.session;
7980
}
8081

8182
get token(): string {
82-
return this.data.token;
83+
return this.data?.token || '';
8384
}
8485

8586
get verified(): boolean {
86-
return this.data.verified;
87+
return this.data?.verified || false;
8788
}
8889

8990
// TODO: Use GQL verifyCode instead of authClient

0 commit comments

Comments
 (0)