Files
kotosoft-id/kotosoft-id-frontend/actions/consents.ts
T
2026-03-09 18:09:02 +03:00

48 lines
1.1 KiB
TypeScript

"use server"
import { Consent } from "@/types"
import { cookies } from "next/headers"
export async function getConsents() {
const store = await cookies()
const accessToken = store.get("access_token")?.value
const response = await fetch(
`${process.env.KOTOSOFT_ID_API_URL}/api/v1/me/consents`,
{
headers: {
Authorization: `Bearer ${accessToken}`,
},
}
)
if (!response.ok) return []
const consents = await response.json() as Consent[]
consents?.forEach((consent: Consent) => {
consent.isRevokable = consent.client_id !== process.env.CLIENT_ID
})
return consents
}
export async function revokeConsent(clientId: string) {
const store = await cookies()
const accessToken = store.get("access_token")?.value
const response = await fetch(
`${process.env.KOTOSOFT_ID_API_URL}/api/v1/me/consent/${clientId}`,
{
method: "DELETE",
headers: {
Authorization: `Bearer ${accessToken}`,
},
}
)
if (!response.ok) {
return { success: false }
}
return { success: true }
}