Comparison of env.local and String variables

I encountered an access denied error with Firebase. The issue seems to arise when I try passing the value of the "project_ID" using an environment variable in the backend's "configs.ts" file, as shown in the code snippet below:

import 'firebase/firestore'
import { getFirestore } from 'firebase/firestore';

const firebaseConfig = {
apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
}

console.log("testing...", process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID)

const app = !getApps().length ? initializeApp(firebaseConfig) : getApp()
const dataBase = getFirestore(app)
export { dataBase }

I realized that everything works fine if I directly assign a string value in the config file instead of using environment variables, like this:

import { getApp, initializeApp, getApps } from 'firebase/app';
import 'firebase/firestore'
import { getFirestore } from 'firebase/firestore';

const firebaseConfig = {
    apiKey: "APIKEYtesting_sdifoasdf5165sdf",
    authDomain: "next-URLTest_446546",
    projectId: "next-Test_454654",
  };
console.log("testing...", process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID) // returns same value

const app = !getApps().length ? initializeApp(firebaseConfig) : getApp()
const dataBase = getFirestore(app)
export { dataBase }

The concern here is that hardcoding the string values directly in the configs could pose a significant security risk. My question is why this discrepancy occurs and how can it be resolved.

Here are the contents of my .env.local file:

NEXT_PUBLIC_FIREBASE_API_KEY=exemple_APIKEY_a65sd4adf65s4df54-6as5d456,
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=next-exemple-4a4d5.url,
NEXT_PUBLIC_FIREBASE_PROJECT_ID=next-exemple-4a4d5,

Answer №1

After carefully examining the issue, I have pinpointed the cause of the error. It appears that the culprit lies within the ".env.local" configuration file, particularly on its final line. It seems that a misplaced comma at the end of the last line has been mistakenly included as part of the variable's value.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The npm build command is triggering an error message that reads "Allocation failed due to ineffective mark-compacts near heap limit."

I'm currently working on a ReactJS/TypeScript project on Windows 10. I've been running into issues when trying to build my TypeScript scripts using the following command: "rimraf ../wwwroot/* && react-scripts-ts build && copyfi ...

Type validation in TypeScript through cross-referencing variables

Can TypeScript be used to define a variable that determines the type of other variables? I want to simplify the process by only needing to check one variable, stateIndicator, which is dependent on other variables to infer their types. type A = {prop1: st ...

Is there a way to convert a literal type from the type level to the term level in TypeScript?

Consider this scenario: I have created a type that can only hold one specific value: export type IfEqual<T, U> = (<G>() => G extends T ? 1 : 2) extends ...

Next.js encounters an error when importing web3

Currently, I am utilizing next js and material ui to create a demo dapp for educational purposes. With metamask installed, I have successfully implemented a "connect to wallet" button. My issue arises when attempting to import the Web3 constructor. This i ...

Challenge of Hosting a Next.js Application on IIS

Having recently started using the nextjs SSR framework of React js, I encountered a challenge in deploying my app on iis. Despite following the deployment steps diligently, I faced issues along the way. 1- First, I built my app using the npm run build com ...

Defined interface with specific number of members

I am tasked with creating an interface that has only two members, one of which is optional and both have undefined names. Something like: interface MyInterface { [required: string]: string|number [optional: string]?: string|number } Unfortunately, ...

A Step-by-Step Guide on Updating Your Angular 7 Project to Angular Version

I am facing a challenge with my Angular material project, which is currently outdated and needs to be updated to version 13. Running npm outdated revealed the following results: https://i.stack.imgur.com/ayjDu.png The Angular update guide suggests upgra ...

AngularFire2 - Deleting an item with Observable - Issue with last item not being removed from the User Interface

When I execute this function, the item is deleted from my Firebase database. However, in my Angular 2 app, when it reaches the last entry, it removes it from the database but does not remove it from the list displayed in my *ngFor loop. Strangely, upon ref ...

Exploring the Capabilities of TypeScript 1.8 in Visual Studio 2017

Recently, I've encountered an issue with my Visual Studio project that was created using TypeScript 1.8 in Visual Studio 2015. Upon upgrading to Visual Studio 2017 and attempting to open the project in the new IDE, I noticed that the TypeScript versio ...

The application is running smoothly in the local environment, however, encountering an issue in the production stage that throws a TypeError: Unable to access the property '

Having trouble deploying an app with Prismic as CMS. It works fine locally, but when deployed to Vercel, I encounter the error: 19:09:51.850 | TypeError: Cannot read property 'titulo' of undefined Seems like there's an issue when fetching d ...

The wrong parameter is used to infer the generic function type argument in TypeScript

When using the code snippet below and not explicitly specifying T at function call, such as getOrPut<Item>(...), it is inferred from the create parameter. However, this can lead to the created item type being incompatible with the obj dictionary, as ...

Encountered an issue during deployment with Vercel: The command "npm run build" terminated with exit code 1 while deploying a Next.js web application

I've been working on a local Next.js app, but encountered an error when deploying it. Vercel Deployment Error: Command "npm run build" exited with 1 Here is the log from the build process: [08:26:17.892] Cloning github.com/Bossman556/TechM ...

Deleting a key from a type in TypeScript using subtraction type

I am looking to create a type in TypeScript called ExcludeCart<T>, which essentially removes a specified key (in this case, cart) from the given type T. For example, if we have ExcludeCart<{foo: number, bar: string, cart: number}>, it should re ...

When setting up a NextJs application, the page directory may not be found

As a novice in NextJs, I recently installed next using the command "yarn create next-app," but encountered an issue - my app was created without a page directory. Attached here is an image confirming the problem. Can someone please advise on how to proceed ...

Secure access to the Express API with Kinde protection

I am currently working on developing a web application using next.js and a mobile application using react native. Both of these apps are integrated with my backend system which is built using node.js and express. To handle authentication, I have decided to ...

Observing changes in a parent component variable with Angular

One feature of my form is that it consists of a parent component and a child component. To disable a button within the form, I utilize a function called isDatasetFilesValid() which checks a specific variable (datasetList[i].fileValid). This variable is mo ...

employing flush for lodash's throttle wrapper

When using TypeScript with JavaScript and Angular: I am trying to use the throttle decorator from lodash to limit an API call while a user is navigating around the page, ensuring that it fires before they leave the site. In my TypeScript constructor, I h ...

Enhancing Your NextJS Website: Implementing a Full Page Background Image

I am facing an issue with adding a background image to my welcome page in NextJS. The problem seems to be related to how NextJS renders components inside a master component with a class of "__next". As a result, when I try to add a full-page background i ...

In Node.js, when accessing a Firebase snapshot, it may return a

Currently, I am utilizing Firebase functions to execute the code for my Flutter application. This code is responsible for sending push notifications to my app. However, I am encountering an issue where I receive a null value at snap.val(). Take a look at h ...

What is the reason behind the addition of '.txt' by the Next.js `Link` Component when redirecting to `href='/'` on GitHub pages?

My website is hosted on github-pages, and I am using the Link Component from Next.js to navigate within it. However, when I click on a component with the href="/", it adds .txt to the end of the URL. My website follows the /app structure. I have ...