web: open reset form immediately for reset links
Some checks failed
Android CI / android (push) Failing after 5m33s
Android Release / release (push) Has started running
CI / test (push) Has been cancelled

This commit is contained in:
Codex
2026-03-09 21:55:42 +03:00
parent 776a7634d2
commit 28f7da5f41
2 changed files with 29 additions and 13 deletions

View File

@@ -15,6 +15,15 @@ const PENDING_NOTIFICATION_NAV_KEY = "bm_pending_notification_nav";
const PENDING_RESET_PASSWORD_TOKEN_KEY = "bm_pending_reset_password_token";
export function App() {
const [pendingResetToken, setPendingResetToken] = useState<string | null>(() => {
const tokenFromLink = extractPasswordResetTokenFromLocation();
if (tokenFromLink) {
window.localStorage.setItem(PENDING_RESET_PASSWORD_TOKEN_KEY, tokenFromLink);
window.history.replaceState(null, "", "/");
return tokenFromLink;
}
return window.localStorage.getItem(PENDING_RESET_PASSWORD_TOKEN_KEY);
});
const accessToken = useAuthStore((s) => s.accessToken);
const me = useAuthStore((s) => s.me);
const loadMe = useAuthStore((s) => s.loadMe);
@@ -71,16 +80,10 @@ export function App() {
}, []);
useEffect(() => {
const resetToken = extractPasswordResetTokenFromLocation();
if (!resetToken) {
return;
}
window.localStorage.setItem(PENDING_RESET_PASSWORD_TOKEN_KEY, resetToken);
if (accessToken) {
if (pendingResetToken && accessToken) {
logout();
}
window.history.replaceState(null, "", "/");
}, [accessToken, logout]);
}, [pendingResetToken, accessToken, logout]);
useEffect(() => {
const nav = extractNotificationNavigationFromLocation();
@@ -154,15 +157,20 @@ export function App() {
})();
}, [accessToken, joiningInvite, loadChats, me, setActiveChatId, setFocusedMessage, showToast]);
if (!accessToken || !me) {
const pendingResetToken = window.localStorage.getItem(PENDING_RESET_PASSWORD_TOKEN_KEY);
if (pendingResetToken) {
return (
<AuthPage
initialResetToken={pendingResetToken}
onResetTokenConsumed={() => window.localStorage.removeItem(PENDING_RESET_PASSWORD_TOKEN_KEY)}
onResetTokenConsumed={() => {
window.localStorage.removeItem(PENDING_RESET_PASSWORD_TOKEN_KEY);
setPendingResetToken(null);
}}
/>
);
}
if (!accessToken || !me) {
return <AuthPage />;
}
return (
<>
<ChatsPage />