Skip to content

Instantly share code, notes, and snippets.

@StephanSchmidt
Created March 17, 2020 07:32
Show Gist options
  • Save StephanSchmidt/949231f0abb2b16d6f923c742dc734da to your computer and use it in GitHub Desktop.
Save StephanSchmidt/949231f0abb2b16d6f923c742dc734da to your computer and use it in GitHub Desktop.

Revisions

  1. StephanSchmidt created this gist Mar 17, 2020.
    24 changes: 24 additions & 0 deletions Controller with Cookie NestJS
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    @Controller()
    class AuthController {
    // constructor(private readonly authService: AuthService) {}
    constructor() {}

    // WARNING:
    // https://docs.nestjs.com/controllers
    //
    // Note that when you inject either @Res() or @Response() in a
    // method handler, you put Nest into Library-specific mode for
    // that handler, and you become responsible for managing the
    // response. When doing so, you must issue some kind of response
    // by making a call on the response object (e.g., res.json(...) or
    // res.send(...))

    @Post("/login/")
    login(@Res() res: Response) {
    res.cookie("jwt", "TOKEN", {
    httpOnly: true,
    secure: true,
    });
    res.send({ login: "ok" });
    }
    }