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>
This commit is contained in:
john
2026-07-11 13:05:44 +08:00
parent 3163445a9d
commit 57a60d41d7
7 changed files with 101 additions and 16 deletions
+29 -2
View File
@@ -30,10 +30,30 @@ Page({
},
async onShow() {
if (this._authCheckPromise) {
await this._authCheckPromise;
return;
}
this._authCheckPromise = this.verifyAccess();
try {
await this._authCheckPromise;
} finally {
this._authCheckPromise = null;
}
},
async verifyAccess() {
if (this._redirectingToLogin) return;
try {
const status = await checkAuth();
if (!status?.authenticated) {
wx.redirectTo({ url: '/pages/login/index' });
this._redirectingToLogin = true;
wx.redirectTo({
url: '/pages/login/index',
complete: () => {
this._redirectingToLogin = false;
},
});
return;
}
await this.ensureCurrentUser();
@@ -47,7 +67,14 @@ Page({
await this.refreshSession(this.data.sessionId);
}
} catch {
wx.redirectTo({ url: '/pages/login/index' });
if (this._redirectingToLogin) return;
this._redirectingToLogin = true;
wx.redirectTo({
url: '/pages/login/index',
complete: () => {
this._redirectingToLogin = false;
},
});
}
},
+2 -2
View File
@@ -17,7 +17,7 @@
<view wx:for="{{messages}}" wx:key="id" id="msg-{{index}}" class="message-row {{item.role}}">
<view class="message {{item.role}}">
<view class="message-body">
<block wx:for="{{item.parts}}" wx:for-item="part" wx:for-index="partIndex" wx:key="partIndex">
<block wx:for="{{item.parts || []}}" wx:for-item="part" wx:for-index="partIndex" wx:key="partIndex">
<text wx:if="{{part.type === 'text'}}" class="message-text">{{part.text}}</text>
<text
wx:elif="{{part.type === 'link'}}"
@@ -27,7 +27,7 @@
>{{part.text}}</text>
</block>
</view>
<view wx:if="{{item.pageLinks.length}}" class="page-links">
<view wx:if="{{item.pageLinks && item.pageLinks.length}}" class="page-links">
<view
wx:for="{{item.pageLinks}}"
wx:for-item="page"
+4
View File
@@ -43,6 +43,10 @@ Page({
try {
const status = await checkAuth();
if (status?.authenticated) {
const app = getApp();
if (status.user) {
app.globalData.user = status.user;
}
wx.switchTab({ url: '/pages/chat/index' });
}
} catch {