feat(auth): endpoint /auth/me, cockpits renomeados e menu de logout
- GET /api/v1/auth/me retorna perfil real do ERP (vw_representantes) - Contrato UserProfile adicionado ao shared api-interface - Hook useCurrentUser() no frontend consome o endpoint - Cockpit rafael → rep, sandra → supervisor (pastas e componentes) - Topbar exibe iniciais do usuário e dropdown com nome, role e "Sair" - Logout limpa token e recarrega para voltar ao DevLogin Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
34
apps/api/src/app/auth/auth.controller.ts
Normal file
34
apps/api/src/app/auth/auth.controller.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { ClsService } from 'nestjs-cls';
|
||||
import type { UserProfile } from '@sar/api-interface';
|
||||
import type { WorkspaceClsStore } from '../workspace/workspace.types';
|
||||
import type { PrismaClient } from '@prisma/client';
|
||||
|
||||
@Controller({ path: 'auth' })
|
||||
export class AuthController {
|
||||
constructor(private readonly cls: ClsService<WorkspaceClsStore>) {}
|
||||
|
||||
@Get('me')
|
||||
async me(): Promise<UserProfile> {
|
||||
const prisma = this.cls.get('prisma') as PrismaClient;
|
||||
const userId = this.cls.get('userId') ?? '';
|
||||
const role = this.cls.get('role') ?? 'rep';
|
||||
const idEmpresa = this.cls.get('idEmpresa');
|
||||
|
||||
const rows = await prisma.$queryRaw<{ codigo: number; nome: string }[]>`
|
||||
SELECT codigo, nome
|
||||
FROM sar.vw_representantes
|
||||
WHERE codigo = ${parseInt(userId, 10)}
|
||||
AND id_empresa = ${idEmpresa}
|
||||
LIMIT 1
|
||||
`;
|
||||
|
||||
const row = rows[0];
|
||||
return {
|
||||
codVendedor: row?.codigo ?? parseInt(userId, 10),
|
||||
nome: row?.nome ?? userId,
|
||||
role,
|
||||
idEmpresa,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,11 @@ import { Module } from '@nestjs/common';
|
||||
import { WorkspaceModule } from '../workspace/workspace.module';
|
||||
import { JwtAuthGuard } from './jwt-auth.guard';
|
||||
import { DevAuthController } from './dev-auth.controller';
|
||||
import { AuthController } from './auth.controller';
|
||||
|
||||
@Module({
|
||||
imports: [WorkspaceModule],
|
||||
controllers: [DevAuthController],
|
||||
controllers: [DevAuthController, AuthController],
|
||||
providers: [JwtAuthGuard],
|
||||
exports: [JwtAuthGuard],
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user