|
| 1 | +<script lang="ts"> |
| 2 | + import { goto } from '$app/navigation'; |
| 3 | + import { base } from '$app/paths'; |
| 4 | + import { |
| 5 | + PUBLIC_DISCORD_OAUTH_CLIENT_ID, |
| 6 | + PUBLIC_DISCORD_OAUTH_REDIRECT_URI, |
| 7 | + PUBLIC_DISCORD_OAUTH_REDIRECT_URI_TEST, |
| 8 | + PUBLIC_ENVIRONMENT |
| 9 | + } from '$env/static/public'; |
| 10 | + import discordImage from '$lib/images/discord.png'; |
| 11 | + import { clientFetch } from '$lib/other/clientFetch'; |
| 12 | + import type { OAuthAuthorizeQuery, OAuthAuthorizeQueryDiscord } from '$lib/types'; |
| 13 | + import { utility } from '$lib/utility/utility'; |
| 14 | + import { redirect } from '@sveltejs/kit'; |
| 15 | +
|
| 16 | + type Props = { |
| 17 | + text: string; |
| 18 | + className?: string; |
| 19 | + }; |
| 20 | +
|
| 21 | + let { text, className }: Props = $props(); |
| 22 | +
|
| 23 | + const onclick = async () => { |
| 24 | + const query: OAuthAuthorizeQueryDiscord = { |
| 25 | + client_id: PUBLIC_DISCORD_OAUTH_CLIENT_ID, |
| 26 | + redirect_uri: utility.getRedirectUri("discord"), |
| 27 | + response_type: 'code', |
| 28 | + scope: 'identify' |
| 29 | + }; |
| 30 | + |
| 31 | + const baseUrl = new URL('https://discord.com/oauth2/authorize'); |
| 32 | +
|
| 33 | + for (const [key, value] of utility.betterEntries(query)) { |
| 34 | + baseUrl.searchParams.set(key, value); |
| 35 | + } |
| 36 | +
|
| 37 | + window.location.href = baseUrl.toString(); |
| 38 | + }; |
| 39 | +</script> |
| 40 | + |
| 41 | +<button class={['button button-thin flex items-center gap-2', className]} {onclick}> |
| 42 | + <span class="font-xx-small">{text}</span> |
| 43 | + <img src={discordImage} alt="Icon for Discord" width={18} /> |
| 44 | +</button> |
| 45 | + |
| 46 | +<style> |
| 47 | + .button:hover { |
| 48 | + background-color: var(--color-discord-foreground); |
| 49 | + } |
| 50 | +
|
| 51 | + .button:hover img { |
| 52 | + filter: grayscale(100%); |
| 53 | + } |
| 54 | +</style> |
0 commit comments