The Firebase JS SDK is now in BETA!
This EAP site is no longer maintained. See the official Firebase Documentation site for the latest documentation and information about the Firebase JS SDK.

Home > @firebase/messaging > getToken

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.

Signature:

export declare function getToken(messaging: FirebaseMessaging, options?: {
    vapidKey?: string;
    swReg?: ServiceWorkerRegistration;
}): Promise<string>;

Parameters

Parameter Type Description
messaging FirebaseMessaging The FirebaseMessaging instance.
options

Returns:

Promise<string>

The promise resolves with an FCM registration token.