From 2591bf0a95281e03902a67b5bf12010811612070 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 25 Sep 2024 14:57:40 +0530 Subject: [PATCH] fix: use data.csrfToken --- src/context/auth.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/context/auth.tsx b/src/context/auth.tsx index cffeb924..9aa1fcbd 100644 --- a/src/context/auth.tsx +++ b/src/context/auth.tsx @@ -88,9 +88,17 @@ const AuthProvider = ({ children }: AuthProviderProps) => { // csrf - include tokens in the axios header every time a request is made useEffect(() => { const getCsrfToken = async () => { - const { data } = await axios.get('http://localhost:8080/csrf-token'); - console.log('CSRFFFFF =>>>>', data); - (axios.defaults.headers as any)['X-CSRF-TOKEN'] = data.getCsrfToken; + try { + const { data } = await axios.get('http://localhost:8080/csrf-token'); + console.log('CSRF Token Response:', data); + if (data && data.csrfToken) { + (axios.defaults.headers as any)['X-CSRF-TOKEN'] = data.csrfToken; + } else { + console.error('CSRF token not found in the response'); + } + } catch (error) { + console.error('Error fetching CSRF token:', error); + } }; getCsrfToken(); }, []);