enzostvs HF Staff commited on
Commit
f3e5514
·
1 Parent(s): 557f95d
Files changed (1) hide show
  1. src/routes/api/auth/+server.ts +8 -7
src/routes/api/auth/+server.ts CHANGED
@@ -2,7 +2,7 @@
2
 
3
  import { json } from '@sveltejs/kit';
4
 
5
- export async function POST({ request, fetch }) {
6
  const { code } = await request.json()
7
 
8
  if (!code) {
@@ -20,21 +20,22 @@ export async function POST({ request, fetch }) {
20
  `${process.env.OAUTH_CLIENT_ID}:${process.env.OAUTH_CLIENT_SECRET}`
21
  ).toString("base64")}`;
22
 
23
- const formData = new FormData();
24
- formData.append("grant_type", "authorization_code");
25
- formData.append("code", code);
26
- formData.append("redirect_uri", REDIRECT_URI);
27
-
28
  const request_auth = await fetch("https://huggingface.co/oauth/token", {
29
  method: "POST",
30
  headers: {
31
  "Content-Type": "application/x-www-form-urlencoded",
32
  Authorization,
33
  },
34
- body: formData,
 
 
 
 
35
  });
36
 
 
37
  const { access_token } = await request_auth.json();
 
38
 
39
  if (!access_token) {
40
  return json({
 
2
 
3
  import { json } from '@sveltejs/kit';
4
 
5
+ export async function POST({ request }) {
6
  const { code } = await request.json()
7
 
8
  if (!code) {
 
20
  `${process.env.OAUTH_CLIENT_ID}:${process.env.OAUTH_CLIENT_SECRET}`
21
  ).toString("base64")}`;
22
 
 
 
 
 
 
23
  const request_auth = await fetch("https://huggingface.co/oauth/token", {
24
  method: "POST",
25
  headers: {
26
  "Content-Type": "application/x-www-form-urlencoded",
27
  Authorization,
28
  },
29
+ body: new URLSearchParams({
30
+ grant_type: "authorization_code",
31
+ code: code,
32
+ redirect_uri: REDIRECT_URI,
33
+ }),
34
  });
35
 
36
+ const data = await request_auth.json();
37
  const { access_token } = await request_auth.json();
38
+ console.log('ac', data)
39
 
40
  if (!access_token) {
41
  return json({