Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/debug/auth-debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
export function debugAuthIssues(request: NextRequest) {
const isProduction = process.env.NODE_ENV === 'production';

console.log('debugAuthIssues called', { isProduction, path: request.nextUrl.pathname });

if (!isProduction) {
return null;
}
Expand All @@ -37,9 +39,9 @@
userPoolId: outputs.auth?.user_pool_id,
region: outputs.auth?.aws_region,
clientId: outputs.auth?.user_pool_client_id,
identityPoolId: outputs.auth?.identity_pool_id,

Check failure on line 42 in lib/debug/auth-debug.ts

View workflow job for this annotation

GitHub Actions / build

Property 'identity_pool_id' does not exist on type '{ user_pool_id: string; aws_region: string; user_pool_client_id: string; }'.
oauthDomain: outputs.auth?.oauth?.domain,

Check failure on line 43 in lib/debug/auth-debug.ts

View workflow job for this annotation

GitHub Actions / build

Property 'oauth' does not exist on type '{ user_pool_id: string; aws_region: string; user_pool_client_id: string; }'.
redirectUris: outputs.auth?.oauth?.redirect_sign_in_uri,

Check failure on line 44 in lib/debug/auth-debug.ts

View workflow job for this annotation

GitHub Actions / build

Property 'oauth' does not exist on type '{ user_pool_id: string; aws_region: string; user_pool_client_id: string; }'.
};

// Verificar cookies de Cognito
Expand Down Expand Up @@ -106,8 +108,8 @@
}

// Verificar que las URLs de redirección incluyan el dominio de producción
const redirectUris = outputs.auth?.oauth?.redirect_sign_in_uri || [];

Check failure on line 111 in lib/debug/auth-debug.ts

View workflow job for this annotation

GitHub Actions / build

Property 'oauth' does not exist on type '{ user_pool_id: string; aws_region: string; user_pool_client_id: string; }'.
const hasProductionUrl = redirectUris.some((uri) => uri.includes('fasttify.com') || uri.includes('www.fasttify.com'));

Check failure on line 112 in lib/debug/auth-debug.ts

View workflow job for this annotation

GitHub Actions / build

Parameter 'uri' implicitly has an 'any' type.

if (!hasProductionUrl) {
console.error('No production redirect URI found in Amplify config');
Expand Down
11 changes: 11 additions & 0 deletions middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,17 @@ async function executeHandlers(
* @returns Respuesta procesada por los middlewares
*/
export async function middleware(request: NextRequest): Promise<NextResponse> {
const isProduction = process.env.NODE_ENV === 'production';

// Log de entrada del middleware principal
if (isProduction) {
console.log('Main middleware called:', {
path: request.nextUrl.pathname,
method: request.method,
timestamp: new Date().toISOString(),
});
}

// Definir la cadena de handlers en orden de ejecución
const handlers: MiddlewareHandler[] = [
handleOAuthProtection,
Expand Down
17 changes: 16 additions & 1 deletion middlewares/auth/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,18 @@ export async function getSession(request: NextRequest, response: NextResponse, f
}

export async function handleAuthenticationMiddleware(request: NextRequest, response: NextResponse) {
// Validar configuración de Amplify en producción
const isProduction = process.env.NODE_ENV === 'production';

// Log de entrada para debugging
if (isProduction) {
console.log('Auth middleware called:', {
path: request.nextUrl.pathname,
method: request.method,
timestamp: new Date().toISOString(),
});
}

// Validar configuración de Amplify en producción
if (isProduction && !validateAmplifyConfig()) {
console.error('Invalid Amplify configuration detected');
}
Expand All @@ -154,6 +164,7 @@ export async function handleAuthenticationMiddleware(request: NextRequest, respo
if (!session) {
// Debug detallado en producción
if (isProduction) {
console.log('No session found, running debug...');
debugAuthIssues(request);
}

Expand All @@ -162,6 +173,10 @@ export async function handleAuthenticationMiddleware(request: NextRequest, respo
return NextResponse.redirect(new URL('/login', request.url), { status: 302 });
}

if (isProduction) {
console.log('Session found, continuing...');
}

return null; // Permitir que el middleware continúe
}

Expand Down
Loading