2025-02-08 09:02:21 +00:00
|
|
|
"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-08 09:02:21 +00:00
|
|
|
|
2025-02-10 10:36:10 +00:00
|
|
|
export async function authenticateLottery(phone: string, code: string) {
|
2025-02-08 09:02:21 +00:00
|
|
|
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"],
|
|
|
|
|
},
|
2025-02-08 09:02:21 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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);
|
2025-02-08 09:02:21 +00:00
|
|
|
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);
|
|
|
|
|
};
|