voluptasmollitia
Version:
Monorepo for the Firebase JavaScript SDK
33 lines (20 loc) • 1.18 kB
Markdown
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@firebase/messaging](./messaging.md) > [getToken](./messaging.gettoken.md)
## getToken() function
Subscribes the `FirebaseMessaging` instance to push notifications. Returns an Firebase Cloud Messaging registration token that can be used to send push messages to that `FirebaseMessaging` instance.
If a notification permission isn't already granted, this method asks the user for permission. The returned promise rejects if the user does not allow the app to show notifications.
<b>Signature:</b>
```typescript
export declare function getToken(messaging: FirebaseMessaging, options?: {
vapidKey?: string;
swReg?: ServiceWorkerRegistration;
}): Promise<string>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| messaging | [FirebaseMessaging](./messaging.firebasemessaging.md) | The <code>FirebaseMessaging</code> instance. |
| options | { vapidKey?: string; swReg?: ServiceWorkerRegistration; } | |
<b>Returns:</b>
Promise<string>
The promise resolves with an FCM registration token.