'nestjs cannot find HEADER parameter
I was passing JWT-token from the postman on my local machine, and I can decode it into some data inside. But for some reason when I push it onto the docker container and throw a request to my API, it can't see my header properly.
Here is my code, written on nestjs.
user.controller.ts
import { UserService } from '../services'
import { Body, Controller, Get, Headers, Param, Patch } from '@nestjs/common'
import { UserDto } from '../types/dtos'
@Controller()
export class UserController {
constructor (
private readonly service: UserService
) {}
@Get('/api/get-user-data')
async getUser (@Headers('access_token') token: string) {
return await this.service.getUserByToken(token)
}
user.service.ts
import jwtDecode from 'jwt-decode'
import { TokenDto } from '../types/dtos/token.dto'
@Injectable()
export class UserService {
userProfileMapper = new UserProfileMapper()
constructor (
@Inject(CREATOR) private readonly repository: BaseRepository<Creator>,
) {}
async getUserByToken (token: string) {
try {
const object: TokenDto = await jwtDecode(token)
const user = await this.repository.get({email: object.email})
return this.userProfileMapper.toDTO(user)
} catch (e) {
console.log(e)
}
}
}
Can it be a problem in the docker container or something else?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
