From 32038bde3beef9736668685f765b5642ed2418d1 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Mon, 1 Jan 2024 21:54:47 -0800 Subject: feat(oauth): add animeschedule back --- .../api/oauth/animeschedule/callback/+server.ts | 35 ++++++++++++++++++++++ .../oauth/animeschedule/callback/+server.ts.bak | 35 ---------------------- 2 files changed, 35 insertions(+), 35 deletions(-) create mode 100644 src/routes/api/oauth/animeschedule/callback/+server.ts delete mode 100644 src/routes/api/oauth/animeschedule/callback/+server.ts.bak (limited to 'src/routes/api/oauth/animeschedule/callback') diff --git a/src/routes/api/oauth/animeschedule/callback/+server.ts b/src/routes/api/oauth/animeschedule/callback/+server.ts new file mode 100644 index 00000000..2364d071 --- /dev/null +++ b/src/routes/api/oauth/animeschedule/callback/+server.ts @@ -0,0 +1,35 @@ +import { dev } from '$app/environment'; +import { env } from '$env/dynamic/private'; +import { env as env2 } from '$env/dynamic/public'; +import { redirect } from '@sveltejs/kit'; + +export const GET = async ({ url, cookies }) => { + const formData = new FormData(); + + formData.append('grant_type', 'authorization_code'); + formData.append('client_id', env2.PUBLIC_ANIMESCHEDULE_CLIENT_ID as string); + formData.append('client_secret', env.ANIMESCHEDULE_CLIENT_SECRET as string); + formData.append('redirect_uri', env2.PUBLIC_ANIMESCHEDULE_REDIRECT_URI as string); + formData.append('code', url.searchParams.get('code') || 'null'); + console.log('code', url.searchParams); + cookies.set( + 'animeschedule', + JSON.stringify( + await ( + await fetch('https://animeschedule.net/api/v3/oauth2/token', { + method: 'POST', + body: formData + }) + ).json() + ), + { + path: '/', + maxAge: 60 * 60 * 24 * 7, + httpOnly: true, + sameSite: 'lax', + secure: !dev + } + ); + + throw redirect(303, '/settings'); +}; diff --git a/src/routes/api/oauth/animeschedule/callback/+server.ts.bak b/src/routes/api/oauth/animeschedule/callback/+server.ts.bak deleted file mode 100644 index 2364d071..00000000 --- a/src/routes/api/oauth/animeschedule/callback/+server.ts.bak +++ /dev/null @@ -1,35 +0,0 @@ -import { dev } from '$app/environment'; -import { env } from '$env/dynamic/private'; -import { env as env2 } from '$env/dynamic/public'; -import { redirect } from '@sveltejs/kit'; - -export const GET = async ({ url, cookies }) => { - const formData = new FormData(); - - formData.append('grant_type', 'authorization_code'); - formData.append('client_id', env2.PUBLIC_ANIMESCHEDULE_CLIENT_ID as string); - formData.append('client_secret', env.ANIMESCHEDULE_CLIENT_SECRET as string); - formData.append('redirect_uri', env2.PUBLIC_ANIMESCHEDULE_REDIRECT_URI as string); - formData.append('code', url.searchParams.get('code') || 'null'); - console.log('code', url.searchParams); - cookies.set( - 'animeschedule', - JSON.stringify( - await ( - await fetch('https://animeschedule.net/api/v3/oauth2/token', { - method: 'POST', - body: formData - }) - ).json() - ), - { - path: '/', - maxAge: 60 * 60 * 24 * 7, - httpOnly: true, - sameSite: 'lax', - secure: !dev - } - ); - - throw redirect(303, '/settings'); -}; -- cgit v1.2.3