initial commit
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
"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 []
|
||||
|
||||
var 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
|
||||
}
|
||||
});
|
||||
|
||||
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/applications/${clientId}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
if (!response.ok) {
|
||||
return { success: false }
|
||||
}
|
||||
|
||||
return { success: true }
|
||||
}
|
||||
Reference in New Issue
Block a user