From 767dd7a82251c1812cda94d96822b63e156a6f96 Mon Sep 17 00:00:00 2001 From: Last2014 Date: Mon, 28 Jul 2025 20:00:33 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=B5=E3=82=A4=E3=83=B3=E3=82=A4=E3=83=B3?= =?UTF-8?q?=E5=87=A6=E7=90=86=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/globals.css | 4 + src/app/layout.tsx | 2 +- src/app/page.tsx | 8 ++ src/app/signin/page.tsx | 230 ++++++++++++++++++++++++++++++++- src/components/footer/main.tsx | 18 +-- test.ts | 12 ++ 6 files changed, 257 insertions(+), 17 deletions(-) create mode 100644 test.ts diff --git a/src/app/globals.css b/src/app/globals.css index a2dc41e..2afc210 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -24,3 +24,7 @@ body { color: var(--foreground); font-family: Arial, Helvetica, sans-serif; } + +.iconify { + display: inline; +} diff --git a/src/app/layout.tsx b/src/app/layout.tsx index a2695ba..16b6c0d 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -15,7 +15,7 @@ const geistMono = Geist_Mono({ }); export const metadata: Metadata = { - title: "uwuzu軽量クライアント", + title: "uwuzu Light Client", description: "(自称)超軽量uwuzuクライアントです。", }; diff --git a/src/app/page.tsx b/src/app/page.tsx index aa751d5..adf2d58 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,9 +1,17 @@ "use client"; import { Icon } from "@iconify/react"; +import { useRouter } from "next/navigation"; +import Cookies from "js-cookie"; import Image from "next/image"; import Link from "next/link"; export default function Home() { + // ログイン済みの場合ホームへ移動 + const router = useRouter(); + if (typeof Cookies.get("host") !== "undefined") { + router.push("/home"); + } + return (
) => { + e.preventDefault(); + setLoading(true); + + + // データを変数に代入 + const host: string = e.currentTarget.host.value; + const token: string = e.currentTarget.token.value; + + try { + // APIテスト + const test = await (await fetch( + `https://${host}/api/me/?token=${token}` + )).json(); + + if (typeof test.error_code !== "undefined") { + alert(` + トークンが誤っています。 + `); + setLoading(false); + return; + } else { + Cookies.set("host", host, { expires: 999 }); + Cookies.set("token", token, { expires: 999 }); + + alert(`${test.username}へログインしました!`); + router.push("/home"); + } + } catch (err) { + alert(` + サーバーとの通信に失敗しました。 + プロトコルあるいはホストが誤っている可能性があります。 + + + 詳細エラー: ${err} + `); + setLoading(false); + return; + } + } + + return ( +
+

+ サインイン +

+ +
+ {loading && ( +
+ +
+ )} +
+ + +
+ +
+ + + +
+ + +
+ + + +
+ + +
+ +
+
+
+ ); } diff --git a/src/components/footer/main.tsx b/src/components/footer/main.tsx index 02e7fca..3922cda 100644 --- a/src/components/footer/main.tsx +++ b/src/components/footer/main.tsx @@ -32,21 +32,9 @@ export default function Footer() { target="" /> - - diff --git a/test.ts b/test.ts new file mode 100644 index 0000000..96ddc3c --- /dev/null +++ b/test.ts @@ -0,0 +1,12 @@ +(async () => { + const req = await fetch("https://uwuzu.net/api/me", { + method: "POST", + cache: "no-store", + body: JSON.stringify({ + token: "RpC9X0BuNUsaOxLkw3Pf5YGMIEHVtgldDnrbWKzhFvjT7eZ4qJ6m81Si2oQcAy", + }), + }); + const res = await req.json(); + + console.log(res); +})();