DEV Community

Discussion on: Building NestJS app boilerplate - Authentication, Validation, GraphQL and Prisma

Collapse
 
valerebron profile image
Valère BRON

Hi Nikita Gr8 Article ... but Express can't write token'cookie !

this line of code seems ok : "res.cookie('token', jwt, { httpOnly: true });" in auth.resolver.ts,
and the token is correctly generated but no cookie is created in client side...

Collapse
 
nikitakot profile image
Nikita Kot

Please check your graphql playground settings in the browser. You should have "request.credentials": "same-origin" set there to allow CORS.

Collapse
 
valerebron profile image
Valère BRON • Edited

Indeed, that works

Collapse
 
nikitakot profile image
Nikita Kot

P.S. If you are not using graphql playground and calling the server from a front-end application served from another server (different domain/port/etc.) you need to enable cors on the nestjs server (not described in the article). To do it simply add these lines to your main.ts file to the bootstrap function.

app.enableCors({
    credentials: true,
    origin: true,
  });
Collapse
 
valerebron profile image
Valère BRON

Cors was the problem yes, thanks again for these speed responses !