Skip to main content

Get Current User Profile

curl -X GET https://api.sociapp.com/auth/me \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN"
{
  "IdUsuario": 15,
  "nombre": "Juan",
  "apellidos": "García López",
  "dni": "12345678A",
  "direccion": "Calle Mayor 123",
  "CP": "28001",
  "provincia": "Madrid",
  "poblacion": "Madrid",
  "pais": "España",
  "email": "[email protected]",
  "telefono": "+34 600 123 456",
  "fechaalta": "2024-01-15",
  "fechabaja": null,
  "formadepago": "Transferencia",
  "cuota": 25.00,
  "categoria": "admin",
  "socio": "Socio",
  "isVerified": true,
  "verificationCode": null,
  "verificationExpires": null
}

Endpoint

GET /auth/me

Authentication

Required: JWT Bearer token in Authorization header This endpoint requires authentication with a valid access token obtained from login or refresh.

Response Fields

IdUsuario
number
Unique user identifier
nombre
string
User’s first name
apellidos
string
User’s last name(s)
dni
string
National identification number
direccion
string
Street address
CP
string
Postal code
provincia
string
Province/state
poblacion
string
City/town
pais
string
Country
email
string
Email address
telefono
string
Phone number
fechaalta
string
Registration date (YYYY-MM-DD format)
fechabaja
string | null
Deactivation date (null if active)
formadepago
string
Payment method (e.g., “Transferencia”, “Efectivo”, “Tarjeta”)
cuota
number
Membership fee amount
categoria
string
User category: “admin”, “monitor”, “trabajador”, “voluntario”, or “usuario”
socio
string
Membership status: “Socio” (member) or “NoSocio” (non-member)
isVerified
boolean
Whether email is verified

Security Notes

The password field is excluded from the response for security. Verification code details are also removed.
  • Password Excluded: User’s hashed password is never returned
  • Verification Data: Verification codes and expiration are included but should not be displayed to end users
  • Token Validation: Endpoint validates JWT signature and expiration
  • User Identification: User ID extracted from JWT payload

Use Cases

  1. Profile Page: Display user information on profile/settings page
  2. Navigation: Show user name in header/navbar
  3. Authorization: Check user category/role for feature access
  4. Session Validation: Verify token is still valid and user exists

Example Integration

// Fetch current user on app load
async function getCurrentUser() {
  const token = localStorage.getItem('access_token');
  
  if (!token) {
    return null;
  }
  
  try {
    const response = await fetch('/auth/me', {
      headers: {
        'Authorization': `Bearer ${token}`
      }
    });
    
    if (!response.ok) {
      // Token invalid or expired
      localStorage.removeItem('access_token');
      return null;
    }
    
    const user = await response.json();
    return user;
  } catch (error) {
    console.error('Failed to fetch user:', error);
    return null;
  }
}

Vue.js Store Integration

// Pinia store example
import { defineStore } from 'pinia';

export const useAuthStore = defineStore('auth', {
  state: () => ({
    user: null,
    isAuthenticated: false
  }),
  
  actions: {
    async init() {
      try {
        const response = await fetch('/auth/me', {
          headers: {
            'Authorization': `Bearer ${localStorage.getItem('access_token')}`
          }
        });
        
        if (response.ok) {
          this.user = await response.json();
          this.isAuthenticated = true;
        } else {
          this.user = null;
          this.isAuthenticated = false;
        }
      } catch (error) {
        console.error('Auth init failed:', error);
        this.isAuthenticated = false;
      }
    }
  },
  
  getters: {
    isAdmin: (state) => state.user?.categoria === 'admin',
    isMonitor: (state) => state.user?.categoria === 'monitor',
    fullName: (state) => 
      state.user ? `${state.user.nombre} ${state.user.apellidos}` : ''
  }
});
  • Login - Authenticate and get tokens
  • Refresh - Refresh expired access token
  • Edit User - Update user profile information

Build docs developers (and LLMs) love