generate own UUID if crypto is not available
All checks were successful
Deploy Frontend / deploy (push) Successful in 1m58s
All checks were successful
Deploy Frontend / deploy (push) Successful in 1m58s
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user