SwiftUI correct login

Dear Developers,


I am making an application in SWIFTUI that is even though useable without logging in, it is using a server with authenticated rest api calls so pretty much pointless. I am trying to figure out a proper way to implement user profile throughout the application with login screen, since many views will have its own rest api call with authentication tokens(correct me if its a bad methodology). The navigation bar would consist of a profile icon so the user can access its own profile anytime. This brings up two of my questions.

First:

-I only found ways like mainview -> body: if ($UserLoggedIn) view1 else view2. Is this really the way swiftui meant to be used? I find this a little less attractive due to profile icon at navigation bar, login anywhere and so on.


Second:

-How may I keep the authentication tokens throughout the application? I found Enviroment object in some stackoverflow like sites others offered Obserable object, Anybody could point out the actual difference? I would like to keep the user logged in (of course if the user toggles the button at login) so he/she does not have to type login information every time they enter the application. Keychain is the way it is used to be implemented?? It is really critical for security reasons, I would like to avoid these problems when hackers access your data.


I would also accept any tutorials that you guys trust from a security standpoint, I study Computer Science, I look for rather advanced tutorials than how to create variables.


ui.: I would rather avoid flutter and other 3rd party libraries, I challenge myself to swiftui for now.


Thank you inadvance,

I appreciate your time and effort

Zahovay

Replies

Hi Zahovay,

currently I am researching for a university project and I am standing in front of the same problem you've mentioned. Did you find a solution for this issue?

Thanks in advance!

Max

So far, I have tried showing a sheet with a welcome message that invites users to login.