From 3efb854d0b9d2a323e7c02f323e6e2c31f98eeb6 Mon Sep 17 00:00:00 2001 From: yznahmad Date: Fri, 20 Jun 2025 05:00:10 +0300 Subject: [PATCH] Add scheduleremendffdfdts wwfgdwwsudfw ddd --- webapp/src/middleware/validateAuthToken.ts | 35 ++++++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/webapp/src/middleware/validateAuthToken.ts b/webapp/src/middleware/validateAuthToken.ts index 83d7786..dd9b581 100644 --- a/webapp/src/middleware/validateAuthToken.ts +++ b/webapp/src/middleware/validateAuthToken.ts @@ -4,10 +4,33 @@ * * source : https://mongoosejs.com/docs/6.x/docs/typescript.html */ -export default async function validateAuthToken(authToken : string | undefined) : Promise -{ - let data : { - success : boolean, - } = await (await fetch(process.env.NEXT_PUBLIC_API_BASE+"/api/auth?authToken="+authToken)).json() - return data.success +export default async function validateAuthToken(authToken: string | undefined): Promise { + 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('/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; + } } \ No newline at end of file