📱 FCM Login

iOS Native App with SwiftUI - Complete Setup & Integration Guide

📖 Overview

FCM Login is a modern authentication and user management system built with Laravel backend and iOS native SwiftUI frontend. The application provides secure authentication with Firebase integration, social login support, and push notification capabilities.

đŸŽ¯ What You'll Learn: This documentation will guide you through setting up both the Laravel backend API and iOS SwiftUI frontend application, including Firebase configuration, authentication flows, and API integration.

Technology Stack

🔧 Backend

  • Laravel 11.x
  • PHP 8.2+
  • Laravel Sanctum
  • Firebase Admin SDK
  • MySQL Database

📱 Frontend

  • SwiftUI
  • iOS 15.0+
  • Firebase iOS SDK
  • Xcode 14+
  • Swift 5.7+

🔐 Authentication

  • Email/Password
  • Google Sign-In
  • Apple Sign-In
  • Facebook Login
  • Firebase Auth

✨ Features

Authentication & User Management

Security Features

Push Notifications

Additional Features

🚀 Laravel Backend Setup

Prerequisites

âš ī¸ Required Software: Make sure you have the following installed before proceeding.

Step 1: Download & Install Dependencies

1Download the source code and install dependencies:

# Extract the downloaded source code
# Navigate to the project directory
cd fcmlogin-admin

# Install PHP dependencies
composer install

# Install Node dependencies
npm install
💡 Tip: After downloading the source code ZIP file, extract it to your desired location (e.g., /Users/yourname/Projects/fcmlogin-admin on Mac or C:\xampp\htdocs\fcmlogin-admin on Windows).

Step 2: Environment Configuration

2Set up your environment variables:

# Copy the example environment file
cp .env.example .env

# Generate application key
php artisan key:generate

Edit the .env file with your configuration:

APP_NAME="FCM Login"
APP_ENV=local
APP_DEBUG=true
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=fcmlogin
DB_USERNAME=root
DB_PASSWORD=your_password

MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=your_username
MAIL_PASSWORD=your_password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="noreply@fcmlogin.com"
MAIL_FROM_NAME="${APP_NAME}"

Step 3: Firebase Configuration

3Set up Firebase for your Laravel application:

3.1 Create Firebase Project

  1. Go to Firebase Console
  2. Click "Add project" and follow the setup wizard
  3. Enable Authentication methods (Email/Password, Google, Apple, Facebook)
  4. Enable Cloud Messaging for push notifications

3.2 Download Service Account Key

  1. In Firebase Console, go to Project Settings → Service Accounts
  2. Click "Generate new private key"
  3. Save the JSON file as firebase-admin.json
  4. Place it in storage/app/firebase-admin.json
# Create the storage directory if it doesn't exist
mkdir -p storage/app

# Move your downloaded file
mv ~/Downloads/your-project-firebase-adminsdk.json storage/app/firebase-admin.json

# Set proper permissions
chmod 600 storage/app/firebase-admin.json
🔒 Security Warning: Never commit firebase-admin.json to version control. Add it to .gitignore file.

3.3 Configure Firebase in .env

FIREBASE_CREDENTIALS=storage/app/firebase-admin.json
FIREBASE_DATABASE_URL=https://your-project-id.firebaseio.com

Step 4: Database Setup

4Create and migrate the database:

# Create database
mysql -u root -p -e "CREATE DATABASE fcmlogin CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"

# Run migrations
php artisan migrate

# (Optional) Seed sample data
php artisan db:seed

Step 5: Storage & Permissions

5Set up storage and permissions:

# Create storage link
php artisan storage:link

# Set proper permissions (Linux/Mac)
chmod -R 775 storage bootstrap/cache
chown -R www-data:www-data storage bootstrap/cache

Step 6: Start Development Server

6Run the development server:

# Start Laravel development server
php artisan serve

# In another terminal, compile assets
npm run dev
✅ Success! Your Laravel backend should now be running at http://localhost:8000

API Base URL Configuration

For production deployment, update your APP_URL in .env:

APP_URL=https://api.yourdomain.com

📱 iOS SwiftUI App Setup

Prerequisites

Step 1: Install CocoaPods

1Install CocoaPods if you haven't already:

# Install CocoaPods
sudo gem install cocoapods

# Verify installation
pod --version

Step 2: Project Setup

2Open your iOS project in Xcode:

# Navigate to iOS project directory
cd /path/to/your/ios-project

# Install dependencies
pod install

# Open workspace (not .xcodeproj)
open YourApp.xcworkspace
âš ī¸ Important: Always open the .xcworkspace file, not the .xcodeproj file when using CocoaPods.

Step 3: Firebase iOS Configuration

3Add Firebase to your iOS app:

3.1 Register iOS App in Firebase

  1. Go to Firebase Console
  2. Select your project
  3. Click "Add app" and select iOS
  4. Enter your iOS bundle ID (e.g., com.yourcompany.fcmlogin)
  5. Download GoogleService-Info.plist

3.2 Add GoogleService-Info.plist to Xcode

  1. Drag GoogleService-Info.plist into your Xcode project
  2. Make sure "Copy items if needed" is checked
  3. Select your app target
  4. Click "Finish"

3.3 Install Dependencies via CocoaPods

Update your Podfile with required dependencies:

Install the pods:

pod install

Step 4: Configure App Delegate

4Initialize Firebase in your AppDelegate.swift:

Step 5: Update Main App File

5Update your main SwiftUI app file:

Step 6: Configure API Base URL

6Update the API configuration in AppsSetting.swift:

  1. Open customfiles/AppsSetting.swift in Xcode.
  2. Locate the API struct around line 22.
  3. Update rootURL to your server URL:
struct API {
    // Update this to your production URL
    static let rootURL = "https://your-domain.com"
    // The baseURL will automatically update to use this rootURL
    static let baseURL = "\(rootURL)/api/v1"
    
    // ...
}

Step 7: Configure Xcode Capabilities

7Enable required capabilities in Xcode:

  1. Select your Project in the Project Navigator
  2. Select the App Target
  3. Go to the Signing & Capabilities tab
  4. Click + Capability and add:
    • Push Notifications (Required for FCM)
    • Background Modes → Check Remote notifications

Step 8: Configure Info.plist

8Add required permissions and URL schemes to Info.plist:

Step 9: Build and Run

9Build and run your app:

  1. Select your target device or simulator in Xcode
  2. Press Cmd + R or click the Run button
  3. Wait for the build to complete
  4. Test authentication and push notifications
✅ Success! Your iOS app is now configured and ready to integrate with the Laravel backend!
đŸ“Ļ Postman Collection: Use the provided Postman collection to test all API endpoints and understand request/response formats. This will help you implement the API calls in your iOS app.

🔔 iOS Push Notification Setup

Complete guide to configuring Apple Push Notification service (APNs) and Firebase Cloud Messaging (FCM).

âš ī¸ Prerequisites: You must have an active Apple Developer Program membership (Individual or Organization) to create APNs keys and certificates.

Step 1: Create APNs Authentication Key

1Generate a key in Apple Developer Console:

  1. Log in to Apple Developer Console
  2. Go to Certificates, Identifiers & Profiles
  3. Select Keys from the sidebar
  4. Click the + button to create a new key
  5. Enter a name (e.g., "FCM Push Key")
  6. Check Apple Push Notifications service (APNs)
  7. Click Continue and then Register
  8. Download the .p8 file (save this securely, you can only download it once!)
  9. Note your Key ID and Team ID (from the top right corner)

Step 2: Configure Firebase Console

2Upload your APNs key to Firebase:

  1. Go to Firebase Console
  2. Open your project and go to Project settings (gear icon)
  3. Select the Cloud Messaging tab
  4. Scroll to Apple app configuration
  5. Under APNs Authentication Key, click Upload
  6. Upload the .p8 file you downloaded in Step 1
  7. Enter your Key ID and Team ID
  8. Click Upload

Step 3: Xcode Capabilities

3Enable Push Notifications in Xcode:

  1. Open your project in Xcode
  2. Select your App Target
  3. Go to Signing & Capabilities tab
  4. Click + Capability
  5. Search for and add Push Notifications
  6. Click + Capability again
  7. Search for and add Background Modes
  8. Check Remote notifications under Background Modes
📝 Note: Ensure your App Bundle ID in Xcode matches the Bundle ID registered in Firebase Console.

Step 4: Testing Push Notifications

4Verify the integration:

🔌 API Reference

Complete API documentation for integrating with the Laravel backend.

📝 Base URL: http://localhost:8000/api/v1 (Development)
🔐 Authentication: Bearer Token (Laravel Sanctum)

Authentication Endpoints

Register POST

Endpoint: /auth/register

Description: Register a new user account with email verification

Required Fields: username, email, password, mobile_no

Login POST

Endpoint: /auth/login

Description: Authenticate user and create session. Returns bearer token for subsequent requests.

Required Fields: email, password, device_name, device_os, app_version

Social Login POST

Endpoint: /auth/social

Description: Authenticate with social providers (Google, Apple, Facebook)

Required Fields: provider, id_token, device_name, device_os, app_version

Firebase Verify POST

Endpoint: /auth/firebase/verify

Description: Verify Firebase ID token and authenticate

Required Fields: firebase_id_token, device_name, device_os, app_version

Forgot Password POST

Endpoint: /auth/forgot-password

Description: Send password reset link to user's email

Required Fields: email

Reset Password POST

Endpoint: /auth/reset-password

Headers: Authorization: Bearer {token}

Description: Change user password (requires authentication)

Required Fields: old_password, new_password, new_password_confirmation

User Profile Endpoints

Get Profile GET

Endpoint: /me

Headers: Authorization: Bearer {token}

Update Profile PUT POST

Endpoint: /me

Headers: Authorization: Bearer {token}

Description: Update user profile information

Optional Fields: username, mobile_no, profile_image

Session Management Endpoints

Get All Sessions GET

Endpoint: /sessions

Headers: Authorization: Bearer {token}

Description: Get all active sessions for the authenticated user

Delete Specific Session DELETE

Endpoint: /sessions/{id}

Headers: Authorization: Bearer {token}

Description: Logout from a specific device

Delete All Sessions DELETE

Endpoint: /sessions

Headers: Authorization: Bearer {token}

Description: Logout from all devices

Push Notification Endpoints

Update FCM Token POST

Endpoint: /fcm-token

Headers: Authorization: Bearer {token}

Description: Update FCM token for authenticated user (secured with bearer token)

Required Fields: fcm_token (20-500 characters)

Rate Limit: 20 requests per minute

Error Responses

All error responses follow this format:

{
    "message": "The given data was invalid.",
    "errors": {
        "field_name": [
            "Error message here"
        ]
    }
}
Status Code Description
200 Success
201 Created
400 Bad Request
401 Unauthorized
403 Forbidden
404 Not Found
422 Validation Error
429 Too Many Requests (Rate Limited)
500 Internal Server Error

đŸ—‘ī¸ Account Deletion

Secure account deletion feature with email confirmation and time-limited links.

âš ī¸ Important: Account deletion is permanent and irreversible. All user data will be permanently deleted from the system.

How It Works

  1. User requests account deletion from the app (requires authentication)
  2. System sends a confirmation email with a secure deletion link
  3. Link is valid for 10 minutes only
  4. User clicks the link to confirm deletion
  5. Account and all associated data are permanently deleted
  6. User sees a success page confirming deletion

API Endpoints

Request Account Deletion POST

Endpoint: /account/delete/request

Headers: Authorization: Bearer {token}

Rate Limit: 5 requests per minute

Description: Request account deletion. User is identified from bearer token. No body required. Sends confirmation email with deletion link valid for 10 minutes. User must click the link in email to complete deletion.

Security Features

💡 Best Practice: Always show a confirmation dialog in your iOS app before calling the deletion request API. Inform users that they will receive an email and must click the link to complete deletion.

📄 CMS Pages & App Settings

Dynamic content management system for app pages and settings.

Overview

The CMS system allows you to manage dynamic content pages and app-wide settings from the admin panel:

API Endpoints

1. Get App Settings GET

Endpoint: /app-settings

Authentication: Not required (public)

Description: Get app-wide settings including maintenance mode status, app versions, and force update flags.

Returns: maintenance_mode, maintenance_message, ios_version, ios_force_update, android_version, android_force_update, app_name, support_email

2. Get All CMS Pages GET

Endpoint: /cms-pages

Authentication: Not required (public)

Description: Get all published CMS pages with their content.

Returns: Array of pages with id, title, slug, content (HTML), created_at, updated_at

3. Get Single CMS Page GET

Endpoint: /cms-pages/{slug}

Authentication: Not required (public)

Description: Get a specific CMS page by its slug (e.g., privacy-policy, terms-of-service).

Returns: Page object with id, title, slug, content (HTML), created_at, updated_at

Maintenance Mode Implementation

Check maintenance mode status on app launch using the /app-settings endpoint. If maintenance_mode is true, display the maintenance screen with the provided message.

Common Use Cases

📜 Legal Pages

Privacy Policy, Terms of Service, GDPR compliance pages

â„šī¸ Information Pages

About Us, FAQ, Help Center, Contact Information

🔧 Maintenance Mode

Show maintenance screen when app is being updated

📱 Version Control

Force update prompts for critical app updates

💡 Pro Tip: Cache CMS pages locally in your iOS app and refresh periodically. This ensures content is available even when offline and reduces API calls.

đŸ’Ŧ Support & Contact

📧 Need Help? Our support team is here to assist you with any issues or questions you may have.

Contact Information

📧 Email Support

Email: lpktechno02@gmail.com

Get help via email for detailed technical issues and inquiries.

đŸ’ŧ Skype/Teams

ID: lpktechnosoft

Connect with us on Skype or Microsoft Teams for real-time support.

🕐 Support Hours

Time: 9:00 AM - 6:00 PM

Timezone: Indian Standard Time (IST)

Monday to Friday

Before Contacting Support

âš ī¸ Important: Please check the common issues in the Troubleshooting section below before reaching out to support. Many common problems have quick solutions documented there.

When Contacting Support, Please Include:

  1. Purchase Code: Your unique purchase/license code for verification
  2. Specific Error Details:
    • Complete error message from console/logs
    • Screenshot of the error (if applicable)
    • Steps to reproduce the issue
  3. Environment Information:
    • PHP version (php -v)
    • Laravel version
    • iOS version and Xcode version (for iOS issues)
    • Operating system (macOS, Windows, Linux)
  4. What You've Tried: List any troubleshooting steps you've already attempted

Support Response Time

We strive to respond to all support requests within:

💡 Pro Tip: For faster resolution, include screenshots, error logs, and your environment details in your first message. This helps us diagnose and solve your issue more quickly!

Email Template for Support Requests

Subject: [FCM Login] - [Brief Description of Issue]

Purchase Code: YOUR_PURCHASE_CODE_HERE

Issue Description:
[Describe your issue in detail]

Environment:
- PHP Version: 
- Laravel Version: 
- iOS Version (if applicable): 
- Xcode Version (if applicable): 
- Operating System: 

Error Message/Console Output:
[Paste error message or attach screenshot]

Steps to Reproduce:
1. 
2. 
3. 

What I've Tried:
- 
- 

Additional Information:
[Any other relevant details]

🔧 Troubleshooting

Laravel Backend Issues

Database Connection Error

Error: SQLSTATE[HY000] [2002] Connection refused

Solution:

Firebase Admin SDK Error

Error: Firebase credentials file not found

Solution:

Storage Link Error

Error: The [public/storage] link already exists

Solution:

# Remove existing link
rm public/storage

# Recreate link
php artisan storage:link

Email Not Sending

Solution:

iOS App Issues

CocoaPods Installation Failed

Error: Unable to find a specification for Firebase

Solution:

# Update CocoaPods repository
pod repo update

# Clean and reinstall
pod deintegrate
pod install

GoogleService-Info.plist Not Found

Solution:

Firebase Not Initializing

Error: Firebase app not configured

Solution:

API Connection Failed

Error: The resource could not be loaded because the App Transport Security policy requires the use of a secure connection

Solution: For development with HTTP (localhost), add to Info.plist:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>
âš ī¸ Warning: Remove this for production builds. Use HTTPS in production.

Push Notifications Not Working

Solution:

Common Integration Issues

401 Unauthorized Error

Solution:

422 Validation Error

Solution:

CORS Error

Solution:

Getting Help