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;