adding logic for getting user details on log in
This commit is contained in:
@@ -34,6 +34,8 @@ final class AuthSessionStore: ObservableObject, SessionStore {
|
|||||||
|
|
||||||
private var handler: AuthStateDidChangeListenerHandle?
|
private var handler: AuthStateDidChangeListenerHandle?
|
||||||
|
|
||||||
|
private var firestoreService: FirestoreService = FirestoreService()
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
// create google sign in configuration object
|
// create google sign in configuration object
|
||||||
let clientID = FirebaseApp.app()?.options.clientID
|
let clientID = FirebaseApp.app()?.options.clientID
|
||||||
@@ -41,6 +43,8 @@ final class AuthSessionStore: ObservableObject, SessionStore {
|
|||||||
|
|
||||||
print("the google client id: prolly shouldn't be printing this: \(clientID)")
|
print("the google client id: prolly shouldn't be printing this: \(clientID)")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
self.setupAuthListen()
|
self.setupAuthListen()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,17 +116,23 @@ final class AuthSessionStore: ObservableObject, SessionStore {
|
|||||||
|
|
||||||
func setupAuthListen() {
|
func setupAuthListen() {
|
||||||
// monitor authentication changes using firebase
|
// monitor authentication changes using firebase
|
||||||
self.handler = Auth.auth().addStateDidChangeListener { (auth, user) in
|
self.handler = Auth.auth().addStateDidChangeListener { [weak self] res, user in
|
||||||
print("auth listener activated")
|
print("auth listener activated")
|
||||||
|
|
||||||
|
guard let self = self else { return }
|
||||||
|
|
||||||
|
|
||||||
// get the user from the auth table in firebase auth
|
// get the user from the auth table in firebase auth
|
||||||
if let user = user {
|
if let user = user {
|
||||||
// if we have a user, create a new user model
|
// if we have a user, create a new user model
|
||||||
print("Got user: \(user.uid)")
|
print("auth listener: Got user: \(user.uid)")
|
||||||
print("phone number: \(user.phoneNumber!)")
|
print("auth listener: phone number: \(user.phoneNumber!)")
|
||||||
|
|
||||||
// TODO: go to firestore and get full user document for the current authenticated user
|
// TODO: go to firestore and get full user document for the current authenticated user
|
||||||
// and have this in environment for all pages to access without having to fetch all the time
|
// and have this in environment for all pages to access without having to fetch all the time
|
||||||
|
|
||||||
|
self.getAndSetEnvironmentUserDetails(userId: user.uid)
|
||||||
|
|
||||||
self.sessionState = .isAuthenticated
|
self.sessionState = .isAuthenticated
|
||||||
} else {
|
} else {
|
||||||
// if we don't have a user, set our session to nil
|
// if we don't have a user, set our session to nil
|
||||||
@@ -131,6 +141,15 @@ final class AuthSessionStore: ObservableObject, SessionStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func getAndSetEnvironmentUserDetails(userId: String) {
|
||||||
|
let firestoreUser: User? = self.firestoreService.getUser(userId: userId)
|
||||||
|
|
||||||
|
// if we get a user back, then set this to our instance to allow UI to get published with all user details
|
||||||
|
if firestoreUser != nil {
|
||||||
|
self.user = firestoreUser
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension UIApplication {
|
extension UIApplication {
|
||||||
|
|||||||
@@ -16,6 +16,11 @@ struct AddBasicInfoView: View {
|
|||||||
|
|
||||||
@State var selectedAvatarIndex: Int = 0
|
@State var selectedAvatarIndex: Int = 0
|
||||||
|
|
||||||
|
var columns: [GridItem] =
|
||||||
|
Array(
|
||||||
|
repeating: GridItem(.fixed(100), spacing: 0, alignment: .center),
|
||||||
|
count: 5)
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ZStack {
|
ZStack {
|
||||||
// bg
|
// bg
|
||||||
@@ -40,30 +45,39 @@ struct AddBasicInfoView: View {
|
|||||||
// header logo area
|
// header logo area
|
||||||
LogoHeaderView()
|
LogoHeaderView()
|
||||||
|
|
||||||
Text("Let's Build Your Profile")
|
// action text
|
||||||
.font(.title)
|
VStack(alignment: .leading) {
|
||||||
.fontWeight(.medium)
|
Text("Let's Build A Profile")
|
||||||
.foregroundColor(NirvanaColor.teal)
|
.font(.title)
|
||||||
.multilineTextAlignment(.center)
|
.fontWeight(.medium)
|
||||||
|
.foregroundColor(NirvanaColor.teal)
|
||||||
|
.multilineTextAlignment(.center)
|
||||||
|
|
||||||
|
Text("Select an avatar you like, then input your first and last name! You can always change this later.")
|
||||||
|
.font(.subheadline)
|
||||||
|
.foregroundColor(Color.black.opacity(0.7))
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
|
||||||
// Horizontal scroll view to allow user to select the avatar he or she wants
|
// Horizontal scroll view to allow user to select the avatar he or she wants
|
||||||
ScrollView(.horizontal, showsIndicators: false) {
|
ScrollView([.horizontal, .vertical], showsIndicators: false) {
|
||||||
LazyHStack {
|
LazyVGrid(columns: columns) {
|
||||||
ForEach(0..<Avatars.avatarSystemNames.count) { index in
|
ForEach(0..<Avatars.avatarSystemNames.count) { index in
|
||||||
Image(Avatars.avatarSystemNames[index])
|
Image(Avatars.avatarSystemNames[index])
|
||||||
.resizable()
|
.resizable()
|
||||||
.scaledToFit()
|
.scaledToFit()
|
||||||
.frame(width: 100, height: 100, alignment: .center)
|
.frame(width: 100, height: 100, alignment: .center)
|
||||||
.blur(radius: self.selectedAvatarIndex == index ? 0 : 4)
|
.blur(radius: self.selectedAvatarIndex == index ? 0 : 1)
|
||||||
|
.scaleEffect(self.selectedAvatarIndex == index ? 1.3 : 1)
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
print("selected another avatar: \(index)")
|
print("selected another avatar: \(index)")
|
||||||
|
|
||||||
self.selectedAvatarIndex = index
|
self.selectedAvatarIndex = index
|
||||||
}
|
}
|
||||||
|
.animation(.spring())
|
||||||
}
|
}
|
||||||
}
|
}.padding(.top, 20)
|
||||||
}
|
}
|
||||||
.padding()
|
|
||||||
|
|
||||||
// input first and last name
|
// input first and last name
|
||||||
VStack {
|
VStack {
|
||||||
@@ -88,10 +102,17 @@ struct AddBasicInfoView: View {
|
|||||||
|
|
||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
// button to save information
|
// button to save information
|
||||||
Button {
|
Button {
|
||||||
|
print("saving information")
|
||||||
|
|
||||||
|
// activate loading splashscreen
|
||||||
|
|
||||||
|
// let view model do work of saving to firestore
|
||||||
|
|
||||||
|
// note: I need these updated attributes to be listened to when loading the circle hub next
|
||||||
|
// but maybe just change the data in cache and no need to re-fetch
|
||||||
} label: {
|
} label: {
|
||||||
Text("Save")
|
Text("Save")
|
||||||
.fontWeight(.heavy)
|
.fontWeight(.heavy)
|
||||||
@@ -102,6 +123,8 @@ struct AddBasicInfoView: View {
|
|||||||
.clipShape(Capsule())
|
.clipShape(Capsule())
|
||||||
.shadow(radius:10)
|
.shadow(radius:10)
|
||||||
}
|
}
|
||||||
|
.offset(x: 0, y: self.firstName.count == 0 || self.lastName.count == 0 ? 200 : 0)
|
||||||
|
.animation(.spring())
|
||||||
.padding()
|
.padding()
|
||||||
}
|
}
|
||||||
.frame(maxHeight: .infinity)
|
.frame(maxHeight: .infinity)
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ import FirebaseAuth
|
|||||||
|
|
||||||
final class PhoneVerificationViewModel : ObservableObject {
|
final class PhoneVerificationViewModel : ObservableObject {
|
||||||
private var firestoreService = FirestoreService()
|
private var firestoreService = FirestoreService()
|
||||||
// TODO: add alert message handler here that publishes changes
|
|
||||||
|
// TODO: add alert message handler here that publishes changes to ui based on business logic errors
|
||||||
|
|
||||||
public func verifyPhoneAndSendSMS(phoneNumber: String) {
|
public func verifyPhoneAndSendSMS(phoneNumber: String) {
|
||||||
// TODO: do some string validation here
|
// TODO: do some string validation here
|
||||||
|
|||||||
Reference in New Issue
Block a user