fix
This commit is contained in:
+6
-6
@@ -10,12 +10,12 @@ steps:
|
|||||||
- go mod tidy
|
- go mod tidy
|
||||||
- go test ./...
|
- go test ./...
|
||||||
|
|
||||||
# - name: lint frontend
|
- name: lint frontend
|
||||||
# image: node:20-alpine
|
image: node:20-alpine
|
||||||
# commands:
|
commands:
|
||||||
# - cd kotosoft-id-frontend
|
- cd kotosoft-id-frontend
|
||||||
# - npm install
|
- npm install
|
||||||
# - npm run lint
|
- npm run lint
|
||||||
|
|
||||||
- name: build and push backend
|
- name: build and push backend
|
||||||
image: docker:24
|
image: docker:24
|
||||||
|
|||||||
+1
-1
@@ -51,7 +51,7 @@ services:
|
|||||||
- proxy
|
- proxy
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
kotosoft_id_net:
|
kotosoft_id_network:
|
||||||
driver: bridge
|
driver: bridge
|
||||||
proxy:
|
proxy:
|
||||||
external: true
|
external: true
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
import { Consent } from "@/types"
|
import { Consent } from "@/types"
|
||||||
import { cookies } from "next/headers"
|
import { cookies } from "next/headers"
|
||||||
import { clearTokens, tryRefresh } from "./auth"
|
|
||||||
|
|
||||||
export async function getConsents() {
|
export async function getConsents() {
|
||||||
const store = await cookies()
|
const store = await cookies()
|
||||||
@@ -17,25 +16,12 @@ export async function getConsents() {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
if (response.status === 401) {
|
|
||||||
const refreshed = await tryRefresh();
|
|
||||||
if (!refreshed) {
|
|
||||||
await clearTokens();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return getConsents();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!response.ok) return []
|
if (!response.ok) return []
|
||||||
|
|
||||||
var consents = await response.json() as Consent[];
|
const consents = await response.json() as Consent[]
|
||||||
consents.forEach((consent: Consent) => {
|
consents.forEach((consent: Consent) => {
|
||||||
if (consent.client_id == process.env.CLIENT_ID) {
|
consent.isRevokable = consent.client_id !== process.env.CLIENT_ID
|
||||||
consent.isRevokable = false
|
})
|
||||||
} else {
|
|
||||||
consent.isRevokable = true
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return consents
|
return consents
|
||||||
}
|
}
|
||||||
@@ -45,7 +31,7 @@ export async function revokeConsent(clientId: string) {
|
|||||||
const accessToken = store.get("access_token")?.value
|
const accessToken = store.get("access_token")?.value
|
||||||
|
|
||||||
const response = await fetch(
|
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",
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@@ -24,13 +24,20 @@ export default function LoginPage() {
|
|||||||
const t = useTranslations("LoginPage");
|
const t = useTranslations("LoginPage");
|
||||||
|
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
const [redirectTo, setRedirectTo] = useState<string | null>(null);
|
||||||
const { register, handleSubmit, formState: { errors, isSubmitting } } = useForm<FormData>();
|
const { register, handleSubmit, formState: { errors, isSubmitting } } = useForm<FormData>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!session) {
|
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<FormData> = async (data) => {
|
const onSubmit: SubmitHandler<FormData> = async (data) => {
|
||||||
setError(null);
|
setError(null);
|
||||||
@@ -39,16 +46,15 @@ export default function LoginPage() {
|
|||||||
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
if (result.expired) {
|
if (result.expired) {
|
||||||
window.location.href = "/api/auth/initiate";
|
setRedirectTo("/api/auth/initiate");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setError(result.message ?? null);
|
setError(result.message ?? null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.redirectURL) {
|
if (result.redirectURL) {
|
||||||
window.location.href = result.redirectURL;
|
setRedirectTo(result.redirectURL);
|
||||||
} else {
|
} else {
|
||||||
router.push(`/consent?session=${session}`);
|
router.push(`/consent?session=${session}`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,31 +7,48 @@ import { Button } from "@/components/ui/button";
|
|||||||
import { localeMap } from "@/types";
|
import { localeMap } from "@/types";
|
||||||
import { enUS } from "date-fns/locale";
|
import { enUS } from "date-fns/locale";
|
||||||
import { format } from "date-fns";
|
import { format } from "date-fns";
|
||||||
|
import { revokeConsent } from "@/actions/consents";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
consents: Consent[] | null;
|
consents: Consent[] | [];
|
||||||
setConsents: (consents: Consent[]) => void;
|
setConsents: (consents: Consent[]) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Applications({ consents, setConsents }: Props) {
|
export default function Applications({ consents, setConsents }: Props) {
|
||||||
const t = useTranslations("MePage.items.applications");
|
const t = useTranslations("MePage.items.applications");
|
||||||
|
const [list, setList] = useState(consents);
|
||||||
|
|
||||||
const locale = useLocale();
|
const locale = useLocale();
|
||||||
const dateLocale = localeMap[locale as keyof typeof localeMap] ?? enUS;
|
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 (
|
return (
|
||||||
<div className="w-full lg:max-w-sm flex flex-col gap-4">
|
<div className="w-full lg:max-w-sm flex flex-col gap-4">
|
||||||
<h1 className="text-xl">{t("title")}</h1>
|
<h1 className="text-xl">{t("title")}</h1>
|
||||||
|
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
{consents?.map((consent) => (
|
{list.map((consent) => (
|
||||||
<Item key={consent.client_id}>
|
<Item key={consent.client_id}>
|
||||||
<ItemContent>
|
<ItemContent>
|
||||||
<ItemTitle>{consent.client_name}</ItemTitle>
|
<ItemTitle>{consent.client_name}</ItemTitle>
|
||||||
<ItemDescription>{t("authorized")} {format(consent.authorized_at, "PPP", { locale: dateLocale }) }</ItemDescription>
|
<ItemDescription>{t("authorized")} {format(consent.authorized_at, "PPP", { locale: dateLocale })}</ItemDescription>
|
||||||
</ItemContent>
|
</ItemContent>
|
||||||
<ItemActions>
|
<ItemActions>
|
||||||
<Button disabled={!consent.isRevokable}>{t("revoke")}</Button>
|
<Button
|
||||||
|
disabled={!consent.isRevokable}
|
||||||
|
onClick={() => handleRevoke(consent.client_id)}
|
||||||
|
>
|
||||||
|
{t("revoke")}
|
||||||
|
</Button>
|
||||||
</ItemActions>
|
</ItemActions>
|
||||||
</Item>
|
</Item>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ export default function Profile({ user, setUser }: Props) {
|
|||||||
|
|
||||||
if (response == null) setError(t("form.updateError"))
|
if (response == null) setError(t("form.updateError"))
|
||||||
else setUser(response)
|
else setUser(response)
|
||||||
} catch (error) {
|
} catch {
|
||||||
setError(t("form.updateError"))
|
setError(t("form.updateError"))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export default async function Me() {
|
|||||||
redirect("/api/auth/initiate");
|
redirect("/api/auth/initiate");
|
||||||
}
|
}
|
||||||
|
|
||||||
var consents = await getConsents();
|
const consents = await getConsents();
|
||||||
|
|
||||||
return <MeComponent userData={user} consentsData={consents} />;
|
return <MeComponent userData={user} consentsData={consents} />;
|
||||||
}
|
}
|
||||||
@@ -91,7 +91,7 @@ export default function RegisterPage() {
|
|||||||
</Field>
|
</Field>
|
||||||
|
|
||||||
<Field>
|
<Field>
|
||||||
<Button onClick={(e) => setStep(1)} variant="default" disabled={isSubmitting}>
|
<Button onClick={() => setStep(1)} variant="default" disabled={isSubmitting}>
|
||||||
{t("next")}
|
{t("next")}
|
||||||
<ArrowRight />
|
<ArrowRight />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
Reference in New Issue
Block a user