update fallbackId
This commit is contained in:
parent
1a8f59e92b
commit
f714645b0c
1 changed files with 2 additions and 5 deletions
|
@ -429,25 +429,22 @@ const ChatWindow = ({id}: { id?: string }) => {
|
||||||
setUserId(storedUserId);
|
setUserId(storedUserId);
|
||||||
console.debug('Using existing user ID:', storedUserId);
|
console.debug('Using existing user ID:', storedUserId);
|
||||||
} else {
|
} else {
|
||||||
// 生成新的 MCID
|
|
||||||
const newUserId = new Mcid().generate().toString(); // 转换为字符串
|
const newUserId = new Mcid().generate().toString(); // 转换为字符串
|
||||||
|
|
||||||
// 存储到 localStorage
|
|
||||||
localStorage.setItem('userId', newUserId);
|
localStorage.setItem('userId', newUserId);
|
||||||
setUserId(newUserId);
|
setUserId(newUserId);
|
||||||
console.debug('Generated new user ID:', newUserId);
|
console.debug('Generated new user ID:', newUserId);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error initializing user ID:', error);
|
console.error('Error initializing user ID:', error);
|
||||||
// 生成随机 ID 作为 fallback
|
const fallbackId = "1234567890";
|
||||||
const fallbackId = crypto.randomBytes(20).toString('hex');
|
|
||||||
localStorage.setItem('userId', fallbackId);
|
localStorage.setItem('userId', fallbackId);
|
||||||
setUserId(fallbackId);
|
setUserId(fallbackId);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
initializeUserId();
|
initializeUserId();
|
||||||
}, []); // 空依赖数组确保只运行一次
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (
|
if (
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue