Firebase Ep.9: Authentication with Google Sign In [DTube exclusive iOS Development tutorial]

in utopian-io •  6 years ago  (edited)


Repository

https://github.com/firebase/firebase-ios-sdk

What Will I Learn?

  • You will learn how to create a Google Sign In button in one of your view controllers in your iOS app.
  • You will learn how to enable users to sign into your iOS app with Google account.
  • You will learn about Firebase Authentication.
  • You will learn to work with GIDSignInDelegate to handle situations such as successful or failed sign in attempts.
  • You will learn how to create a sign out button for the user to log out of the app.

Requirements

  • A Mac running macOS 10.13.2 High Sierra or later
  • Xcode 9.3.1 or later installed
  • Latest version of Cocoapods installed
  • A real iOS device running iOS 11 or later or iOS simulator included in Xcode for testing
  • A Firebase iOS app created in Firebase console if not using starter project below

Before you begin

Download starter project for this video here

Required knowledge

  • A little understanding with Cocoapods
  • A little understanding with UI elements in iOS
  • Fair understanding with the Swift programming language
  • Fair understanding with the user interface of Xcode IDE

Difficulty

Intermediate

Resources

Firebase website: https://firebase.google.com
Firebase documentation: https://firebase.google.com/docs/
Adding Firebase to Xcode project: https://firebase.google.com/docs/ios/setup?authuser=0
Intro to Firebase Authentication: https://firebase.google.com/docs/auth/
Intro to Firebase Authentication in iOS: https://firebase.google.com/docs/auth/ios/start
Firebase documentation on Google Sign In on iOS: https://firebase.google.com/docs/auth/ios/google-signin
Firebase Auth error handling: https://firebase.google.com/docs/auth/ios/errors
Google sign in documentation: https://developers.google.com/identity/sign-in/ios?authuser=0
Firebase iOS SDK Github repository: https://github.com/firebase/firebase-ios-sdk

Overview

In this video, we will be talking about how you can allow your users to sign into your Firebase iOS app with their Google accounts. We will be taking a look at how we can add a button in a view controller to allow the user to tap onto it so that they can sign in. By tapping that button, we will present a view controller that allows the user to enter their username and password of their Google accounts in order to sign in. Depending on whether if the sign in was a success or a failure, we will work with the GIDSignInDelegate to handle both situations. For example, if the sign in was a success, we want to display another view controller, but if the sign in was a failure for any reason, we want to display an alert for the user, letting them know that there is something wrong.

Creating a sign in button

In this tutorial we’re using storyboard to create our user interface. According to Firebase’s documentation, we’re inserting a UIView into the view controller, then we set its UIView custom class to GIDSignInButton. Note that the button won’t appear in the storyboard file, you have to run the app in order to see the button.

UIView in storyboard

Sign into iOS app with Google account

The GIDSignInButton is designed so that when we click on that button, without the need to call the sign in function manually, it will present a view controller where we can sign into a Google account, with a familiar Google sign in interface. After successful sign in, we obtain the credentials then authenticate into our Firebase application.

ViewController.swift

Signing out

A simple do-catch statement in the IBAction method of our sign out button will sign us out of the Firebase application quickly when the user taps on the button when signed in.

loggedInViewController.swift

DTube Video tutorial

Source code

You may download the source code of the final project for reference here

TechCoderX’s Firebase tutorial series

All previous Firebase episodes are made before my transition from YouTube to DTube, so my Firebase YouTube video tutorial links for episode 1 to 8 are included here.

Proof of work done

https://github.com/techcoderx


▶️ DTube
▶️ IPFS
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Video tutorials should teach the user something unique, shouldn't contain ubiquitous functions; the narrator, should name himself at the start of the video and video's narration should be better. The concept in your video tutorial easily be read from the documentation which can be followed by any computer user and your video's narration is tricky to understand. Therefore, in the voting phase, your video tutorial might not be considered.

Guideline References:

  • To be considered for potential reward, end-user focused tutorials must provide clear instructions of substantial project functions that are unique to that specific Open Source project and essential learning requirements for end-users.

  • Tutorials containing process videos, such as gameplay, content creation, simple on-screen instructions, basic instructions for/in ubiquitous functions (Save, Open, Print, etc.), or (4) basic programming concepts (variables, operators, loops, etc.) will not be considered for potential reward.

  • To verify authorship, submissions should include mention of the contributor’s Utopian account name at the beginning of the video.

  • To be considered for potential reward, video tutorials should be presented in an organized and well prepared fashion. Presenters should speak clearly and professionally and videos should not contain any substantial pauses.


Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thank you for the criticism. 🙂

Hey @yokunjon
Here's a tip for your valuable feedback! @Utopian-io loves and incentivises informative comments.

Contributing on Utopian
Learn how to contribute on our website.

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Just an FYI; You are probably going to need to go back and embed the video into the post. That aside, this is a very nice tutorial.

Thank you so much! Your tutorials are extremely helpful for me to make good tutorials although I'm not interested in Flutter 🙃

Nice tutorial! I feel like I can almost do this stuff...haha

Great tutorial. I absolutely love Firebase, I use it almost exclusively for every project I work on now because it negates the need to configure and secure a backend for my web applications. The realtime database and newly introduced FireStore are brilliant, loving the advanced querying features that realtime was missing.