I am making the auth portion of the app (login,register,forgot password pages). since i have a function that handles the errors which i call for all the different transactions (log in, log out, register user, etc) and if it catches that error then it sets a custom message to a variable in my viewmodel(environmentObject) which then is observed by a view on the screen that draws it to the screen accordingly.
Problem is that if i get an error in login page and say navigate to forgot password then the error is still saved on that viewmodel variable and since it is also observed from forgot password page then it gets displayed on this page even though it has nothing to do with it. (this happens between all screens not just those two). The fix i have in mind is resetting the variable every time i navigate into a new page, however i have no clue how to do this swift. Using swiftUI
I have tried using init block and reset the variable there however init runs before my environmentObject is initialized therefore I cannot set a member variable there.