> ## 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.

# Login to Account

> Authenticate user with email and password

<Note>
  This is a public endpoint that does not require authentication.
</Note>

### Body

<ParamField body="email" type="string" required>
  The email address of the account
</ParamField>

<ParamField body="password" type="string" required>
  The account password
</ParamField>

### Response

<ResponseField name="access_token" type="string">
  JWT access token for authenticated requests
</ResponseField>

<ResponseField name="refresh_token" type="string">
  JWT refresh token for obtaining new access tokens
</ResponseField>

<ResponseField name="expires_in" type="integer">
  Token expiration time in seconds
</ResponseField>

<ResponseField name="token_type" type="string">
  Type of token (always "bearer")
</ResponseField>

### Error Responses

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

  <Expandable title="Error Object">
    <ResponseField name="status" type="integer">
      HTTP status code (401 for unauthorized)
    </ResponseField>

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

<Note>
  The API will return a 401 Unauthorized status code with "Invalid credentials" message in these cases:

  * User with provided email does not exist
  * Password verification fails
</Note>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.tktchurch.com/v1/auth/login" \
    -H "Content-Type: application/json" \
    -d '{
      "email": "user@example.com",
      "password": "securepassword123"
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.tktchurch.com/v1/auth/login', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      email: 'user@example.com',
      password: 'securepassword123'
    })
  });

  const data = await response.json();
  ```

  ```swift Swift theme={null}
  struct LoginRequest: Codable {
      let email: String
      let password: String
  }

  let request = LoginRequest(
      email: "user@example.com",
      password: "securepassword123"
  )

  let url = URL(string: "https://api.tktchurch.com/v1/auth/login")!
  var urlRequest = URLRequest(url: url)
  urlRequest.httpMethod = "POST"
  urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
  urlRequest.httpBody = try? JSONEncoder().encode(request)

  let (data, response) = try await URLSession.shared.data(for: urlRequest)
  let result = try JSONDecoder().decode(AuthResponse.self, from: data)
  ```

  ```kotlin Kotlin theme={null}
  data class LoginRequest(
      val email: String,
      val password: String
  )

  suspend fun login(email: String, password: String) {
      val client = OkHttpClient()
      
      val request = LoginRequest(email, password)
      val json = Gson().toJson(request)
      
      val requestBody = json.toRequestBody("application/json".toMediaType())
      
      val httpRequest = Request.Builder()
          .url("https://api.tktchurch.com/v1/auth/login")
          .post(requestBody)
          .header("Content-Type", "application/json")
          .build()
          
      client.newCall(httpRequest).execute().use { response ->
          if (response.isSuccessful) {
              val responseData = response.body?.string()
              // Handle success
          } else {
              // Handle error
          }
      }
  }
  ```

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

  const login = async (email: string, password: string) => {
    try {
      const response = await axios.post('https://api.tktchurch.com/v1/auth/login', {
        email,
        password
      }, {
        headers: {
          'Content-Type': 'application/json'
        }
      });
      
      return response.data;
    } catch (error) {
      if (axios.isAxiosError(error)) {
        // Handle error response
        const errorMessage = error.response?.data?.error?.reason || 'Login failed';
        throw new Error(errorMessage);
      }
      throw error;
    }
  };
  ```
</RequestExample>

<ResponseExample>
  ```json 200 Success theme={null}
  {
    "access_token": "eyJhbGciOiJIUzI1NiIs...",
    "refresh_token": "eyJhbGciOiJIUzI1NiIs...",
    "expires_in": 3600,
    "token_type": "bearer"
  }
  ```

  ```json 401 Invalid Credentials theme={null}
  {
    "error": {
      "status": 401,
      "reason": "Invalid credentials"
    }
  }
  ```

  ```json 400 Validation Error theme={null}
  {
    "error": {
      "status": 400,
      "reason": "Validation error: email is required"
    }
  }
  ```
</ResponseExample>
