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:
Jose Olarte III
2026-05-13 20:57:14 +08:00
parent 6a9f34a516
commit 4c97c578bb

View File

@@ -3,7 +3,16 @@ import { Preferences } from "@capacitor/preferences";
const DEVICE_ID_KEY = "stable_device_id";
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> {