diff options
| author | Fuwn <[email protected]> | 2023-12-08 12:33:29 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-12-08 12:33:29 -0800 |
| commit | 602fd66ca3c19d59b31855bef98058a05fca9975 (patch) | |
| tree | d7800b9f0d1282f4ff807dbbfa208c17e12eb329 /src | |
| parent | feat(wrapped): update on filter (diff) | |
| download | due.moe-602fd66ca3c19d59b31855bef98058a05fca9975.tar.xz due.moe-602fd66ca3c19d59b31855bef98058a05fca9975.zip | |
feat: https and animeschedule oauth
Diffstat (limited to 'src')
| -rw-r--r-- | src/routes/api/oauth/animeschedule/callback/+server.ts.bak | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/routes/api/oauth/animeschedule/callback/+server.ts.bak b/src/routes/api/oauth/animeschedule/callback/+server.ts.bak new file mode 100644 index 00000000..2364d071 --- /dev/null +++ b/src/routes/api/oauth/animeschedule/callback/+server.ts.bak @@ -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'); +}; |