From 759fe065619f63ce5e03e34bc3ebbff5ac0f9a69 Mon Sep 17 00:00:00 2001 From: Giovanni Rezcjikov Date: Mon, 9 Mar 2026 13:35:53 +0300 Subject: [PATCH] fix --- .drone.yml | 12 ++++----- docker-compose.yml | 2 +- kotosoft-id-frontend/actions/consents.ts | 22 +++------------- kotosoft-id-frontend/app/login/page.tsx | 22 ++++++++++------ .../app/me/items/applications.tsx | 25 ++++++++++++++++--- kotosoft-id-frontend/app/me/items/profile.tsx | 2 +- kotosoft-id-frontend/app/me/page.tsx | 2 +- kotosoft-id-frontend/app/register/page.tsx | 2 +- 8 files changed, 49 insertions(+), 40 deletions(-) diff --git a/.drone.yml b/.drone.yml index dcb9afb..41516d2 100644 --- a/.drone.yml +++ b/.drone.yml @@ -10,12 +10,12 @@ steps: - go mod tidy - go test ./... - # - name: lint frontend - # image: node:20-alpine - # commands: - # - cd kotosoft-id-frontend - # - npm install - # - npm run lint + - name: lint frontend + image: node:20-alpine + commands: + - cd kotosoft-id-frontend + - npm install + - npm run lint - name: build and push backend image: docker:24 diff --git a/docker-compose.yml b/docker-compose.yml index 3964ab7..83e1831 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -51,7 +51,7 @@ services: - proxy networks: - kotosoft_id_net: + kotosoft_id_network: driver: bridge proxy: external: true \ No newline at end of file diff --git a/kotosoft-id-frontend/actions/consents.ts b/kotosoft-id-frontend/actions/consents.ts index 24b335a..974ce0e 100644 --- a/kotosoft-id-frontend/actions/consents.ts +++ b/kotosoft-id-frontend/actions/consents.ts @@ -2,7 +2,6 @@ import { Consent } from "@/types" import { cookies } from "next/headers" -import { clearTokens, tryRefresh } from "./auth" export async function getConsents() { const store = await cookies() @@ -16,26 +15,13 @@ export async function getConsents() { }, } ) - - if (response.status === 401) { - const refreshed = await tryRefresh(); - if (!refreshed) { - await clearTokens(); - return null; - } - return getConsents(); - } if (!response.ok) return [] - var consents = await response.json() as Consent[]; + const consents = await response.json() as Consent[] consents.forEach((consent: Consent) => { - if (consent.client_id == process.env.CLIENT_ID) { - consent.isRevokable = false - } else { - consent.isRevokable = true - } - }); + consent.isRevokable = consent.client_id !== process.env.CLIENT_ID + }) return consents } @@ -45,7 +31,7 @@ export async function revokeConsent(clientId: string) { const accessToken = store.get("access_token")?.value const response = await fetch( - `${process.env.KOTOSOFT_ID_API_URL}/api/v1/me/consents/${clientId}`, + `${process.env.KOTOSOFT_ID_API_URL}/api/v1/me/consent/${clientId}`, { method: "DELETE", headers: { diff --git a/kotosoft-id-frontend/app/login/page.tsx b/kotosoft-id-frontend/app/login/page.tsx index 150d4dc..0eb491b 100644 --- a/kotosoft-id-frontend/app/login/page.tsx +++ b/kotosoft-id-frontend/app/login/page.tsx @@ -24,13 +24,20 @@ export default function LoginPage() { const t = useTranslations("LoginPage"); const [error, setError] = useState(null); + const [redirectTo, setRedirectTo] = useState(null); const { register, handleSubmit, formState: { errors, isSubmitting } } = useForm(); useEffect(() => { if (!session) { - window.location.href = "/api/auth/initiate"; + router.replace("/api/auth/initiate"); } - }, [session]); + }, [session, router]); + + useEffect(() => { + if (redirectTo) { + router.push(redirectTo); + } + }, [redirectTo, router]); const onSubmit: SubmitHandler = async (data) => { setError(null); @@ -39,16 +46,15 @@ export default function LoginPage() { if (!result.success) { if (result.expired) { - window.location.href = "/api/auth/initiate"; + setRedirectTo("/api/auth/initiate"); return; } - setError(result.message ?? null); return; } if (result.redirectURL) { - window.location.href = result.redirectURL; + setRedirectTo(result.redirectURL); } else { router.push(`/consent?session=${session}`); } @@ -113,9 +119,9 @@ export default function LoginPage() { - {t.rich("noAccountNote", { - register: (chunks) => {chunks} - })} + {t.rich("noAccountNote", { + register: (chunks) => {chunks} + })} diff --git a/kotosoft-id-frontend/app/me/items/applications.tsx b/kotosoft-id-frontend/app/me/items/applications.tsx index 8f78eb2..21b260e 100644 --- a/kotosoft-id-frontend/app/me/items/applications.tsx +++ b/kotosoft-id-frontend/app/me/items/applications.tsx @@ -7,31 +7,48 @@ import { Button } from "@/components/ui/button"; import { localeMap } from "@/types"; import { enUS } from "date-fns/locale"; import { format } from "date-fns"; +import { revokeConsent } from "@/actions/consents"; +import { useState } from "react"; interface Props { - consents: Consent[] | null; + consents: Consent[] | []; setConsents: (consents: Consent[]) => void; } export default function Applications({ consents, setConsents }: Props) { const t = useTranslations("MePage.items.applications"); + const [list, setList] = useState(consents); const locale = useLocale(); const dateLocale = localeMap[locale as keyof typeof localeMap] ?? enUS; + const handleRevoke = async (clientId: string) => { + const result = await revokeConsent(clientId); + if (result.success) { + const updated = list.filter(c => c.client_id !== clientId); + setList(updated); + setConsents(updated); + } + }; + return (

{t("title")}

- {consents?.map((consent) => ( + {list.map((consent) => ( {consent.client_name} - {t("authorized")} {format(consent.authorized_at, "PPP", { locale: dateLocale }) } + {t("authorized")} {format(consent.authorized_at, "PPP", { locale: dateLocale })} - + ))} diff --git a/kotosoft-id-frontend/app/me/items/profile.tsx b/kotosoft-id-frontend/app/me/items/profile.tsx index 734f956..8164e00 100644 --- a/kotosoft-id-frontend/app/me/items/profile.tsx +++ b/kotosoft-id-frontend/app/me/items/profile.tsx @@ -42,7 +42,7 @@ export default function Profile({ user, setUser }: Props) { if (response == null) setError(t("form.updateError")) else setUser(response) - } catch (error) { + } catch { setError(t("form.updateError")) } }; diff --git a/kotosoft-id-frontend/app/me/page.tsx b/kotosoft-id-frontend/app/me/page.tsx index 4a016fe..98f7960 100644 --- a/kotosoft-id-frontend/app/me/page.tsx +++ b/kotosoft-id-frontend/app/me/page.tsx @@ -10,7 +10,7 @@ export default async function Me() { redirect("/api/auth/initiate"); } - var consents = await getConsents(); + const consents = await getConsents(); return ; } \ No newline at end of file diff --git a/kotosoft-id-frontend/app/register/page.tsx b/kotosoft-id-frontend/app/register/page.tsx index c7519ea..0330795 100644 --- a/kotosoft-id-frontend/app/register/page.tsx +++ b/kotosoft-id-frontend/app/register/page.tsx @@ -91,7 +91,7 @@ export default function RegisterPage() { -