Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 730 Bytes
b1a4d81 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import { json, type RequestEvent } from '@sveltejs/kit';
/** @type {import('./$types').RequestHandler} */
export async function GET(request : RequestEvent) {
if (!request.cookies.get('hf_access_token')) {
return json({
error: {
token: "You must be logged"
}
}, { status: 401 })
}
const response = await fetch("https://huggingface.co/oauth/userinfo", {
method: "GET",
headers: {
Authorization: `Bearer ${request.cookies.get('hf_access_token')}`,
},
})
const user = await response.clone().json().catch(() => ({}));
if (!user?.sub) {
return json({
error: {
token: "Token is invalid"
}
}, { status: 401 })
}
return json({
user
})
}
|