awinogrodzki/next-firebase-auth-edge

Cannot read properties of undefined (reading 'privateKey') - getFirebaseAuth()

Closed this issue · 4 comments

Hey,
I am using official firebase library for user sign in. When the user signs in, I store the user token in cookie as 'fireBaseToken'.
Now in the middleware I am using next-firebase-auth-edge lib. for verifying the token when user tries to access restricted pages.
After surfing through documentation, I found that verifyIdToken is used in to verify tokens from firebase.
So I wrote this code (in the attached screenshot), but getting error.

What am I doing wrong? Is there any other method I have to use? Is there any other alternative? Please look for the issue ASAP !
Frame 2
middleware 2

[i will use env var later]

even when writing any random string it throws same error. For example in ->

{
..., privateKey: 'Hi all'
}

Hey @Faraz643, thanks for reporting

Is this the only place where you call getFirebaseAuth?

Do you have access to the full stack trace of this error?

getFirebaseAuth would only throw this error if you did not provide first argument to getFirebaseAuth function. I may be missing some context here however, so let's first investigate the stack trace

Hey @Faraz643, thanks for reporting

Is this the only place where you call getFirebaseAuth?

Do you have access to the full stack trace of this error?

getFirebaseAuth would only throw this error if you did not provide first argument to getFirebaseAuth function. I may be missing some context here however, so let's first investigate the stack trace

This is the only file (middleware) where I am calling getFirebaseAuth.

and what is the first argument? am I missing something here? I dont have the full stack trace for this error. Only shown in terminal(above screenshot).

this is what I have _>

Server Error
TypeError: Cannot read properties of undefined (reading 'privateKey')

This error happened while generating the page. Any console logs will be displayed in the terminal window.
Source
middleware.js (26:30) @ getFirebaseAuth

  24 |
  25 | export async function middleware(req) {
> 26 | const auth = getFirebaseAuth();
     |                            ^
  27 |
  28 | const {
  29 |   nextUrl: { pathname, origin },

ISSUE SOLVED.

My Mistake. I was calling the method somewhere else, without args and forgot to comment it out. :(
:).

Thank you for your support.