简体   繁体   English

如何安全地将 API 密钥传递给 React 组件所需的 React 前端

[英]How do I safely pass API keys to a React Front end that is needed for a React Component

I am using @react-google-maps/api to create a map component on React.我正在使用 @react-google-maps/api 在 React 上创建一个 map 组件。 In order to load the component we need to pass an API key to useJsApiLoader.为了加载组件,我们需要将 API 密钥传递给 useJsApiLoader。 How do I handle securing the API key so it is not visible on the front end in this situation?如何处理保护 API 密钥,使其在这种情况下在前端不可见? (I have a express.js back end) (我有一个 express.js 后端)

Here is the documentation for @react-google-maps https://react-google-maps-api-docs.netlify.app/这是@react-google-maps https://react-google-maps-api-docs.netlify.app/的文档

Create a.env file in the root directory of the project and add the variables in that file.在项目的根目录中创建一个 .env 文件,并在该文件中添加变量。 Import the variables using react-dotenv package.使用 react-dotenv package 导入变量。 Hope this helps希望这可以帮助

Reference参考

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React Microfronends:如何将身份验证和其他信息从一个前端应用程序传递到另一个前端应用程序? - React Microfronends: How do I pass authentication and other information from one Front end app to another Front end app? 我如何安全地从 React 组件渲染 Markdown? - How do I SAFELY render Markdown from a React component? 如何将数据从反应前端传递到节点快递后端? - How do I pass data from react front end to node express backend? 如何将反应前端的objectId传给服务端graphql? - How do I pass in objectId from the react front end to server-side graphql? 如何安全地传递参数以使组件与react-rails交互 - How safely to pass params to react component with react-rails 如何将道具传递到反应组件? - How do I pass props to a react component? 如何从对象数组中获取数据,并通过 API 端点将其传递到 .fetch() 使用 React 所需的对象值? - How can I fetch data from an array of objects, pass it through an API end point to .fetch() the needed object value using React? 如何将标题和图像文件从前端 (React.js) 传递到后端 API (Spring Boot)? - How can I pass both the title and an image file from my front end (React.js) to my backend API (Spring Boot)? 我如何在反应中传递 map function 前面的道具? - How do I pass a prop in front of map function in react? 如何在 React 中安全地将 props 有条件地传递给功能组件 - How to type safely pass props conditionally to a functional component in React
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM