turkmentv_front/api/index.ts

41 lines
903 B
TypeScript
Raw Normal View History

"use server";
import baseUrl from "@/baseUrl";
import routes from "@/routes";
2025-02-10 10:36:10 +00:00
import { revalidateTag } from "next/cache";
2025-02-10 10:36:10 +00:00
export async function authenticateLottery(phone: string, code: string) {
try {
const res = await fetch(`${baseUrl.QUIZ_SRC}${routes.lotteryActive}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
phone: phone,
key: code,
}),
2025-02-10 10:36:10 +00:00
next: {
revalidate: 300,
tags: ["lotteryData"],
},
});
if (!res.ok) {
console.log("Authentication failed");
return undefined;
}
const result = await res.json();
2025-02-10 13:23:33 +00:00
console.log("Data fetched successfully " + res.status);
return result;
} catch (err) {
console.log(err);
return undefined;
}
}
2025-02-10 10:36:10 +00:00
2025-02-10 13:23:33 +00:00
export const revalidateTagName = async (tag: string) => {
2025-02-10 10:36:10 +00:00
revalidateTag(tag);
};