fix(notifications): fall back when crypto.randomUUID is missing
If randomUUID is unavailable (older WebViews), generate a one-time ID with Date.now + random segment, log a single DeviceId warning, and persist it as before so registration still works.
This commit is contained in:
@@ -3,7 +3,16 @@ import { Preferences } from "@capacitor/preferences";
|
|||||||
const DEVICE_ID_KEY = "stable_device_id";
|
const DEVICE_ID_KEY = "stable_device_id";
|
||||||
|
|
||||||
function generateDeviceId(): string {
|
function generateDeviceId(): string {
|
||||||
return crypto.randomUUID();
|
if (typeof crypto !== "undefined" && crypto.randomUUID) {
|
||||||
|
return crypto.randomUUID();
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.warn(
|
||||||
|
"[DeviceId] crypto.randomUUID unavailable, using fallback generator",
|
||||||
|
);
|
||||||
|
|
||||||
|
return `${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getOrCreateDeviceId(): Promise<string> {
|
export async function getOrCreateDeviceId(): Promise<string> {
|
||||||
|
|||||||
Reference in New Issue
Block a user