From c2c1c6dfcc44c8520399397fc3c227e046f350b4 Mon Sep 17 00:00:00 2001 From: Mo Tarbin Date: Sun, 8 Feb 2026 10:29:39 -0500 Subject: [PATCH] update authentication logic to conditionally include credentials for native platforms --- src/hooks/useAuth.jsx | 17 +++++++++++++---- src/utils/Fetcher.jsx | 15 ++++++++++++--- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/hooks/useAuth.jsx b/src/hooks/useAuth.jsx index d5999c7..4ed9bde 100644 --- a/src/hooks/useAuth.jsx +++ b/src/hooks/useAuth.jsx @@ -1,7 +1,7 @@ import { createContext, useContext, useEffect, useState } from 'react' import { useNavigate } from 'react-router-dom' -import { clearAllTokens, saveTokens } from '../utils/TokenStorage' import { apiClient } from '../utils/ApiClient' +import { clearAllTokens, saveTokens } from '../utils/TokenStorage' const AuthContext = createContext(null) @@ -36,12 +36,21 @@ export const AuthProvider = ({ children }) => { const login = async credentials => { setIsLoading(true) try { - const response = await fetch(`${baseURL}/auth/login`, { + const isNative = + typeof window !== 'undefined' && window.Capacitor?.isNativePlatform?.() + + const config = { method: 'POST', - credentials: 'include', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(credentials), - }) + } + + // Only use credentials for web, not for native apps + if (!isNative) { + config.credentials = 'include' + } + + const response = await fetch(`${baseURL}/auth/login`, config) if (!response.ok) { const error = await response.json() diff --git a/src/utils/Fetcher.jsx b/src/utils/Fetcher.jsx index 4124c92..c29e96a 100644 --- a/src/utils/Fetcher.jsx +++ b/src/utils/Fetcher.jsx @@ -68,10 +68,19 @@ const login = (username, password) => { const logout = () => { const baseURL = apiManager.getApiURL() - return fetch(`${baseURL}/auth/logout`, { + const isNative = + typeof window !== 'undefined' && window.Capacitor?.isNativePlatform?.() + + const config = { method: 'POST', - credentials: 'include', - }) + } + + // Only use credentials for web, not for native apps + if (!isNative) { + config.credentials = 'include' + } + + return fetch(`${baseURL}/auth/logout`, config) } const GetAllUsers = () => {