I’ve this logout perform in a singleton “Session”:
func logout() async throws {
strive await app.currentUser?.logOut() // realm logout
setUser(nil) // resets a config variable
NavigationManager.shared.authPath = .init() // resets authentication NavigationPath
}
That is how I route the person into the app’s primary screens in the event that they’re signed in:
Group {
if let config = supervisor.configuration { // If that is nil -> go to auth circulation
OpenSyncedRealmView()
.surroundings(.realmConfiguration, config)
} else {
AuthRouterView()
}
}
When calling the signal out perform from a button within my settings view – the app indicators out efficiently:
Button {
Activity {
strive await session.logout()
}
} label: {
Textual content("signout")
}
When calling the perform from a sheet with a warning – the app will not signal out:
var physique: some View {
VStack {
...
Button {
logoutSheet.toggle()
} label: {
Textual content("signout")
}
...
}
.sheet(isPresented: $logoutSheet) {
VButton {
Activity {
strive await session.logout()
}
} label: {
Textual content("certain?")
}
}
}
[ I get errors (Fatal error: Unexpectedly found nil while unwrapping an Optional value) from places in the app where I utilize variables that I turned nil in my setUser(nil) function call ]
I attempted to put the sheet on the Button within the VStack. It did not assist..