> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tktchurch.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Get Current User

> Get the profile of the currently authenticated user

<Note>
  This endpoint requires authentication. Include the JWT access token in the Authorization header.
</Note>

### Response

<ResponseField name="id" type="string">
  User's unique identifier (UUID)
</ResponseField>

<ResponseField name="email" type="string">
  User's email address
</ResponseField>

<ResponseField name="firstName" type="string" required={false}>
  User's first name
</ResponseField>

<ResponseField name="lastName" type="string" required={false}>
  User's last name
</ResponseField>

<ResponseField name="status" type="string">
  User's account status. One of:

  * `active`: User is active and can access the system
  * `inactive`: User is inactive (unverified email or deactivated account)
  * `suspended`: User is temporarily suspended
</ResponseField>

<ResponseField name="provider" type="string">
  Authentication provider. One of:

  * `local`: Local authentication using email and password
  * `google`: Google OAuth authentication
  * `facebook`: Facebook OAuth authentication
  * `apple`: Apple Sign In authentication
</ResponseField>

<ResponseField name="providerInfo" type="object" required={false}>
  Provider-specific user information

  <Expandable title="Provider Info">
    <ResponseField name="providerId" type="string" required={false}>
      The provider's unique identifier for the user
    </ResponseField>

    <ResponseField name="displayName" type="string" required={false}>
      The user's display name from the provider
    </ResponseField>

    <ResponseField name="photoUrl" type="string" required={false}>
      URL to the user's profile photo
    </ResponseField>

    <ResponseField name="email" type="string" required={false}>
      The user's email from the provider
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="lastLoginAt" type="string" required={false}>
  Timestamp of last login
</ResponseField>

<ResponseField name="roles" type="array" required={false}>
  List of user roles

  <Expandable title="Role Object">
    <ResponseField name="id" type="string" required={false}>
      Role identifier (UUID)
    </ResponseField>

    <ResponseField name="name" type="string">
      Role name
    </ResponseField>

    <ResponseField name="description" type="string">
      Role description
    </ResponseField>

    <ResponseField name="permissions" type="array">
      List of permissions granted to this role
    </ResponseField>

    <ResponseField name="isSystem" type="boolean">
      Whether this is a system-defined role
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="createdAt" type="string" required={false}>
  Account creation timestamp
</ResponseField>

### Error Responses

<ResponseField name="error" type="object">
  Error details when the request fails

  <Expandable title="Error Object">
    <ResponseField name="status" type="integer">
      HTTP status code
    </ResponseField>

    <ResponseField name="reason" type="string">
      Error message explaining why the request failed
    </ResponseField>
  </Expandable>
</ResponseField>

<Note>
  Common error cases:

  * 401 Unauthorized: Missing or invalid access token
  * 401 Unauthorized: Token has expired
  * 404 Not Found: User not found
</Note>

<RequestExample>
  ```bash cURL theme={null}
  curl -X GET "https://api.tktchurch.com/v1/auth/me" \
    -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..."
  ```

  ```javascript JavaScript theme={null}
  const getCurrentUser = async (accessToken) => {
    const response = await fetch('https://api.tktchurch.com/v1/auth/me', {
      method: 'GET',
      headers: {
        'Authorization': `Bearer ${accessToken}`
      }
    });

    if (!response.ok) {
      const error = await response.json();
      throw new Error(error.error.reason);
    }

    return response.json();
  };

  // Usage
  try {
    const user = await getCurrentUser('eyJhbGciOiJIUzI1NiIs...');
    console.log('Current user:', user);
  } catch (error) {
    console.error('Failed to get user profile:', error.message);
  }
  ```

  ```swift Swift theme={null}
  func getCurrentUser(accessToken: String) async throws -> User {
      var urlRequest = URLRequest(url: URL(string: "https://api.tktchurch.com/v1/auth/me")!)
      urlRequest.httpMethod = "GET"
      urlRequest.setValue("Bearer \(accessToken)", forHTTPHeaderField: "Authorization")
      
      let (data, response) = try await URLSession.shared.data(for: urlRequest)
      guard let httpResponse = response as? HTTPURLResponse else {
          throw URLError(.badServerResponse)
      }
      
      if httpResponse.statusCode != 200 {
          let error = try JSONDecoder().decode(ErrorResponse.self, from: data)
          throw error
      }
      
      return try JSONDecoder().decode(User.self, from: data)
  }

  // Usage
  do {
      let user = try await getCurrentUser(accessToken: "eyJhbGciOiJIUzI1NiIs...")
      print("Current user:", user)
  } catch {
      print("Failed to get user profile: \(error.localizedDescription)")
  }
  ```

  ```kotlin Kotlin theme={null}
  class UserService(private val client: OkHttpClient) {
      suspend fun getCurrentUser(accessToken: String): User {
          val request = Request.Builder()
              .url("https://api.tktchurch.com/v1/auth/me")
              .get()
              .header("Authorization", "Bearer $accessToken")
              .build()

          client.newCall(request).execute().use { response ->
              if (!response.isSuccessful) {
                  val error = response.body?.string()?.fromJson<ErrorResponse>()
                  throw Exception(error?.reason ?: "Failed to get user profile")
              }
              
              return response.body?.string()?.fromJson<User>()
                  ?: throw Exception("Empty response")
          }
      }
  }

  // Usage
  try {
      val user = userService.getCurrentUser("eyJhbGciOiJIUzI1NiIs...")
      println("Current user: $user")
  } catch (e: Exception) {
      println("Failed to get user profile: ${e.message}")
  }
  ```

  ```typescript React Native theme={null}
  import axios from 'axios';

  interface User {
    id: string;
    email: string;
    firstName?: string;
    lastName?: string;
    status: 'active' | 'inactive' | 'suspended';
    provider: 'local' | 'google' | 'facebook' | 'apple';
    providerInfo?: {
      providerId?: string;
      displayName?: string;
      photoUrl?: string;
      email?: string;
    };
    lastLoginAt?: string;
    roles?: Array<{
      id?: string;
      name: string;
      description: string;
      permissions: string[];
      isSystem: boolean;
    }>;
    createdAt?: string;
  }

  const getCurrentUser = async (accessToken: string): Promise<User> => {
    try {
      const response = await axios.get(
        'https://api.tktchurch.com/v1/auth/me',
        {
          headers: {
            'Authorization': `Bearer ${accessToken}`
          },
        }
      );
      
      return response.data;
    } catch (error) {
      if (axios.isAxiosError(error)) {
        throw new Error(error.response?.data?.error?.reason || 'Failed to get user profile');
      }
      throw error;
    }
  };

  // Usage
  try {
    const user = await getCurrentUser('eyJhbGciOiJIUzI1NiIs...');
    console.log('Current user:', user);
  } catch (error) {
    console.error('Failed to get user profile:', error.message);
  }
  ```
</RequestExample>

<ResponseExample>
  ```json 200 Success theme={null}
  {
    "id": "123e4567-e89b-12d3-a456-426614174000",
    "email": "john.doe@example.com",
    "firstName": "John",
    "lastName": "Doe",
    "status": "active",
    "provider": "google",
    "providerInfo": {
      "providerId": "google123",
      "displayName": "John Doe",
      "photoUrl": "https://example.com/photo.jpg",
      "email": "john.doe@example.com"
    },
    "lastLoginAt": "2024-01-20T08:30:00Z",
    "roles": [
      {
        "id": "456e4567-e89b-12d3-a456-426614174000",
        "name": "Member",
        "description": "Regular church member",
        "permissions": ["event:read", "newsletter:read", "livestream:read"],
        "isSystem": true
      }
    ],
    "createdAt": "2023-12-01T00:00:00Z"
  }
  ```

  ```json 401 Unauthorized theme={null}
  {
    "error": {
      "status": 401,
      "reason": "Invalid or expired access token"
    }
  }
  ```

  ```json 404 Not Found theme={null}
  {
    "error": {
      "status": 404,
      "reason": "User not found"
    }
  }
  ```
</ResponseExample>
