curl --request GET \
--url https://api.example.com/api/auth/me{
"user": {
"user_id": "<string>",
"email": "<string>",
"name": "<string>",
"surname": "<string>",
"role": {},
"status": {},
"document_type": {},
"document_number": "<string>",
"phone": "<string>",
"created_at": "<string>"
}
}Retrieve the authenticated user’s profile information
curl --request GET \
--url https://api.example.com/api/auth/me{
"user": {
"user_id": "<string>",
"email": "<string>",
"name": "<string>",
"surname": "<string>",
"role": {},
"status": {},
"document_type": {},
"document_number": "<string>",
"phone": "<string>",
"created_at": "<string>"
}
}/api/auth/me endpoint returns the profile information of the currently authenticated user based on their JWT token. This endpoint is useful for:
Authorization: Bearer <your_jwt_token>
Cookie: auth_token=<your_jwt_token>
/api/* endpoints (except public routes like /api/auth/login) are automatically validated by the authentication middleware at server/middleware/auth.ts.
The middleware:
auth_token cookieverifyToken() from server/utils/jwt.ts{ userId, email, role }event.context.userserver/middleware/auth.ts:22-55
Show User object properties
ADMIN, USERON, OFFDNI, PASSPORT, NIEuserIdserver/middleware/auth.ts:36-39 and server/middleware/auth.ts:51-54ON (account has been deactivated)server/api/auth/me.get.ts:31-35# Using Authorization header
curl -X GET https://api.beils.com/api/auth/me \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
{
"user": {
"user_id": "550e8400-e29b-41d4-a716-446655440000",
"email": "[email protected]",
"name": "María",
"surname": "García",
"role": "USER",
"status": "ON",
"document_type": "DNI",
"document_number": "12345678A",
"phone": "+34612345678",
"created_at": "2024-01-15T10:30:00.000Z"
}
}
{
"statusCode": 401,
"statusMessage": "Unauthorized: Token is missing or invalid"
}
{
"statusCode": 403,
"statusMessage": "Cuenta inactiva o no encontrada. Contacta con soporte admin."
}
interface JwtPayload {
userId: string;
email: string;
role: string;
iat: number; // Issued at timestamp
exp: number; // Expiration timestamp
}
server/utils/jwt.ts:5-9
signToken function:
export const signToken = (payload: object, expiresIn: string | number = '24h') => {
return jwt.sign(payload, JWT_SECRET, { expiresIn: expiresIn as any });
}
JWT_SECRET environment variable'super-secret-tp-plus-dashboard' (development only)server/utils/jwt.ts:11-13
verifyToken function:
export const verifyToken = (token: string): JwtPayload | null => {
try {
return jwt.verify(token, JWT_SECRET) as JwtPayload;
} catch (error) {
return null;
}
}
null if the token is:
server/utils/jwt.ts:15-21
select: {
user_id: true,
email: true,
name: true,
surname: true,
role: true,
status: true,
document_type: true,
document_number: true,
phone: true,
created_at: true,
}
password, refresh_token, and address information are never returned.
Source: server/api/auth/me.get.ts:17-28
JWT_SECRET periodically in production/api/auth/login/api/hello/api/* routes require a valid JWT token.
Source: server/middleware/auth.ts:7
async function isTokenValid(token) {
try {
const response = await fetch('https://api.beils.com/api/auth/me', {
headers: { 'Authorization': `Bearer ${token}` }
});
return response.ok;
} catch (error) {
return false;
}
}
async function autoLogin() {
const token = localStorage.getItem('auth_token');
if (!token) return null;
try {
const response = await fetch('https://api.beils.com/api/auth/me', {
headers: { 'Authorization': `Bearer ${token}` }
});
if (response.ok) {
const { user } = await response.json();
return user;
}
} catch (error) {
localStorage.removeItem('auth_token');
}
return null;
}
async function checkAdminAccess(token) {
const response = await fetch('https://api.beils.com/api/auth/me', {
headers: { 'Authorization': `Bearer ${token}` }
});
const { user } = await response.json();
return user.role === 'ADMIN';
}