diff options
| author | mat <github@matdoes.dev> | 2022-12-15 18:14:46 -0600 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-12-15 18:14:46 -0600 |
| commit | 925ad2bfff17f8d9381731fb0050936dcd7e0a72 (patch) | |
| tree | 6f9fd4547ff9f883af1771bda5e85b7e0f5a56bd /src/routes/login | |
| parent | 6e723aadf6de45a79b4ef64d288ea275628232c5 (diff) | |
| download | skyblock-stats-925ad2bfff17f8d9381731fb0050936dcd7e0a72.tar.gz skyblock-stats-925ad2bfff17f8d9381731fb0050936dcd7e0a72.tar.bz2 skyblock-stats-925ad2bfff17f8d9381731fb0050936dcd7e0a72.zip | |
finish migrating to sveltekit v1
hopefully
Diffstat (limited to 'src/routes/login')
| -rw-r--r-- | src/routes/login/+page.ts | 36 | ||||
| -rw-r--r-- | src/routes/login/+server.ts | 18 |
2 files changed, 18 insertions, 36 deletions
diff --git a/src/routes/login/+page.ts b/src/routes/login/+page.ts deleted file mode 100644 index 1cd9b23..0000000 --- a/src/routes/login/+page.ts +++ /dev/null @@ -1,36 +0,0 @@ -import type { RequestHandler } from '@sveltejs/kit' -import env from '$lib/env' - - -export const get: RequestHandler = async ({ request, platform }) => { - const host = request.headers.get('host') - - const clientId = env(platform).DISCORD_CLIENT_ID - - if (!clientId) - return { - status: 500, - headers: { - 'content-type': 'text/plain', - }, - body: 'DISCORD_CLIENT_ID is not set as an environment variable. Please contact the owner of the website if this was expected to work.', - } - - if (!host) - return { - status: 400, - headers: { - 'content-type': 'text/plain', - }, - body: 'Host header is required.', - } - - const protocol = request.url.startsWith('https') ? 'https' : 'http' - - return { - status: 303, - headers: { - location: `https://discord.com/oauth2/authorize?client_id=${clientId}&redirect_uri=${protocol}://${host}%2Floggedin&response_type=code&scope=identify` - } - } -} diff --git a/src/routes/login/+server.ts b/src/routes/login/+server.ts new file mode 100644 index 0000000..684f11e --- /dev/null +++ b/src/routes/login/+server.ts @@ -0,0 +1,18 @@ +import env from '$lib/env' +import { error, redirect, type RequestHandler } from '@sveltejs/kit' + +export const GET = (async ({ request, platform }) => { + const host = request.headers.get('host') + + const clientId = env(platform).DISCORD_CLIENT_ID + + if (!clientId) + throw error(500, 'DISCORD_CLIENT_ID is not set as an environment variable. Please contact the owner of the website if this was expected to work.') + + if (!host) + throw error(400, 'Host header is required.') + + const protocol = request.url.startsWith('https') ? 'https' : 'http' + + throw redirect(303, `https://discord.com/oauth2/authorize?client_id=${clientId}&redirect_uri=${protocol}://${host}%2Floggedin&response_type=code&scope=identify`) +}) satisfies RequestHandler |
