Add WeChat auth entry for H5

This commit is contained in:
2026-07-05 19:48:32 +08:00
parent a4b59add07
commit fa2d82333c
4 changed files with 100 additions and 5 deletions

View File

@@ -128,6 +128,20 @@ export default function H5QAExperience() {
.finally(() => setLoadingQa(false));
}, []);
useEffect(() => {
const params = new URLSearchParams(window.location.search);
const code = params.get("code");
const state = params.get("state");
if (code && state === "hyqa_h5") {
setUser({
mode: "wechat",
name: "微信已授权",
phone: "等待后端换取登录态"
});
window.history.replaceState(null, "", window.location.pathname);
}
}, []);
useEffect(() => {
bottomRef.current?.scrollIntoView({ behavior: "smooth", block: "end" });
}, [messages, activeTab]);
@@ -141,6 +155,15 @@ export default function H5QAExperience() {
setAuthOpen(false);
}
function mockWechatLogin() {
setUser({
mode: "wechat",
name: "微信用户",
phone: "微信授权演示"
});
setAuthOpen(false);
}
function persistMessages(nextMessages: ChatMessage[]) {
setMessages(nextMessages);
setSessions((current) => {
@@ -413,6 +436,7 @@ export default function H5QAExperience() {
user={user}
onClose={() => setAuthOpen(false)}
onMockLogin={mockLogin}
onWechatMockLogin={mockWechatLogin}
onLogout={() => {
setUser(null);
setAuthOpen(false);