Files
kotosoft-id/kotosoft-id-frontend/actions/oauth.ts
T
2026-03-08 14:54:29 +03:00

34 lines
958 B
TypeScript

"use server"
import type { OAuthSession } from "@/types";
export async function getSession(token: string): Promise<OAuthSession | null> {
if (!token) return null;
try {
const response = await fetch(
`${process.env.KOTOSOFT_ID_API_URL}/oauth/session/${token}`,
{ cache: "no-store" }
);
if (!response.ok) return null;
return await response.json() as OAuthSession;
} catch {
return null;
}
}
export async function Approve(session: string, allow: boolean): Promise<string | null> {
if (!session) return null;
try {
const response = await fetch(`${process.env.KOTOSOFT_ID_API_URL}/oauth/session/approve`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ session, allow }),
cache: "no-store",
});
if (!response.ok) return null;
const data = await response.json();
return data.redirect_url ?? null;
} catch {
return null;
}
}