monorepo-microservice-rbac/apps/services/cert/gateway/src/app.controller.ts

30 lines
915 B
TypeScript
Raw Normal View History

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