Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 704 Bytes
f555806 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import { NextRequest, NextResponse } from 'next/server';
import { whoAmI } from '@huggingface/hub';
export async function POST(request: NextRequest) {
try {
const body = await request.json().catch(() => ({}));
const token = (body?.token || '').trim();
if (!token) {
return NextResponse.json({ error: 'Token is required' }, { status: 400 });
}
const info = await whoAmI({ accessToken: token });
return NextResponse.json({
name: info?.name || info?.username || 'user',
email: info?.email || null,
orgs: info?.orgs || [],
});
} catch (error: any) {
return NextResponse.json({ error: error?.message || 'Invalid token' }, { status: 401 });
}
}
|