๐Ÿ” Authentication API

Pregnancy Food Tracker - Email-based Authentication System

โœ“ API Ready โš™ Configuration Required

Quick Start

๐Ÿงช Test API Endpoints ๐Ÿ“– Main Documentation ๐Ÿ‘ค Profile API Docs ๐Ÿ“ View Code Examples

Setup Checklist

Authentication Endpoints

POST /api/check_user.php

Check if a user exists in the database by email address.

POST /api/register_user.php

Register a new user with email only. All other profile information is optional and can be added later.

POST /api/send_auth_code.php

Send a 2-digit authentication code to the user's email via SMTP2GO. Code expires in 10 minutes.

POST /api/verify_auth_code.php

Verify the authentication code entered by the user. Returns a session token on success.

Profile Management Endpoints

GET/POST /api/get_user_profile.php

Retrieve complete user profile information including pregnancy status and calculated pregnancy weeks.

POST /api/update_profile.php โญ

Comprehensive profile update endpoint - Update ALL user fields (display_name, date_of_birth, phone_e164, due_date, months_before_due_at_intake, number_of_kids, is_pregnant). Requires authentication. Perfect for multi-page forms.

POST /api/update_pregnancy_info.php

Update pregnancy-specific fields only (is_pregnant, due_date, months_before_due_at_intake, number_of_kids). Alternative to update_profile.php for pregnancy-only updates.

POST /api/unlock_account.php

Unlock a user account that was automatically locked after 5 failed verification attempts. Admin/support use only.

Authentication Flow

  1. Check User: Verify if email exists in database
  2. Register (if new): Create user account if not found
  3. Send Code: Email 2-digit authentication code to user
  4. Verify Code: Validate code and receive session token
  5. Access Granted: Use session token for authenticated requests

Security Features

Requirements

Configuration

Before using the API, configure your settings:

  1. Copy config/database.example.php to config/database.php
  2. Copy config/smtp.example.php to config/smtp.php
  3. Update both files with your actual credentials
  4. Test the API using the test page