I'm coding a simple get endpoint, and I send from front-end header the token information. But in back-end I need to use userId. I think it is available on token, but how can I get userId from token?
// 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);
}