Cleanup, fixing YT/Spotify auth

This commit is contained in:
2025-07-04 13:37:37 +02:00
parent dfd6d559bf
commit 270cd9ad05
11 changed files with 133 additions and 69 deletions

View File

@ -1,3 +1,4 @@
import { BASE_URL } from '$env/static/private';
import { Logger } from '$lib/log';
import { YoutubePlaylistAdder } from '$lib/server/playlist/ytPlaylistAdder';
import { redirect } from '@sveltejs/kit';
@ -7,9 +8,10 @@ const logger = new Logger('YT Auth');
export const load: PageServerLoad = async ({ url }) => {
const adder = new YoutubePlaylistAdder();
const redirect_uri = new URL(`${BASE_URL}/ytauth`);
if (url.searchParams.has('code')) {
logger.debug(url.searchParams);
await adder.receivedAuthCode(url.searchParams.get('code') || '', url);
await adder.receivedAuthCode(url.searchParams.get('code') || '', redirect_uri);
redirect(307, '/');
} else if (url.searchParams.has('error')) {
logger.error('received error', url.searchParams.get('error'));
@ -19,8 +21,7 @@ export const load: PageServerLoad = async ({ url }) => {
if (await adder.authCodeExists()) {
redirect(307, '/');
}
const authUrl = adder.constructAuthUrl(url);
const authUrl = adder.constructAuthUrl(redirect_uri);
logger.debug('+page.server.ts', authUrl.toString());
redirect(307, authUrl);
};