/**
 *
 * @description this file contain the @validateAuthToken function that be used inside the middleware.ts
 * * source : https://mongoosejs.com/docs/6.x/docs/typescript.html
 */

// export default async function validateAuthToken(authToken: string | undefined): Promise<boolean> {
//     try {
//         if (!authToken) {
//             console.warn('No auth token provided');
//             return false;
//         }

//         const apiBase = process.env.NEXT_PUBLIC_API_BASE;
//         if (!apiBase) {
//             console.error('NEXT_PUBLIC_API_BASE environment variable is not set');
//             return false;
//         }

//         const url = new URL('https://irongym.yznapps.com/api/auth', apiBase);
//         url.searchParams.append('authToken', authToken);

//         const response = await fetch(url.toString());
        
//         if (!response.ok) {
//             console.error('Auth API request failed with status:', response.status);
//             return false;
//         }

//         const data = await response.json();
//         return !!data?.success;
//     } catch (error) {
//         console.error('Error validating auth token:', error);
//         return false;
//     }
// }


export default async function validateAuthToken(authToken : string | undefined) : Promise<boolean | undefined>
{
    let data : {
        success : boolean,
    } = await (await fetch("https://irongym.yznapps.com/api/auth?authToken="+authToken)).json()
    return data.success
}