请帮我找到如何优化我的代码。我需要限制登录用户的数据。为此,我需要从 Request 的 JWT 令牌中获取 UUID。但我不喜欢我的方法,因为我有重复的代码:
const jwt = request.headers.authorization.replace('Bearer ', '');
const json = this.jwtService.decode(jwt, { json: true }) as { uuid: string };
Run Code Online (Sandbox Code Playgroud)
有谁知道我如何优化它?
这是我的控制器代码。
import { Controller, Get, Put, Body, Param, UseGuards, Req } from '@nestjs/common';
import { SettingService } from '../services';
import { AuthGuard } from '@nestjs/passport';
import { ResultInterface } from '../interfaces';
import { Request } from 'express';
import { JwtService } from '@nestjs/jwt';
@Controller('settings')
export class SettingController {
/**
* @param service
* @param …Run Code Online (Sandbox Code Playgroud)