mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-11-16 01:21:16 +01:00
login expired
This commit is contained in:
parent
73dcbce95a
commit
1db931c94b
@ -3177,6 +3177,7 @@
|
|||||||
"rememberme": "Remember me",
|
"rememberme": "Remember me",
|
||||||
"invalid": "Invalid username or password.",
|
"invalid": "Invalid username or password.",
|
||||||
"locked": "Your account has been locked.",
|
"locked": "Your account has been locked.",
|
||||||
|
"sessionExpired": "Your session has expired. Please sign in again.",
|
||||||
"signinTitle": "Please sign in",
|
"signinTitle": "Please sign in",
|
||||||
"ssoSignIn": "Login via Single Sign-on",
|
"ssoSignIn": "Login via Single Sign-on",
|
||||||
"oAuth2AutoCreateDisabled": "OAUTH2 Auto-Create User Disabled",
|
"oAuth2AutoCreateDisabled": "OAUTH2 Auto-Create User Disabled",
|
||||||
|
|||||||
@ -93,18 +93,32 @@ export async function handleHttpError(error: any): Promise<boolean> {
|
|||||||
return false; // Don't show global toast, but continue rejection
|
return false; // Don't show global toast, but continue rejection
|
||||||
}
|
}
|
||||||
|
|
||||||
// Suppress "Authentication required" 401 errors on auth pages
|
// Handle 401 authentication errors
|
||||||
const status: number | undefined = error?.response?.status;
|
const status: number | undefined = error?.response?.status;
|
||||||
if (status === 401) {
|
if (status === 401) {
|
||||||
const pathname = window.location.pathname;
|
const pathname = window.location.pathname;
|
||||||
|
const errorMessage = error?.response?.data?.error || error?.response?.data?.message || '';
|
||||||
|
const isAuthenticationError = errorMessage.toLowerCase().includes('authentication');
|
||||||
|
|
||||||
|
// Check if we're already on an auth page
|
||||||
const isAuthPage = pathname.includes('/login') ||
|
const isAuthPage = pathname.includes('/login') ||
|
||||||
pathname.includes('/signup') ||
|
pathname.includes('/signup') ||
|
||||||
pathname.includes('/auth/') ||
|
pathname.includes('/auth/') ||
|
||||||
pathname.includes('/invite/');
|
pathname.includes('/invite/');
|
||||||
if (isAuthPage) {
|
|
||||||
console.debug('[httpErrorHandler] Suppressing 401 on auth page:', pathname);
|
// If not on auth page, redirect to login with expired session message
|
||||||
return true; // Suppress toast
|
if (!isAuthPage) {
|
||||||
|
console.debug('[httpErrorHandler] 401 detected, redirecting to login');
|
||||||
|
// Store the current location so we can redirect back after login
|
||||||
|
const currentLocation = window.location.pathname + window.location.search;
|
||||||
|
// Redirect to login with state
|
||||||
|
window.location.href = `/login?expired=true&from=${encodeURIComponent(currentLocation)}`;
|
||||||
|
return true; // Suppress toast since we're redirecting
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// On auth pages, suppress the toast (user is already trying to authenticate)
|
||||||
|
console.debug('[httpErrorHandler] Suppressing 401 on auth page:', pathname);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
// Compute title/body (friendly) from the error object
|
// Compute title/body (friendly) from the error object
|
||||||
const { title, body } = extractAxiosErrorMessage(error);
|
const { title, body } = extractAxiosErrorMessage(error);
|
||||||
|
|||||||
@ -95,13 +95,7 @@ export default function Landing() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're at home route ("/"), show login directly (marketing/landing page)
|
// No session - redirect to login page
|
||||||
// Otherwise navigate to login (fixes URL mismatch for tool routes)
|
// This ensures the URL always shows /login when not authenticated
|
||||||
const isHome = location.pathname === '/' || location.pathname === '';
|
|
||||||
if (isHome) {
|
|
||||||
return <Login />;
|
|
||||||
}
|
|
||||||
|
|
||||||
// For non-home routes without auth, navigate to login (preserves from location)
|
|
||||||
return <Navigate to="/login" replace state={{ from: location }} />;
|
return <Navigate to="/login" replace state={{ from: location }} />;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -74,7 +74,7 @@ export default function Login() {
|
|||||||
}
|
}
|
||||||
}, [enabledProviders]);
|
}, [enabledProviders]);
|
||||||
|
|
||||||
// Handle query params (email prefill and success messages)
|
// Handle query params (email prefill, success messages, and session expiry)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
try {
|
try {
|
||||||
const emailFromQuery = searchParams.get('email');
|
const emailFromQuery = searchParams.get('email');
|
||||||
@ -82,6 +82,12 @@ export default function Login() {
|
|||||||
setEmail(emailFromQuery);
|
setEmail(emailFromQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if session expired (401 redirect)
|
||||||
|
const expired = searchParams.get('expired');
|
||||||
|
if (expired === 'true') {
|
||||||
|
setError(t('login.sessionExpired', 'Your session has expired. Please sign in again.'));
|
||||||
|
}
|
||||||
|
|
||||||
const messageType = searchParams.get('messageType')
|
const messageType = searchParams.get('messageType')
|
||||||
if (messageType) {
|
if (messageType) {
|
||||||
switch (messageType) {
|
switch (messageType) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user