feat(rednote): add isolated persistent browser H5 entry

This commit is contained in:
xsl
2026-10-19 22:59:10 +08:00
parent 9eec4369da
commit 4af825a5e4
24 changed files with 707 additions and 45 deletions
+8 -3
View File
@@ -1,8 +1,10 @@
/* Guest access uses an ephemeral server session, never a saved browser identity. */
window.AccountClient = (function () {
'use strict';
var kindKey = 'juzi.auth.kind.v1', user = null, guestReady = false;
var rednote = !!(window.JuziEntry && window.JuziEntry.mode === 'rednote');
var kindKey = rednote ? 'juzi.rednote.auth.kind.v1' : 'juzi.auth.kind.v1', user = null, guestReady = false;
function clearGuestCache() {
if (rednote) return;
try {
localStorage.removeItem('juzi.identity.v1');
localStorage.removeItem('juzi.reports.v1'); // Retired local guest-report cache.
@@ -12,7 +14,7 @@ window.AccountClient = (function () {
} catch (_) {}
}
function rememberKind() {
try { if (user && user.kind === 'wechat') localStorage.setItem(kindKey, 'wechat'); else localStorage.removeItem(kindKey); } catch (_) {}
try { if (user && (user.kind === 'wechat' || (rednote && user.kind === 'browser_persistent'))) localStorage.setItem(kindKey, user.kind); else localStorage.removeItem(kindKey); } catch (_) {}
}
function request(url, data) {
var controller = new AbortController();
@@ -43,7 +45,7 @@ window.AccountClient = (function () {
function ensureGuest() {
// The visitor entry is entirely local. Create temporary server access only
// after explicit consent in the welcome dialog, not on entry/button tap.
if (!user || user.kind === 'wechat' || guestReady) return Promise.resolve({ user: user });
if (!user || user.kind === 'wechat' || (rednote && user.kind === 'browser_persistent') || guestReady) return Promise.resolve({ user: user });
return browser(true);
}
function init(options) {
@@ -58,6 +60,9 @@ window.AccountClient = (function () {
}
function logout() {
return request('api/auth/logout', {}).then(function (v) {
if (rednote && user) {
try { localStorage.removeItem('juzi.rednote.profile.v1.browser_persistent.' + encodeURIComponent(user.id)); } catch (_) {}
}
user = null; guestReady = false; rememberKind(); return v;
});
}