Lecture Material: Anonymous Login with Firebase

Add new view

Press the Command + N to make new view. And choose Cocoa Touch Class

Check the box on ‘Also create XIB file’ to seperate each files.

Of course, you can combine and place every view into a Main storyboard, but in that case, this file is going to be large and takes a lot of time in every time you open the storyboard file.

And I re-organised directory structures to separate between the view-related files and logic related files.

Set constraints and alignments

Drag the button with pressing Ctrl key, and drop to source code (LoginVC)

Name it the event handler. Make sure the type is ‘UIButton’ and the event is ‘Touch Up Inside’

Refer the official page in Firebase documentation

So, on your button press handler, implement a verification of authenticating as anonymous.

After you execute project in an emulator, you will face with an error

firebase-test[33757:651569] [boringssl] boringssl_metrics_log_metric_block_invoke(144) Failed to log metricsOptional(Error Domain=FIRAuthErrorDomain Code=17085 "ADMIN_ONLY_OPERATION" UserInfo={NSLocalizedDescription=ADMIN_ONLY_OPERATION, FIRAuthErrorUserInfoNameKey=ERROR_ADMIN_RESTRICTED_OPERATION})

This is because you haven’t turned on the anonymous login feature on the Firebase console yet.

Go to the console, and make it enable.

Your anonymous login is working well. And you can check the new auth of user on the Authentication menu.

So, after this, let’s implement the logout feature.

There are several ways to back to the previous screen. In this case, you use ‘dismiss’ method to close the current screen.

After you follow all, you still have to press the sign-in button in every time you opened the app.

To maintain a session and prevent to request login process with signed-in user, you have to check the auth state on the login screen.

To deal with the user auth state and information which is included on the auth. You can check this official doc.

You can see the checking process under the ‘addStateDidChangeListener’.

With this, you don’t need to press the ‘Sign-in’ button again, next time you open the app.




Majored in Physics, self-taught and worked in the IT industry as a Dev/Design/Planning for 11 years. And I had run my Startup for 3 years. I fancy a ☔️ 🇬🇧

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Apple Watch 8 Bug: SwiftUI Navigation Stack pops back with TabView

Upcoming iPhone Car Key Feature Detailed in iOS 13.6 Privacy Screens

Share Common Network Fetching Code for iOS and Android

Protocols with Associated Types in Swift

Create the App Store with UICollectionView Compositional Layouts

Restore your application’s data from iCloud and track progress

Swift 5: Fallthrough Used-Cases You Must Know

Create Flexible Components in Swift

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Fredric Cliver

Fredric Cliver

Majored in Physics, self-taught and worked in the IT industry as a Dev/Design/Planning for 11 years. And I had run my Startup for 3 years. I fancy a ☔️ 🇬🇧

More from Medium

Build your First WatchOS App with SwiftUI— Counter App — Part 2

Generating JWT for AppStore Connect API with JWTKit in Swift

How To Send Images in The Notification Payload — Firebase

Building iOS QR Code Scanner with SwiftUI on M1 Mac