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

💋#NFTxCards is one of a kind platform that makes collecting experience exciting and responds to…

Write For Next Level Swift

Living Worlds: A Small (But Handy) New Feature

SwiftUI and the Intermittent EditMode

Manage paging requesting automatically

WhatsApp Communities to make group messaging EVEN BETTER! See what it is all about — HT Tech

WhatsApp Communities to make group messaging EVEN BETTER! See what it is all about - HT Tech

SwiftUI Accessibility: Dynamic Type

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

How To Send Images in The Notification Payload — Firebase

How To Integrate Admob native Ads in iOS CollectionView or TableView Swift

Add Touch ID & Face ID in Swift

Build an Animated Custom Tab Bar in Your iOS Apps