Files
sam-react-prod/src/app/api/auth/check/route.ts

39 lines
1.0 KiB
TypeScript
Raw Normal View History

import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
/**
* Auth Check Route Handler
*
* Purpose:
* - Check if user is authenticated (HttpOnly cookie validation)
* - Prevent browser back button cache issues
* - Real-time authentication validation
*/
export async function GET(request: NextRequest) {
try {
// Get token from HttpOnly cookie
const token = request.cookies.get('user_token')?.value;
if (!token) {
return NextResponse.json(
{ error: 'Not authenticated', authenticated: false },
{ status: 401 }
);
}
// Optional: Verify token with PHP backend
// (현재는 토큰 존재 여부만 확인, 필요시 PHP API 호출 추가 가능)
return NextResponse.json(
{ authenticated: true },
{ status: 200 }
);
} catch (error) {
console.error('Auth check error:', error);
return NextResponse.json(
{ error: 'Internal server error', authenticated: false },
{ status: 500 }
);
}
}