I need set header autorization client. But have error in my Mutation "Submission error! response.header is not a function".
my main.ts
async function bootstrap() {
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter(),
);
await app.enableCors({
origin: true,
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS',
credentials: true,
});
await app.useGlobalPipes(new ValidationPipe({ stopAtFirstError: true }));
await app.register(fastifyCookie, {
secret: 'secret',
});
await app.listen(3500);
}
my resolver
@Mutation((returns) => AccessToken, { nullable: true })
async registerUser(
@Args('createUser') createUserInput: CreateUserInput,
@Res({ passthrough: true }) response: FastifyReply,
): Promise<{ token: string }> {
const token = await this.userService.registerUser(createUserInput);
// await response.setCookie('token_auth', token, { httpOnly: true });
// response.signCookie('Bearer ' + token);
await response.header('Authorization', 'Bearer ' + token);
// await response.cookie('token_auth', token, { httpOnly: true });
return { token: token };
}
New contributor