0

I am really stable with normal JS but as I started migrating to TS I am getting a lot of trubles. Normally I would return req.user = user, but right now with TS I am not anymore able to do that, can anyone help me? Thanks


export const auth = async(req: Request, res:Response, next: NextFunction) => {
    try {
        const token = req.headers["authorization"]?.replace('Bearer ' , '');
        const isValidToken: any = verify(<string>token, 'secret');

        const driver = await Driver.findById({_id: isValidToken._id});

        req.user = driver; //  <= Here I get an Error

        //Property 'user' does not exist on type 'Request<ParamsDictionary, any, any, 
        //ParsedQs, Record<string, any>>'.ts(2339)


        next();
    } catch(e) {
        res.status(400).send({e});
    }
    
    
}

Normally I would return req.user = user, but right now with TS I am not anymore able to do that, can anyone help me? Thanks

0 Answers0