fix and update

This commit is contained in:
lendry
2026-07-07 08:14:26 +03:00
parent 9ca5071f1a
commit cddb29fef6
3 changed files with 50 additions and 5 deletions

View File

@@ -655,8 +655,6 @@ export default function LoginPage() {
await completePin(pendingSessionId, pin); await completePin(pendingSessionId, pin);
finishLoginRedirect();
} catch (error) { } catch (error) {
showToast(error instanceof Error ? error.message : 'Не удалось проверить PIN-код'); showToast(error instanceof Error ? error.message : 'Не удалось проверить PIN-код');

View File

@@ -34,6 +34,7 @@ import {
subscribeApiReady, subscribeApiReady,
subscribeApiNotReady, subscribeApiNotReady,
} from '@/lib/api'; } from '@/lib/api';
import { resolvePostPinAuthRedirect } from '@/lib/auth-post-pin-redirect';
import { finalizeFedcmLogin, isFedcmLoginPopup, shouldFinalizeFedcmLogin } from '@/lib/fedcm-login-bridge'; import { finalizeFedcmLogin, isFedcmLoginPopup, shouldFinalizeFedcmLogin } from '@/lib/fedcm-login-bridge';
import { FedcmApiLoginStatusBridge } from './fedcm-api-login-status'; import { FedcmApiLoginStatusBridge } from './fedcm-api-login-status';
import { usePublicSettings } from './public-settings-provider'; import { usePublicSettings } from './public-settings-provider';
@@ -682,12 +683,25 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
setIsLoading(false); setIsLoading(false);
} }
if (pathname.startsWith('/auth/') && !isFedcmLoginPopup()) { if (isFedcmLoginPopup()) {
router.replace('/'); await finalizeFedcmLogin(response.accessToken);
return; return;
} }
if (shouldFinalizeFedcmLogin(pathname) || isFedcmLoginPopup()) { const postPinRedirect =
typeof window !== 'undefined'
? resolvePostPinAuthRedirect(pathname, window.location.search)
: null;
if (postPinRedirect !== null) {
if (shouldFinalizeFedcmLogin(pathname)) {
await finalizeFedcmLogin(response.accessToken);
}
router.replace(postPinRedirect);
return;
}
if (shouldFinalizeFedcmLogin(pathname)) {
await finalizeFedcmLogin(response.accessToken); await finalizeFedcmLogin(response.accessToken);
} }
}, },

View File

@@ -0,0 +1,33 @@
/** Безопасный внутренний путь для post-login/post-pin редиректа (без open redirect). */
export function isSafeInternalRedirect(path: string): boolean {
if (!path.startsWith('/') || path.startsWith('//')) return false;
if (path.includes('://')) return false;
return true;
}
export function readPostAuthRedirect(search: string): string | null {
if (typeof window === 'undefined') return null;
const redirect = new URLSearchParams(search).get('redirect');
if (!redirect || !isSafeInternalRedirect(redirect)) return null;
return redirect;
}
/**
* Куда перейти после успешного ввода PIN на auth-страницах.
* null — остаться на текущей странице (OAuth consent, основное приложение).
*/
export function resolvePostPinAuthRedirect(pathname: string, search = ''): string | null {
if (pathname.startsWith('/auth/oauth/authorize')) {
return null;
}
if (pathname.startsWith('/auth/login') || pathname.startsWith('/auth/register')) {
return readPostAuthRedirect(search) ?? '/';
}
if (pathname.startsWith('/auth/')) {
return '/';
}
return null;
}