generate own UUID if crypto is not available
All checks were successful
Deploy Frontend / deploy (push) Successful in 1m58s

This commit is contained in:
2026-04-26 22:02:15 +02:00
parent b185b8c1ad
commit 76a8774695

View File

@@ -1,9 +1,19 @@
import axios from "axios"; 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 = () => { export const getUserId = () => {
let id = localStorage.getItem("poster_picker_uid"); let id = localStorage.getItem("poster_picker_uid");
if (!id) { if (!id) {
id = crypto.randomUUID(); id = generateUUID();
localStorage.setItem("poster_picker_uid", id); localStorage.setItem("poster_picker_uid", id);
} }
return id; return id;