feat: ci/cd
This commit is contained in:
@@ -27,7 +27,7 @@ export async function clearTokens() {
|
||||
store.delete("refresh_token");
|
||||
}
|
||||
|
||||
async function tryRefresh(): Promise<boolean> {
|
||||
export async function tryRefresh(): Promise<boolean> {
|
||||
if (refreshPromise) return refreshPromise;
|
||||
|
||||
refreshPromise = (async () => {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { Consent } from "@/types"
|
||||
import { cookies } from "next/headers"
|
||||
import { clearTokens, tryRefresh } from "./auth"
|
||||
|
||||
export async function getConsents() {
|
||||
const store = await cookies()
|
||||
@@ -15,15 +16,24 @@ 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[];
|
||||
consents.forEach((consent: Consent) => {
|
||||
if (consent.client_id == process.env.CLIENT_ID) {
|
||||
consent.isRevokable == false
|
||||
consent.isRevokable = false
|
||||
} else {
|
||||
consent.isRevokable == true
|
||||
consent.isRevokable = true
|
||||
}
|
||||
});
|
||||
|
||||
@@ -35,7 +45,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/applications/${clientId}`,
|
||||
`${process.env.KOTOSOFT_ID_API_URL}/api/v1/me/consents/${clientId}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
|
||||
Reference in New Issue
Block a user