feat: 使 Nakama custom ID 持久化以确保用户身份一致性

This commit is contained in:
邹方成 2026-01-03 22:34:01 +08:00
parent 83377543f8
commit 241722e1af

View File

@ -77,9 +77,13 @@ class NakamaManager {
async authenticateWithGameToken(gameToken) {
this.gameToken = gameToken;
// 生成唯一的 custom ID
const customId = `game_${Date.now()}_${Math.random().toString(36).substring(7)}`;
console.log('[Nakama] Authenticating with Custom ID:', customId);
// 获取或生成持久化的 custom ID
let customId = uni.getStorageSync('nakama_custom_id');
if (!customId) {
customId = `game_${Date.now()}_${Math.random().toString(36).substring(7)}`;
uni.setStorageSync('nakama_custom_id', customId);
}
console.log('[Nakama] Authenticating with Persistent ID:', customId);
// HTTP 认证请求
const scheme = this.useSSL ? 'https://' : 'http://';