35 lines
818 B
TypeScript
35 lines
818 B
TypeScript
import axios from "axios";
|
|
import { envConfig } from "./config";
|
|
import { redirect } from "next/navigation";
|
|
import { cookies } from "next/headers";
|
|
|
|
if (!envConfig.apiUrl) {
|
|
console.error("API URL is not defined in envConfig");
|
|
}
|
|
|
|
export async function GetStudent(numAcount: number) {
|
|
const cookieStore = cookies();
|
|
const token = (await cookieStore).get("token")?.value;
|
|
|
|
if (!token) redirect("/");
|
|
try {
|
|
const response = await axios.get(
|
|
`${envConfig.apiUrl}/student/${numAcount}`,
|
|
{
|
|
headers: {
|
|
Authorization: `Bearer ${token}`,
|
|
},
|
|
}
|
|
);
|
|
|
|
return response.data;
|
|
} catch (error: any) {
|
|
const msg =
|
|
error.response?.data?.message ||
|
|
error.message ||
|
|
"Error desconocido al obtener estudiante";
|
|
return { error: msg };
|
|
}
|
|
}
|
|
//IO
|