monorepo-microservice-rbac/apps/services/cert/gateway/src/app.controller.ts
2023-10-10 16:48:34 +08:00

30 lines
915 B
TypeScript

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('cert.token.config', []),
);
const tokenCipher = request.cookies[tokenKeyInCookie];
if (!tokenCipher) return { code: 1, msg: '登录状态失效,请重新登录' };
const result = await firstValueFrom(
this.client.send('cert.token.decode', tokenCipher),
);
return { code: 0, data: result };
}
}