Stephan Bakkelund Valois
1 min readApr 9, 2021

--

It sounds like something is wrong with your middleware function, or that you didn't use it in your project.

The front end will send a bearer token with the payload. Inside the middleware function authenticateToken(), you fetch the bearer token, and verify it with the firebase admin SDK / library.

I'm not sure how familar you are with middleware functions, but I like to think about them as "hooking into" the incoming request, and make a change. That's actually what we're doing in this particular middleware (authenticateToken()). After the bearer token has been verified, it will put it onto the request object. (req.currentUser).

Now, without looking at your code, there are some things you need to check. Are you using the middleware in your express app? It has to be required into your index.js file, and applied to the express app. app.use(decodeToken). If not, the middleware function will never be able to hook into the request.

Also, are you logging any errors when you send a request to the backend? as per the tutorial, you should be logging a console.error if the bearer token didn't get verified by firebase.

1. Verify that you are using the middleware

2. Check wether you are successfully sending the bearer token with the payload from the frontend

3. Check wether you are verifying it correctly.

If you still can't get it to work, I will have to see your code. You can also use the source code https://github.com/Devalo/Firebase-auth-react-express-mongodb as a reference.

--

--

Stephan Bakkelund Valois
Stephan Bakkelund Valois

Responses (1)