feat: use login(userId, userSig) with demo API pre-fetch

这个提交包含在:
徐勤民 2026-05-02 12:53:19 +08:00
父节点 ac72012443
当前提交 cfc3769dbd

查看文件

@ -35,7 +35,23 @@ Page({
this.setData({ loading: true, error: '' })
try {
const sdk = app.globalData.sdk
await sdk.loginWithDemo(userId, password)
const config = sdk.requireConfig()
// 1. Call demo API to get userSig
const res = await new Promise((resolve, reject) => {
wx.request({
url: `${config.apiUrl}/api/demo/auth/login`,
method: 'POST',
header: { 'Content-Type': 'application/json' },
data: { appId: config.appKey, userId, password },
success: (r) => resolve(r.data),
fail: (err) => reject(err),
})
})
if (res.code !== 200) {
throw new Error(res.message || '登录失败')
}
// 2. Login with userSig
await sdk.login(userId, res.data.imToken)
app.globalData.userId = userId
wx.navigateTo({ url: '/pages/chat/chat' })
} catch (err) {