This commit is contained in:
Giovanni Rezcjikov
2026-03-09 13:35:53 +03:00
parent b4066b1a7c
commit 759fe06561
8 changed files with 49 additions and 40 deletions
+4 -18
View File
@@ -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: {