34 lines
958 B
TypeScript
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;
|
|
}
|
|
} |