templates #11

Closed
kayela wants to merge 47 commits from templates into main
Showing only changes of commit 56711e9136 - Show all commits

View File

@@ -3,35 +3,15 @@ import axios from 'axios';
const AuthContext = createContext(); const AuthContext = createContext();
// Ensure API_URL is correctly set, with fallback and validation const API_URL = process.env.REACT_APP_BACKEND_URL || window.location.origin;
const getApiUrl = () => {
const url = process.env.REACT_APP_BACKEND_URL;
// Log the environment variable for debugging // Log environment on module load for debugging
console.log('[AuthContext] Environment check:', { console.log('[AuthContext] Module initialized with:', {
REACT_APP_BACKEND_URL: url, REACT_APP_BACKEND_URL: process.env.REACT_APP_BACKEND_URL,
REACT_APP_BASENAME: process.env.REACT_APP_BASENAME, REACT_APP_BASENAME: process.env.REACT_APP_BASENAME,
PUBLIC_URL: process.env.PUBLIC_URL API_URL: API_URL
}); });
if (!url) {
console.error('[AuthContext] REACT_APP_BACKEND_URL is not defined!');
// Fallback to current origin API (same domain)
return window.location.origin.replace('/membership', '');
}
// Remove any trailing /membership or /api from the backend URL
const cleanUrl = url.replace(/\/(membership|api)\/?$/, '');
if (cleanUrl !== url) {
console.warn('[AuthContext] Cleaned backend URL:', { original: url, cleaned: cleanUrl });
}
return cleanUrl;
};
const API_URL = getApiUrl();
export const AuthProvider = ({ children }) => { export const AuthProvider = ({ children }) => {
const [user, setUser] = useState(null); const [user, setUser] = useState(null);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);