import { NextResponse } from "next/server";
import { refreshSession } from "@/lib/threads-browser";

export const maxDuration = 60;

export async function POST() {
  try {
    const result = await refreshSession();
    return NextResponse.json(result, { status: result.valid ? 200 : 401 });
  } catch (error) {
    const message = error instanceof Error ? error.message : "更新 session 失敗";
    return NextResponse.json({ valid: false, message, refreshed: false }, { status: 500 });
  }
}