đ 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
- Multi-Provider Authentication: Support for email/password, Google, Apple, Facebook,
and Firebase authentication
- Email Verification: Automated email verification system for new registrations
- Password Management: Secure password reset and change functionality
- Session Management: Multi-device session tracking with ability to logout from
specific devices or all devices
- Profile Management: User profile updates with image upload support
Security Features
- Laravel Sanctum: Token-based API authentication
- Session Validation: Custom middleware to validate active sessions
- Rate Limiting: API throttling to prevent abuse
- Firebase Custom Tokens: Support for non-native providers like LinkedIn
Push Notifications
- FCM Integration: Firebase Cloud Messaging for push notifications
- Secure Token Management: Bearer token authenticated FCM token endpoint (POST
/fcm-token)
- Targeted Notifications: Send notifications to specific users or all devices from
admin panel
- Rate Limited: 20 requests/min for token updates
Additional Features
- App Update Check: Version management for iOS and Android platforms
- Onboarding Screens: Customizable onboarding flow for new users
- CMS Pages: Dynamic content management with rich text editor
- Account Deletion: Secure email-based account deletion with 10-minute expiry
- Maintenance Mode: App-wide maintenance mode control
- SwiftUI Design: Modern, declarative UI framework for iOS
- RESTful API: Well-structured v1 API with comprehensive endpoints
đ 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
- Go to Firebase Console
- Click "Add project" and follow the setup wizard
- Enable Authentication methods (Email/Password, Google, Apple, Facebook)
- Enable Cloud Messaging for push notifications
3.2 Download Service Account Key
- In Firebase Console, go to Project Settings â Service Accounts
- Click "Generate new private key"
- Save the JSON file as
firebase-admin.json
- 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
- macOS 12.0 or later - Required for Xcode
- Xcode 14.0 or later - Download from App Store
- iOS 15.0+ Device or Simulator
- Apple Developer Account - For device testing and App Store deployment
- CocoaPods - Dependency manager for iOS
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
- Go to Firebase Console
- Select your project
- Click "Add app" and select iOS
- Enter your iOS bundle ID (e.g.,
com.yourcompany.fcmlogin)
- Download
GoogleService-Info.plist
3.2 Add GoogleService-Info.plist to Xcode
- Drag
GoogleService-Info.plist into your Xcode project
- Make sure "Copy items if needed" is checked
- Select your app target
- Click "Finish"
3.3 Install Dependencies via CocoaPods
Update your Podfile with required dependencies:
ReachabilitySwift - Network connectivity monitoring
FacebookLogin & FBSDKLoginKit - Facebook authentication
- Firebase SDK pods as needed for your app
Install the pods:
pod install
Step 4: Configure App Delegate
4Initialize Firebase in your AppDelegate.swift:
- Import Firebase and FirebaseMessaging
- Call
FirebaseApp.configure() in didFinishLaunchingWithOptions
- Register for remote notifications
- Set up FCM messaging delegate
- Handle device token registration
Step 5: Update Main App File
5Update your main SwiftUI app file:
- Add
@UIApplicationDelegateAdaptor to connect AppDelegate
- This allows SwiftUI to use the AppDelegate for Firebase initialization
Step 6: Configure API Base URL
6Update the API configuration in AppsSetting.swift:
- Open
customfiles/AppsSetting.swift in Xcode.
- Locate the
API struct around line 22.
- 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:
- Select your Project in the Project Navigator
- Select the App Target
- Go to the Signing & Capabilities tab
- 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:
- Camera Permission:
NSCameraUsageDescription - "We need camera access
to capture profile photos."
- Photo Library Permission:
NSPhotoLibraryUsageDescription - "We need
photo library access to upload profile photos."
- FaceID Permission:
NSFaceIDUsageDescription - "We use FaceID to
securely unlock your profile."
- Google Sign-In URL Scheme: Add your Google client ID reversed (found in
GoogleService-Info.plist)
- Facebook URL Scheme: Add your Facebook app ID with
fb prefix
- Query Schemes: Add
fbapi and fb-messenger-share-api
Step 9: Build and Run
9Build and run your app:
- Select your target device or simulator in Xcode
- Press
Cmd + R or click the Run button
- Wait for the build to complete
- 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:
- Log in to Apple Developer Console
- Go to Certificates, Identifiers & Profiles
- Select Keys from the sidebar
- Click the + button to create a new key
- Enter a name (e.g., "FCM Push Key")
- Check Apple Push Notifications service (APNs)
- Click Continue and then Register
- Download the
.p8 file (save this securely, you can only download it once!)
- Note your Key ID and Team ID (from the top right corner)
Step 2: Configure Firebase Console
2Upload your APNs key to Firebase:
- Go to Firebase Console
- Open your project and go to Project settings (gear icon)
- Select the Cloud Messaging tab
- Scroll to Apple app configuration
- Under APNs Authentication Key, click Upload
- Upload the
.p8 file you downloaded in Step 1
- Enter your Key ID and Team ID
- Click Upload
Step 3: Xcode Capabilities
3Enable Push Notifications in Xcode:
- Open your project in Xcode
- Select your App Target
- Go to Signing & Capabilities tab
- Click + Capability
- Search for and add Push Notifications
- Click + Capability again
- Search for and add Background Modes
- 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:
- Run the app on a real iOS device (Push Notifications do not work on Simulator)
- Accept the permission prompt for notifications
- Go to Firebase Console â Messaging
- Create a new campaign
- Enter a title and body
- Select your iOS app as the target
- Send a test message or publish the campaign
đ 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
- User requests account deletion from the app (requires authentication)
- System sends a confirmation email with a secure deletion link
- Link is valid for 10 minutes only
- User clicks the link to confirm deletion
- Account and all associated data are permanently deleted
- 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
- Bearer Token Authentication: Only authenticated users can request deletion
- Email Verification: Confirmation link sent to registered email only
- Time-Limited Links: Deletion links expire after 10 minutes
- One-Time Use: Each deletion token can only be used once
- Rate Limiting: Prevents abuse with 5 requests per minute limit
- Secure Tokens: 64-character random tokens for deletion links
đĄ 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:
- CMS Pages: Create pages like Privacy Policy, Terms of Service, About Us, etc.
- App Settings: Control maintenance mode, app versions, and other global settings
- Rich Text Editor: Summernote editor for formatted content
- Auto-Generated Slugs: URL-friendly slugs created from page titles
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:
- Purchase Code: Your unique purchase/license code for verification
- Specific Error Details:
- Complete error message from console/logs
- Screenshot of the error (if applicable)
- Steps to reproduce the issue
- Environment Information:
- PHP version (
php -v)
- Laravel version
- iOS version and Xcode version (for iOS issues)
- Operating system (macOS, Windows, Linux)
- What You've Tried: List any troubleshooting steps you've already attempted
Support Response Time
We strive to respond to all support requests within:
- Critical Issues: Within 4-6 hours during business hours
- General Inquiries: Within 24 hours
- Feature Requests: Within 48 hours
đĄ 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:
- Verify MySQL is running:
mysql.server status
- Check database credentials in
.env
- Ensure database exists:
CREATE DATABASE fcmlogin;
Firebase Admin SDK Error
Error: Firebase credentials file not found
Solution:
- Verify
firebase-admin.json exists in storage/app/
- Check file permissions:
chmod 600 storage/app/firebase-admin.json
- Verify path in
.env: FIREBASE_CREDENTIALS=storage/app/firebase-admin.json
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:
- Check mail configuration in
.env
- For development, use Mailtrap or MailHog
- Verify queue is running:
php artisan queue:work
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:
- Download from Firebase Console â Project Settings â iOS app
- Drag file into Xcode project navigator
- Ensure "Copy items if needed" is checked
- Verify file is in the app target
Firebase Not Initializing
Error: Firebase app not configured
Solution:
- Verify
FirebaseApp.configure() is called in AppDelegate
- Check
GoogleService-Info.plist is in the project
- Clean build folder:
Cmd + Shift + K
- Rebuild project:
Cmd + B
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:
- Enable Push Notifications capability in Xcode
- Upload APNs certificate to Firebase Console
- Request notification permissions in app
- Verify FCM token is being sent to backend
- Test on physical device (push notifications don't work on simulator)
Common Integration Issues
401 Unauthorized Error
Solution:
- Verify Bearer token is included in Authorization header
- Check token hasn't expired
- Ensure session is still valid (not deleted)
- Login again to get a fresh token
422 Validation Error
Solution:
- Check API request body matches expected format
- Verify all required fields are included
- Check field data types (string, integer, etc.)
- Review error message for specific field issues
CORS Error
Solution:
- Verify
fruitcake/laravel-cors is installed
- Check
config/cors.php configuration
- Add your iOS app domain to allowed origins
Getting Help
đ Additional Resources: