48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
"use server"
|
|
|
|
import { Consent } from "@/types"
|
|
import { cookies } from "next/headers"
|
|
|
|
export async function fetchConsents(): Promise<Consent[] | []> {
|
|
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 }
|
|
} |