Some more context...
I'm building an app with Swiftui. A user can login or sign up (seems to be working!) and then when logged in, fill out a form with a date picker, and textfields. This data is uploaded to firebase successfully in a document and then displayed in a list on the app. No matter which user is signed in the same data is displayed in the list. What I would like to achieve:
Only the signed in user can see the data they have added to their list. Only the signed in user can read, write and delete this data.
Very new to programming, thanks in advance for any help available.
import SwiftUI
import Firebase
import Combine
class SessionStore: ObservableObject {
var didChange = PassthroughSubject<SessionStore, Never>()
@Published var session: User? {didSet{self.didChange.send(self) }}
var handle: AuthStateDidChangeListenerHandle?
func listen() {
handle = Auth.auth().addStateDidChangeListener({ (auth, user) in
if let user = user {
self.session = User(uid: user.uid, email: user.email)
}
else {
self.session = nil
}
})
}
func signUp(email: String, password: String, handler: @escaping AuthDataResultCallback) {
Auth.auth().createUser(withEmail: email, password: password, completion: handler)
}
func signIn(email: String, password: String, handler: @escaping AuthDataResultCallback) {
Auth.auth().signIn(withEmail: email, password: password, completion: handler)
}
func signOut() {
do {
try Auth.auth().signOut()
self.session = nil
}catch {
print("error signing out")
}
}
func unbind() {
if let handle = handle {
Auth.auth().removeStateDidChangeListener(handle)
}
}
deinit {
unbind()
}
}
struct User {
var uid: String
var email: String?
init(uid: String, email: String?) {
self.uid = uid
self.email = email
}
}
