initial commit
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
"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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user