fallback to nanoid when crypto fails (#2845)
This commit is contained in:
@@ -1,10 +1,20 @@
|
|||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
|
import { nanoid } from "nanoid";
|
||||||
|
|
||||||
type ClientIdStore = {
|
type ClientIdStore = {
|
||||||
clientId: string;
|
clientId: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const initialClientId = crypto.randomUUID();
|
const generateClientId = (): string => {
|
||||||
|
try {
|
||||||
|
return crypto.randomUUID();
|
||||||
|
} catch (error) {
|
||||||
|
// if crypto.randomUUID() fails, use nanoid as a fallback
|
||||||
|
return nanoid();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const initialClientId = generateClientId();
|
||||||
|
|
||||||
export const useClientIdStore = create<ClientIdStore>(() => ({
|
export const useClientIdStore = create<ClientIdStore>(() => ({
|
||||||
clientId: initialClientId,
|
clientId: initialClientId,
|
||||||
|
|||||||
Reference in New Issue
Block a user