Device Indexing

Access the unique device identifier of native mobile devices in your Lovable application.

Lovable Prompt
Lovable Prompt

Access the unique device identifier of native mobile devices in your application using the Despia SDK from: https://www.npmjs.com/package/despia-native

First, install the package: npm install despia-native

Then import it: import despia from 'despia-native'

  1. Import the Despia SDK in your component

  2. Access the unique device identifier using despia.uuid

  3. Display the device ID in your UI

  4. Send the device ID to your backend to link with user accounts

This feature requires native capabilities which will be fully provided by the “despia-native” npm package, no additional native libraries are needed!

Please follow the installation instructions for the "despia-native" npm package closely, and do not modify my instructions. Implementation as mentioned is critical.

How it works: The Despia SDK provides access to a unique device identifier through despia.uuid. This persistent ID helps you track devices, prevent account sharing, and manage user sessions across your mobile application.

Installation

Install the Despia package from NPM:

npm install despia-native

Usage

1. Import the SDK

import despia from 'despia-native';

2. Get Device ID

Access the Device ID from the despia.uuid variable:

// Simple example - show device ID and sync with user
const deviceId = despia.uuid;

// Display in UI
<p>Device: {deviceId}</p>

// Sync with backend when user logs in
fetch('/api/sync-device', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    userId: user.id,
    deviceId: deviceId,
    timestamp: new Date().toISOString()
  })
});

Backend Integration

// /api/sync-device endpoint
export default async function handler(req, res) {
  const { userId, deviceId, timestamp } = req.body;
  
  try {
    // Store the device-user association in your database
    await db.collection('user_devices').doc(deviceId).set({
      userId,
      deviceId,
      lastSeen: timestamp,
      createdAt: timestamp
    }, { merge: true });

    res.status(200).json({ success: true });
  } catch (error) {
    res.status(500).json({ error: 'Failed to sync device' });
  }
}

Resources

  • NPM Package

  • View full NPM documentation for additional configuration options

Lovable Integration

This SDK is optimized for Lovable's prompt-based AI builder, enabling quick integration of device identification into your generated apps.

Need Help?

For additional support or questions, please contact our support team at support@despia.com

Updated on