I'm deploying a React application to an Azure Web App. The project structure is as follows: root
│
├── server.js
├── package.json
├── package-lock.json
│
└── client
├── build
├── public
├── package.json
├── package-lock.json
└── src
└── index.js
In the index.js file located in the src directory of my React application, I'm trying to configure Auth0 for authentication. Here's the relevant code snippet:
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import { Auth0Provider } from '@auth0/auth0-react';
const domain = process.env.REACT_APP_AUTH0_DOMAIN;
const clientId = process.env.REACT_APP_AUTH0_CLIENT_ID;
if (!domain || !clientId) {
console.error('Missing Auth0 configuration');
}
ReactDOM.render(
<React.StrictMode>
<Auth0Provider
domain={domain}
clientId={clientId}
authorizationParams={{
redirect_uri: window.location.origin, // Automatically use the current origin
}}
>
<App />
</Auth0Provider>
</React.StrictMode>,
document.getElementById('root')
);
I've set up the environment variables REACT_APP_AUTH0_DOMAIN and REACT_APP_AUTH0_CLIENT_ID in my Azure Web App settings, but my React application is unable to read these variables at runtime. The error Missing Auth0 configuration is logged in the console, indicating that the environment variables are not being found.
Environment Variable Configuration: Verified that the environment variables are correctly configured in the Azure portal under the "Configuration" section of the App Service.
Build and Deployment: Ensured that the React application is being built and deployed correctly by running npm run build and then deploying the contents of the build folder.
I expect that after correctly setting the environment variables, my React application should be able to read these variables at runtime and configure Auth0 properly.
Interestingly, the same problem exists when running the application locally with the given file structure. However, locally, it is resolved by adding an extra .env file to the client folder. Unfortunately, this approach cannot be applied in Azure as the environment variables configured in the Azure portal should be automatically available to the application at runtime.




buildstage only.