Anonymous Login is an easy way for people to try an app without sharing any of their personal information. Sometimes people want to try out apps, but they’re not ready to share any information about themselves. For this, SUSI introduced a way to log in to apps anonymously.
In SUSI iOS we use login and signup to save user’s messages, preferences, settings and secure messages from others. There are Login and Sign up features presents in SUSI iOS app. But the user can also use the app without logging in. Here I will show you, how the anonymous mode implemented in SUSI iOS.
The user can use app either by login using username and password or anonymously by clicking the skip button.
At the time of the login process, we store the user’s data in User object with `accessToken` and during `signout` process we remove the user key from `UserDefaults`. User Defaults is an interface to the user’s defaults database, where user store key-value pairs persistently across launches of the app.
When the user enters in anonymous mode by clicking the Skip button, `currentUser: user` object set to the nil.
Here is how the skip button action implemented in LoginViewController:
- Delete the current Realm database from the device
- Delete the trained voice model from the device
- Reset all settings to default settings
- Set SUSI API URL as server URL
- Enter into chat screen
When the user enters into the Login screen, we check the existing session by `checkSession()` method:
Save user globally so that it can be checked anytime whether the user is logged in or entered anonymously by `currentUser` value nil or not. In the case of anonymous mode, `currentUser` is nil.
The user can always login into the app. If the user is using the app in anonymous mode but he/she want to login then he/she can log in. There is an option for login in Settings Menu.
Clicking on login button, direct user to Login screen where the user can log in with registered email and password.
- User Defaults: https://developer.apple.com/documentation/foundation/userdefaults
- App Delegate: https://developer.apple.com/documentation/uikit/uiapplicationdelegate?hl=et
- SUSI iOS Link: https://github.com/fossasia/susi_iOS