Purpose of Authentication Model
The purpose of building an authentication model is to allow each user to have an account in the app to store their data. This is to ensure the app is personalised to each user.
Goals this week:
- Learn to connect SwiftUI project with Firebase
- Build an authentication model (using Firebase to encrypt each user's account information so that it is secured)
- Build the function to store user data in Firebase Firestore
- Demo of Working authentication
1. Connecting SwiftUI project with Firebase
I followed this tutorial to help me connect swiftui and firebase:
https://www.youtube.com/watch?v=6b2WAePdiqA&t=1241s
https://www.youtube.com/watch?v=6b2WAePdiqA&t=1241s
2. Building Authentication Model
Initially I followed the same tutorial to build my authentication model. However, I realise that this model would reset user's login information once the app is closed (see video).
REDO Authentication model. After reading through all of Firebase documentation on authentication models, along with reading through some StackFlow threads, I finally found the solution! turns out the tutorial I followed had not include an initialiser that checks if user is signed in, so I added in that code:
init() {
// Check if the user is already signed in
if Auth.auth().currentUser != nil {
isUserAuthenticated = true
}
}
Screenshot below shows my app can successfully create user data (both are my account so no breach of privacy hehe):
REDO Authentication model. After reading through all of Firebase documentation on authentication models, along with reading through some StackFlow threads, I finally found the solution! turns out the tutorial I followed had not include an initialiser that checks if user is signed in, so I added in that code:
init() {
// Check if the user is already signed in
if Auth.auth().currentUser != nil {
isUserAuthenticated = true
}
}
Screenshot below shows my app can successfully create user data (both are my account so no breach of privacy hehe):
3. Build the function to store user data in Firebase Firestore
Now that users can create their own account, theres need to be away to store user data in Firestore database - this is to keep track of the accounts made ensuring that no duplicates of emails.
Below are the functions I made to store user data. Each users are assigned a unique UUID that is made up of a string of random numbers and alphabet. User's data will not be stores as their name or any personal identifiers to protect their privacy. Hence they are assigned a unique UUID.
Below are the functions I made to store user data. Each users are assigned a unique UUID that is made up of a string of random numbers and alphabet. User's data will not be stores as their name or any personal identifiers to protect their privacy. Hence they are assigned a unique UUID.
4. Demo of Working authentication :)
As I have not designed the interface, I build a simple login and logout screen to test out my code and authentication model.
Video demo of the app authentication signup & sign in demo :))
Video demo of the app authentication signup & sign in demo :))






Post a Comment