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:
18
apps/web/src/lib/queries/auth.ts
Normal file
18
apps/web/src/lib/queries/auth.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { UserProfileSchema, type UserProfile } from '@sar/api-interface';
|
||||
import { apiFetch } from '../api-client';
|
||||
|
||||
export const AUTH_KEYS = {
|
||||
me: ['auth', 'me'] as const,
|
||||
};
|
||||
|
||||
export function useCurrentUser() {
|
||||
return useQuery<UserProfile, Error>({
|
||||
queryKey: AUTH_KEYS.me,
|
||||
queryFn: async () => {
|
||||
const res = await apiFetch('/auth/me');
|
||||
return UserProfileSchema.parse(res);
|
||||
},
|
||||
staleTime: 5 * 60 * 1000,
|
||||
});
|
||||
}
|
||||
@@ -7,15 +7,15 @@ import {
|
||||
} from '@tanstack/react-router';
|
||||
import { Typography } from 'antd';
|
||||
import { AppShell } from '../components/layout/AppShell';
|
||||
import { RafaelPainel } from '../cockpits/rafael/RafaelPainel';
|
||||
import { ClientsPage } from '../cockpits/rafael/ClientsPage';
|
||||
import { ClientDetailPage } from '../cockpits/rafael/ClientDetailPage';
|
||||
import { OrdersPage } from '../cockpits/rafael/OrdersPage';
|
||||
import { OrderDetailPage } from '../cockpits/rafael/OrderDetailPage';
|
||||
import { NewOrderPage } from '../cockpits/rafael/NewOrderPage';
|
||||
import { CatalogPage } from '../cockpits/rafael/CatalogPage';
|
||||
import { ApprovalQueuePage } from '../cockpits/sandra/ApprovalQueuePage';
|
||||
import { SandraPainel } from '../cockpits/sandra/SandraPainel';
|
||||
import { RepPainel } from '../cockpits/rep/RepPainel';
|
||||
import { ClientsPage } from '../cockpits/rep/ClientsPage';
|
||||
import { ClientDetailPage } from '../cockpits/rep/ClientDetailPage';
|
||||
import { OrdersPage } from '../cockpits/rep/OrdersPage';
|
||||
import { OrderDetailPage } from '../cockpits/rep/OrderDetailPage';
|
||||
import { NewOrderPage } from '../cockpits/rep/NewOrderPage';
|
||||
import { CatalogPage } from '../cockpits/rep/CatalogPage';
|
||||
import { ApprovalQueuePage } from '../cockpits/supervisor/ApprovalQueuePage';
|
||||
import { SupervisorPainel } from '../cockpits/supervisor/SupervisorPainel';
|
||||
import { authStore } from './auth-store';
|
||||
|
||||
function getRoleFromToken(): string {
|
||||
@@ -31,7 +31,7 @@ function getRoleFromToken(): string {
|
||||
|
||||
function HomeRoute() {
|
||||
const role = getRoleFromToken();
|
||||
return role === 'supervisor' || role === 'manager' ? <SandraPainel /> : <RafaelPainel />;
|
||||
return role === 'supervisor' || role === 'manager' ? <SupervisorPainel /> : <RepPainel />;
|
||||
}
|
||||
|
||||
function NotFoundPage() {
|
||||
@@ -65,7 +65,7 @@ const indexRoute = createRoute({
|
||||
const rafaelRoute = createRoute({
|
||||
getParentRoute: () => rootRoute,
|
||||
path: '/rep',
|
||||
component: RafaelPainel,
|
||||
component: RepPainel,
|
||||
});
|
||||
|
||||
const clientesRoute = createRoute({
|
||||
|
||||
Reference in New Issue
Block a user