support adding to spotify playlist
This commit is contained in:
28
src/routes/spotifyAuth/+page.server.ts
Normal file
28
src/routes/spotifyAuth/+page.server.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { log } from '$lib/log';
|
||||
import { SpotifyPlaylistAdder } from '$lib/server/spotifyPlaylistAdder';
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
import type { PageServerLoad } from './$types';
|
||||
|
||||
export const load: PageServerLoad = async ({ url }) => {
|
||||
const adder = new SpotifyPlaylistAdder();
|
||||
let redirectUri = url;
|
||||
if (url.hostname === 'localhost') {
|
||||
redirectUri.hostname = '127.0.0.1';
|
||||
}
|
||||
log.debug(url.searchParams, url.hostname);
|
||||
if (url.searchParams.has('code')) {
|
||||
await adder.receivedAuthCode(url.searchParams.get('code') || '', url);
|
||||
redirect(307, '/');
|
||||
} else if (url.searchParams.has('error')) {
|
||||
log.error('received error', url.searchParams.get('error'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (await adder.authCodeExists()) {
|
||||
redirect(307, '/');
|
||||
}
|
||||
|
||||
const authUrl = adder.constructAuthUrl(url);
|
||||
log.debug('+page.server.ts', authUrl.toString());
|
||||
redirect(307, authUrl);
|
||||
};
|
1
src/routes/spotifyAuth/+page.svelte
Normal file
1
src/routes/spotifyAuth/+page.svelte
Normal file
@ -0,0 +1 @@
|
||||
<h1>Something went wrong</h1>
|
@ -1,2 +1 @@
|
||||
<h1>Hello and welcome to my site!</h1>
|
||||
<a href="/about">About my site</a>
|
||||
<h1>Something went wrong</h1>
|
||||
|
Reference in New Issue
Block a user