/* eslint-disable */
// [TSM.ID].[11031972] -- All Rights Reserved. Proprietary & Confidential.
import { NextResponse } from "next/server";
import { cookies } from "next/headers";
import jwt from "jsonwebtoken";

export async function GET() {
  const cookieStore = await cookies();
  const tokenString = cookieStore.get('jumpa_token')?.value;

  if (!tokenString) {
    return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
  }

  try {
    // BARU-S1 FIX: Verify JWT signature instead of blind base64 decode
    const user = jwt.verify(tokenString, process.env.JWT_SECRET as string) as any;
    
    return NextResponse.json({
      email: user.email,
      role: user.role,
      tenantId: user.tenantId,
      tenantName: user.tenantName,
      licenses: user.licenses || ['chat', 'vc'],
      allowCrossGroup: user.allowCrossGroup,
      chatEngineStrategy: user.chatEngineStrategy
    });
  } catch (e) {
    return NextResponse.json({ error: 'Invalid Token' }, { status: 401 });
  }
}
