Files
john 57a60d41d7 fix(miniapp): persist session token for WeChat login
Return sessionToken from login endpoints and store it client-side because
wx.request cannot rely on Set-Cookie. Also fix multi-cookie parsing,
start on login page, and guard chat rendering fields.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-11 13:05:44 +08:00

40 lines
1.2 KiB
JavaScript

// Production default for miniapp release / 提审.
// Local Portal debug: set LOCAL_DEV = true, or copy config.local.example.js → config.local.js
const LOCAL_DEV = false;
function createUuid() {
const bytes = [];
for (let i = 0; i < 16; i += 1) {
bytes.push(Math.floor(Math.random() * 256));
}
bytes[6] = (bytes[6] & 0x0f) | 0x40;
bytes[8] = (bytes[8] & 0x3f) | 0x80;
const hex = bytes.map((byte) => byte.toString(16).padStart(2, '0')).join('');
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
}
const defaults = {
API_BASE_URL: LOCAL_DEV ? 'http://127.0.0.1:8081' : 'https://m.tkmind.cn',
MINIAPP_LOGIN_PATH: '/auth/wechat-miniapp/login',
SESSION_COOKIE_NAME: 'tkmind_user_session',
SELECTED_SESSION_KEY: 'tkmind_selected_session_id',
AGENT_RUN_POLL_MS: 1200,
AGENT_RUN_MAX_POLLS: 120,
};
let localOverrides = {};
try {
localOverrides = require('./config.local.js');
} catch {
// Optional gitignored overrides in utils/config.local.js
}
module.exports = {
createUuid,
...defaults,
...localOverrides,
...(localOverrides.API_BASE_URL
? { API_BASE_URL: String(localOverrides.API_BASE_URL).replace(/\/$/, '') }
: {}),
};