85b31e9528
Co-authored-by: ISMAIL MASSERAN <topaz@Mac.dlinkrouter.local> Co-authored-by: ISMAIL MASSERAN <topaz@ISMAILs-Macbook.local> Reviewed-on: #1
21 lines
508 B
TypeScript
21 lines
508 B
TypeScript
import { DEVICE_TOKEN_KEY } from "./constants";
|
|
|
|
export function getDeviceToken(): string {
|
|
if (typeof window === "undefined") {
|
|
return "";
|
|
}
|
|
|
|
const existing = window.localStorage.getItem(DEVICE_TOKEN_KEY);
|
|
if (existing) {
|
|
return existing;
|
|
}
|
|
|
|
const token =
|
|
typeof crypto !== "undefined" && "randomUUID" in crypto
|
|
? crypto.randomUUID()
|
|
: `web-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
|
|
window.localStorage.setItem(DEVICE_TOKEN_KEY, token);
|
|
return token;
|
|
}
|