From 76a8774695f8c50d92643c7cdc9cdc21a61c0496 Mon Sep 17 00:00:00 2001 From: Hugo Pierret Date: Sun, 26 Apr 2026 22:02:15 +0200 Subject: [PATCH] generate own UUID if crypto is not available --- src/services/api.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/services/api.js b/src/services/api.js index f8261f3..3bafd54 100644 --- a/src/services/api.js +++ b/src/services/api.js @@ -1,9 +1,19 @@ import axios from "axios"; +const generateUUID = () => { + if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") { + return crypto.randomUUID(); + } + return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => { + const r = (Math.random() * 16) | 0; + return (c === "x" ? r : (r & 0x3) | 0x8).toString(16); + }); +}; + export const getUserId = () => { let id = localStorage.getItem("poster_picker_uid"); if (!id) { - id = crypto.randomUUID(); + id = generateUUID(); localStorage.setItem("poster_picker_uid", id); } return id;