我正在编写一个简单的 get 端点,并从前端标头发送令牌信息。但在后端我需要使用 userId。我认为它在令牌上可用,但我怎样才能从令牌中获取 userId?
// React Front End service
const response = await fetch(
`${process.env.REACT_APP_API_HOST}/export-data/pdf?${urlParams}`,
{
headers: {
...authService.authHeader(),
Authorization: `Bearer ${authService.getToken()}`,
},
}
);
// Nestjs Back End controller
@UseGuards(AuthGuard)
@Permissions('admin')
@Get('/pdf')
async exportDataPdf(@Query() query: GetOrdersFilterDto): Promise<any> {
// I need to use userId from token here.
return await this.exportDataService.exportDataPdf(query);
}