私は単純な 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);
}