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

# Verify Email

> Verify user email address using the token sent via email

<Note>
  This is a public endpoint that does not require authentication. The verification token in the URL is sufficient for verification.
</Note>

### Query Parameters

<ParamField query="token" type="string" required={true}>
  The verification token received in the email. This is a JWT token containing the user ID.
</ParamField>

### Response

A successful request returns HTTP 200 OK status, indicating that the email has been verified.
The user's `emailVerified` status will be updated to `true` in the database.

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

  * 400 Bad Request: Missing verification token
  * 401 Unauthorized: Invalid or expired token
  * 404 Not Found: User not found
</Note>

<RequestExample>
  ```bash cURL theme={null}
  curl -X GET "https://api.tktchurch.com/v1/auth/verify-email?token=eyJhbGciOiJIUzI1NiIs..."
  ```

  ```javascript JavaScript theme={null}
  const verifyEmail = async (token) => {
    const response = await fetch(
      `https://api.tktchurch.com/v1/auth/verify-email?token=${token}`,
      {
        method: 'GET'
      }
    );

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

    return response.status === 200;
  };

  // Usage
  try {
    await verifyEmail('eyJhbGciOiJIUzI1NiIs...');
    console.log('Email verified successfully');
  } catch (error) {
    console.error('Verification failed:', error.message);
  }
  ```

  ```swift Swift theme={null}
  func verifyEmail(token: String) async throws {
      guard var urlComponents = URLComponents(string: "https://api.tktchurch.com/v1/auth/verify-email") else {
          throw URLError(.badURL)
      }
      
      urlComponents.queryItems = [
          URLQueryItem(name: "token", value: token)
      ]
      
      guard let url = urlComponents.url else {
          throw URLError(.badURL)
      }
      
      var request = URLRequest(url: url)
      request.httpMethod = "GET"
      
      let (_, response) = try await URLSession.shared.data(for: request)
      guard let httpResponse = response as? HTTPURLResponse else {
          throw URLError(.badServerResponse)
      }
      
      guard httpResponse.statusCode == 200 else {
          throw URLError(.badServerResponse)
      }
  }

  // Usage
  do {
      try await verifyEmail(token: "eyJhbGciOiJIUzI1NiIs...")
      print("Email verified successfully")
  } catch {
      print("Verification failed: \(error.localizedDescription)")
  }
  ```

  ```kotlin Kotlin theme={null}
  class EmailVerificationService(private val client: OkHttpClient) {
      suspend fun verifyEmail(token: String) {
          val url = HttpUrl.Builder()
              .scheme("https")
              .host("api.tktchurch.com")
              .addPathSegments("v1/auth/verify-email")
              .addQueryParameter("token", token)
              .build()

          val request = Request.Builder()
              .url(url)
              .get()
              .build()

          client.newCall(request).execute().use { response ->
              if (!response.isSuccessful) {
                  val error = response.body?.string()?.fromJson<ErrorResponse>()
                  throw Exception(error?.reason ?: "Verification failed")
              }
          }
      }
  }

  // Usage
  try {
      emailVerificationService.verifyEmail("eyJhbGciOiJIUzI1NiIs...")
      println("Email verified successfully")
  } catch (e: Exception) {
      println("Verification failed: ${e.message}")
  }
  ```

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

  const verifyEmail = async (token: string): Promise<boolean> => {
    try {
      const response = await axios.get(
        'https://api.tktchurch.com/v1/auth/verify-email',
        {
          params: { token }
        }
      );
      
      return response.status === 200;
    } catch (error) {
      if (axios.isAxiosError(error)) {
        throw new Error(error.response?.data?.error?.reason || 'Verification failed');
      }
      throw error;
    }
  };

  // Usage
  try {
    await verifyEmail('eyJhbGciOiJIUzI1NiIs...');
    console.log('Email verified successfully');
  } catch (error) {
    console.error('Verification failed:', error.message);
  }
  ```
</RequestExample>

<ResponseExample>
  ```json 200 Success theme={null}
  {
    "status": 200,
    "message": "Email verified successfully"
  }
  ```

  ```json 400 Missing Token theme={null}
  {
    "error": {
      "status": 400,
      "reason": "Verification token is required"
    }
  }
  ```

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

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