Skip to content

Conversation

@mariana0412
Copy link
Contributor

  • Implemented login to the TDEI server
  • Implemented saving received token and its expiration date to Keychain for using in future requests
  • Added checking if token is present in Keychain and valid in order to decide which screen user should see first - Login or Setup

@himanshunaidu himanshunaidu linked an issue Nov 8, 2024 that may be closed by this pull request

init() {
let isTokenValid = keychainService.isTokenValid()
_isAuthenticated = State(initialValue: isTokenValid)
Copy link
Collaborator

@himanshunaidu himanshunaidu Nov 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So mostly, I do not see a problem with this kind of initialization for this context, despite its misgivings given in:
https://stackoverflow.com/questions/56691630/swiftui-state-var-initialization-issue
More specifically: https://stackoverflow.com/a/71247040

I wonder if there would come a situation where this initialization could cause problems. Most likely it shouldn't.
I'll just keep it in mind.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as a note, we don't have a problem with this way to setting the State because the struct IOSAccessAssessment does not have any dependencies.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this article does mention that this is bad practice, since we are accommodating what may lead to potentially inconsistent behavior:
https://www.swiftcraft.io/articles/how-to-initialize-state-inside-the-views-init-

}
.padding()
.navigationBarTitle("Setup View", displayMode: .inline)
.navigationBarBackButtonHidden(true)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Later we should have a logout feature as well.

@himanshunaidu
Copy link
Collaborator

Error message:
Login failed: The data couldn't be read because it is missing.

Seems to be JSON error, even if the password is the incorrect one.
We can fix this later.

@himanshunaidu
Copy link
Collaborator

Aside from my comments it looks good to me as a first PR for the login page.
You can merge it for now, and we can deal with the UX and coding practice discussion later.

@mariana0412 mariana0412 self-assigned this Nov 20, 2024
@himanshunaidu
Copy link
Collaborator

This is great!
We can merge this.

@himanshunaidu himanshunaidu merged commit 3302960 into main Nov 20, 2024
@himanshunaidu himanshunaidu deleted the feature/login branch January 8, 2025 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Authentication API

3 participants