Authentication
Introduction
Chat21 uses Firebase as backend (a Chat21 standalone engine is under development), and because of this dependency Chat21 actually relies on Firebase for authentication and users' management.
All of these examples are available in the Chat21 Swift Playground project 👉🏻 https://github.com/chat21/chat21-swift-playground. We strongly recommend you to install and configure the playground and use it to try all of these examples.
If you have feedbacks or suggestions about this documentation, please send us an email at support@frontiere21.it. We are always open to improvements coming from Chat21 Community!
Register a new user
To register a new user using email and password you can use directly Chat21 ChatAuth class method createUser, like in the example below:
As soon as you create a user you should save the newly created one in Contacts with ChatUser.createContact method. In this manner his first name and last name become persistent in the cloud of Chat21 and will be available to everyone will connect to your chat.
Sign in with existing user
To sign in with an existing user you can use ChatAuth.auth method:
Every time you sign in with a user remember to instantiate a Chat with that user with ChatManager.start method:
Sign in with Firebase
If you prefer you can sign in directly using Firebase users (for example, if you already use Firebase for your App). Simply remember to create a ChatUser with the Firebase UserId and then start the chat, as in the example below:
Custom authentication
If your app already has his own user base and you just want to add chat features to let users talk with each other the best way is to use custom authentication.
Custom authentication directly relies on Firebase. You must read Firebase documentation available here:
https://firebase.google.com/docs/auth/admin/create-custom-tokens
After you'll login with Firebase Custom Auth you will have to create a ChatUser using the Firebase UserId as in the examples before, then you can start the chat with the ChatManager.start method.
Last updated