web: open reset form immediately for reset links
This commit is contained in:
@@ -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 />
|
||||
|
||||
Reference in New Issue
Block a user