Skip to content

Commit b541b3c

Browse files
committed
Make sure notification permissions are granted before calling getToken
1 parent 6104c68 commit b541b3c

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

packages/functions/src/context.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,16 @@ export class ContextProvider {
8585
}
8686

8787
async getInstanceIdToken(): Promise<string | undefined> {
88-
try {
89-
if (!this.messaging) {
90-
return undefined;
91-
}
88+
if (
89+
!this.messaging ||
90+
!('Notification' in self) ||
91+
Notification.permission !== 'granted'
92+
) {
93+
return undefined;
94+
}
9295

93-
const token = await this.messaging.getToken();
94-
if (!token) {
95-
return undefined;
96-
}
97-
return token;
96+
try {
97+
return this.messaging.getToken();
9898
} catch (e) {
9999
// We don't warn on this, because it usually means messaging isn't set up.
100100
// console.warn('Failed to retrieve instance id token.', e);

0 commit comments

Comments
 (0)