> ## Documentation Index
> Fetch the complete documentation index at: https://docs.opigno.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Integration with Firebase

Opigno Enterprise provides a native mobile application for learners that uses Firebase to send push notifications to Android and iOS devices.
A push notification will be triggered every time when Opigno in-built site notification is created.

<Note>
  If you work on the custom application, Firebase settings should be updated in the backoffice.
</Note>

## Register mobile device

To send push notifications, we need to know the information about the mobile device and associated Firebase token.
Opigno Enterprise API provides an endpoint to register mobile devices.
If device already exists (there is a match between a user context UUID and device UUID), an associated token will be updated.

To register device, the `registerMobileDevice` mutation should be executed **right after the login**.
Mutation has one required argument `deviceData` that represents the information about the mobile device that is being registered:

| Argument        | Type     | Description                                                                       |
| :-------------- | :------- | :-------------------------------------------------------------------------------- |
| `deviceName`    | `String` | **Required.** A name of the device that uses a Firebase token.                    |
| `deviceUuid`    | `String` | **Required.** UUID of the current mobile device.                                  |
| `deviceOs`      | `String` | **Required.** Current mobile device OS.                                           |
| `firebaseToken` | `String` | **Required.** A Firebase token assigned to the device to send push notifications. |

If the mutation executed without any errors, a boolean value will be returned as a response indicating the success status:

<CodeGroup>
  ```filename GraphQL theme={null}
  mutation registerMobileDevice {
    registerMobileDevice(deviceData: {
      deviceName: "iPhone",
      deviceUuid: "B064943C-B06F-46EF-B262-************",
      deviceOs: "iOS",
      firebaseToken: "dTJyESe2iUo9siCCh6pffQ:APA91bGINrL-..."
    }) {
      errors
      response
    }
  }
  ```

  ```File Query result [expandable] theme={null}
  {
    "data": {
      "registerMobileDevice": {
        "errors": [],
        "response": true
      }
    }
  }
  ```
</CodeGroup>

## Unregister mobile device

To prevent push notifications from being created when a user is logged out from the application,
should be executed the `unregisterMobileDevice` mutation. It has one argument - `firebaseToken`.

If the mutation executed without any errors, a boolean value will be returned as a response indicating the success status:

<CodeGroup>
  ```filename GraphQL example theme={null}
  mutation unregisterMobileDevice {
    unregisterMobileDevice(firebaseToken: "dTJyESe2iUo9siCCh6pffQ:APA91bGINrL-...") {
      errors
      response
    }
  }
  ```

  ```File Query result example [expandable] theme={null}
  {
    "data": {
      "registerMobileDevice": {
        "errors": [],
        "response": true
      }
    }
  }
  ```
</CodeGroup>

## Update Firebase token

Default lifetime of the Firebase token is 1 hour. Once this time is over, push notifications will not be
delivered to the related device.
To prevent such cases, the token should be updated. To do this, `updateFirebaseToken` mutation should be executed.

| Argument        | Type     | Description                                                               |
| :-------------- | :------- | :------------------------------------------------------------------------ |
| `deviceUuid`    | `String` | **Required.** UUID of the corresponding mobile device.                    |
| `firebaseToken` | `String` | **Required.** A new Firebase token that should be assigned to the device. |

If the mutation executed without any errors, a boolean value will be returned as a response indicating the success status:

<CodeGroup>
  ```filename GraphQL example theme={null}
  mutation updateFirebaseToken {
    updateFirebaseToken(firebaseToken: "dTJyESe2iUo9siCCh6pffQ:APA91bGINrL-...", deviceUuid: "B064943C-B06F-46EF-B262-************") {
      errors
      response
    }
  }
  ```

  ```File Query result example [expandable] theme={null}
  {
    "data": {
      "updateFirebaseToken": {
        "errors": [],
        "response": true
      }
    }
  }
  ```
</CodeGroup>
