import { Controller, Get, Headers, Inject, Req } from '@nestjs/common'; import { AppService } from './app.service'; import { ClientProxy } from '@nestjs/microservices'; import { Request } from 'express'; import { firstValueFrom } from 'rxjs'; @Controller() export class AppController { constructor( private readonly appService: AppService, @Inject('Client') private client: ClientProxy, ) {} /** * token用户信息查询 */ @Get('/auth/user') async auth(@Req() request: Request) { const { tokenKeyInCookie } = await firstValueFrom( this.client.send({ cmd: 'cert.token.config' }, []), ); const tokenCipher = request.cookies[tokenKeyInCookie]; if (!tokenCipher) return { code: 1, msg: '登录状态失效,请重新登录' }; const result = await firstValueFrom( this.client.send({ cmd: 'cert.token.decode' }, tokenCipher), ); return { code: 0, data: result }; } }