I am trying to implement firebase functions using typescript. So far I was able to create some functions without problem until I had to deal with authentication. This is my first time using typescript, so I may be asking something that is obvious for most of the developers.
Context:
I was able to implement authentication check using this example. As we can see in that example (javascript) the code is decoding the token and passing the user information to the request, which will be processed by the next function.
Problem:
My problem is that I do not know how to do that in typescript. First of all, I had to add some types to the parameters in my token validator functions as the compiler was complaining about not having a type (like in the javascript example), so I went for something like this:
const validateFirebaseIdToken = async (req: any, res: any, next: any)
The problem is that in my next function I am not able to get the user:
example.get('/', async (req, res) => {
req.user
}
I receive the error: Property 'user' does not exist on type 'Request < Dictionary< string>>'.
so, how would you do it in this case? I do not want to decode the token again in the second function because it wouldn't make sense (I already did that in the previous step (token validation)).
Ideally:
I would like to use the same approach as it is in the javascript example.
I would like to add the right type to the parameters in the toke validation function. I tried using Request < Dictionary< String>> butthe compiler complains saying that that type is not generic (I deduced the type from the second function)
This is my code:
const validateFirebaseIdToken = async (req: any, res: any, next: any) => {}
const example = express();
example.use(validateFirebaseIdToken);
example.get('/', async (req, res) => {}