fallback to nanoid when crypto fails (#2845)

This commit is contained in:
LawyZheng
2025-07-01 00:35:31 +08:00
committed by GitHub
parent e448721468
commit 7a96642c12

View File

@@ -1,10 +1,20 @@
import { create } from "zustand";
import { nanoid } from "nanoid";
type ClientIdStore = {
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>(() => ({
clientId: initialClientId,