# Authentication

Follow the steps to add Email Authentication, Google Authentication and Apple Authentication to your app

# Configure Authentication

  1. Add latest firebase_core (opens new window) package to pubspec.yaml

  2. Add latest firebase_auth (opens new window) package to pubspec.yaml

  3. Go to firebase console of the project

  4. Click Get Started button

  5. Enable Email/Password, Google and Apple authentications

  6. Configuring Android App

    • Go to Project Overview > Project Settings
    • In Your Apps section, choose Android App
    • Download google_services.json and copy to android/app folder
    • Add classpath 'com.google.gms:google-services:4.3.15' to android/build.gradle like this









     























    buildscript {
        ext.kotlin_version = '1.7.10'
        repositories {
            google()
            mavenCentral()
        }
    
        dependencies {
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
            classpath 'com.google.gms:google-services:4.3.15'
        }
    }
    
    allprojects {
        repositories {
            google()
            mavenCentral()
        }
    }
    
    rootProject.buildDir = '../build'
    subprojects {
        project.buildDir = "${rootProject.buildDir}/${project.name}"
    }
    subprojects {
        project.evaluationDependsOn(':app')
    }
    
    tasks.register("clean", Delete) {
        delete rootProject.buildDir
    }
    
    
    • Add apply plugin: 'com.google.gms.google-services' to bottom of android/app/build.gradle
  7. Configuring iOS App

    • Go to Project Overview > Project Settings
    • In Your Apps section, choose iOS App
    • Add team id. This is available at apple developer account (opens new window)
    • Download GoogleService-Info.plist and copy to ios/Runner folder
    • Open Info.plist on Xcode
    • Drag and drop GoogleService-Info.plist to Runner folder in xcode
    • Add the CFBundleURLTypes with reverse client id from GoogleService-Info.plist below into the Info.plist file
    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>com.googleusercontent.apps.xxxxxxxxxxxxxx</string>
            </array>
        </dict>
    </array>
    
    • Inside Podfile uncomment or change it to platform :ios, '12.0'
    • Inside iOS/Flutter/AppFrameworkInfo.plist change MinimumOSVersion to 12.0
    • Delete podfile.lock
    • In terminal, cd ios and run pod install --repo-update

# Adding Authentication (Email+Google+Apple)

  1. Add latest google_sign_in (opens new window) package to pubspec.yaml
  2. Add latest the_apple_sign_in (opens new window) package to pubspec.yaml
  3. Add latest webview_flutter (opens new window) package to pubspec.yaml
  4. Add latest auto_size_text (opens new window) package to pubspec.yaml
  5. Add latest connectivity_plus (opens new window) package to pubspec.yaml
  6. Click Pub get on Android Studio
  7. Download utils folder from here (opens new window) and add it inside lib/ folder
  8. Download tasks folder from here (opens new window) and add it inside lib/ folder
  9. Download authentication folder from here (opens new window) and add it inside lib/services/ folder
  10. Add redirect functionality in splash screen (eg:- Redirect to authentication if user doesn't exist in sqlite, redirect to onboarding if level is 0 and redirect to layout if level = 1)
  11. Delete podfile.lock
  12. In terminal, cd ios and run pod install --repo-update
  13. Run app.
  • If Error - DT_TOOLCHAIN_DIR occur, add the highlighted code on Podfile and repeat steps 11-13



 
 
 
 
 
 



post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
    target.build_configurations.each do |config|
      xcconfig_path = config.base_configuration_reference.real_path
      xcconfig = File.read(xcconfig_path)
      xcconfig_mod = xcconfig.gsub(/DT_TOOLCHAIN_DIR/, "TOOLCHAIN_DIR")
      File.open(xcconfig_path, "w") { |file| file << xcconfig_mod }
    end
  end
end

# Authentication Test

  1. Sign up with Email
  2. Sign out
  3. Login with email wrong Password
  4. Login with wrong email
  5. Login
  6. Sign out
  7. Send forgot Password email
  8. Change Password
  9. Login
  10. Sign out
  11. Clean login details from firestore and firebase authentication
  12. Try registering with google login
  13. Try login with google Login
  14. Try registering with apple Login
  15. Try login with apple Login