feat: Enhance login functionality with Discord integration and improve code formatting
Some checks failed
SteamWarCI Build failed
Some checks failed
SteamWarCI Build failed
This commit is contained in:
@@ -18,12 +18,14 @@
|
||||
-->
|
||||
|
||||
<script lang="ts">
|
||||
import { preventDefault } from 'svelte/legacy';
|
||||
import { preventDefault } from "svelte/legacy";
|
||||
|
||||
import {l} from "@utils/util.ts";
|
||||
import {t} from "astro-i18n";
|
||||
import {get} from "svelte/store";
|
||||
import {navigate} from "astro:transitions/client";
|
||||
import { l } from "@utils/util.ts";
|
||||
import { t } from "astro-i18n";
|
||||
import { get } from "svelte/store";
|
||||
import { navigate } from "astro:transitions/client";
|
||||
import { onMount } from "svelte";
|
||||
import { authV2Repo } from "./repo/authv2.ts";
|
||||
|
||||
let username: string = $state("");
|
||||
let pw: string = $state("");
|
||||
@@ -31,7 +33,7 @@
|
||||
let error: string = $state("");
|
||||
|
||||
async function login() {
|
||||
let {authV2Repo} = await import("./repo/authv2.ts");
|
||||
let { authV2Repo } = await import("./repo/authv2.ts");
|
||||
if (username === "" || pw === "") {
|
||||
pw = "";
|
||||
error = t("login.error");
|
||||
@@ -52,6 +54,24 @@
|
||||
error = t("login.error");
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
if (window.location.hash.includes("access_token")) {
|
||||
const params = new URLSearchParams(window.location.hash.substring(1));
|
||||
const accessToken = params.get("access_token");
|
||||
|
||||
if (accessToken) {
|
||||
let auth = $authV2Repo.loginDiscord(accessToken);
|
||||
if (!auth) {
|
||||
pw = "";
|
||||
error = t("login.error");
|
||||
return;
|
||||
}
|
||||
|
||||
navigate(l("/dashboard"));
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<form class="bg-gray-100 dark:bg-neutral-900 p-12 rounded-2xl shadow-2xl border-2 border-gray-600 flex flex-col" onsubmit={preventDefault(login)}>
|
||||
@@ -63,12 +83,19 @@
|
||||
<input type="password" id="password" name="password" placeholder={t("login.placeholder.password")} bind:value={pw} />
|
||||
</div>
|
||||
<p class="mt-2">
|
||||
<a class="text-neutral-500 hover:underline" href={l("/set-password")}>{t("login.setPassword")}</a></p>
|
||||
<a class="text-neutral-500 hover:underline" href={l("/set-password")}>{t("login.setPassword")}</a>
|
||||
</p>
|
||||
|
||||
{#if error}
|
||||
<p class="mt-2 text-red-500">{error}</p>
|
||||
{/if}
|
||||
<button class="btn mt-4 !mx-0 justify-center" type="submit" onclick={preventDefault(login)}>{t("login.submit")}</button>
|
||||
<a
|
||||
class="btn mt-4 !mx-0 justify-center"
|
||||
href="https://discord.com/oauth2/authorize?client_id=869611389818400779&response_type=token&redirect_uri=http%3A%2F%2Flocalhost%3A4321%2Flogin&scope=identify"
|
||||
>
|
||||
{t("login.discord")}
|
||||
</a>
|
||||
</form>
|
||||
|
||||
<style lang="postcss">
|
||||
@@ -79,4 +106,4 @@
|
||||
label {
|
||||
@apply text-neutral-300;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user