ethan0905 / ft_transcendence

Wiki with step-by-step explained strategy on how to: create app (front+back+infra), 42auth, 2FA and more..
2 stars 0 forks source link

error TS2345: Argument of type 'Request' is not assignable to parameter of type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>'. #19

Closed ethan0905 closed 1 year ago

ethan0905 commented 1 year ago

I am trying to pass my Req and my Res element to my getToken() function but got this error:

backend_nestjs    | src/auth/auth.controller.ts:36:49 - error TS2345: Argument of type 'Request' is not assignable to parameter of type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>'.
backend_nestjs    |   Type 'Request' is missing the following properties from type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>': get, header, accepts, acceptsCharsets, and 83 more.
backend_nestjs    |
backend_nestjs    | 36   const token = await this.authService.getToken(req, res);

Here is my function inside my auth.controller.ts:

    @Get('42/callback')
    async getToken(@Req() req: Request, @Res() res: Response) {
        const token = await this.authService.getToken(req, res);
        console.log("token = " + token);
        // res.redirect(`http://localhost:3000/?token=${token.access_token}`);
    }

Inside my auth.service.ts:

    async getToken(@Req() req: Request, @Res() res: Response) {
        const code = req.query.code as string;
        console.log("req.query.code = " + code);

        const token = await this.accessToken(code);
        console.log("this.accessToken = " + token);
    }
ethan0905 commented 1 year ago

Ok I fixed it. Simply forgot to import the Request and Response from express library.