Skip to content

Conversation

@caleb-bit
Copy link
Contributor

Overview

We now use the new backend routes for login logic.

Changes Made

  • Instead of calling the GET API on the frontend, now we use backend routes that handle authorization.
  • Relevant UI state logic has been updated.
  • We store the device ID in user preferences to keep the user logged in.

Next Steps

We are still awaiting some minor backend updates

  • a meal_swipes field (number of meal swipes left)
  • a transactionType field (+/- of the transaction)

Copy link
Collaborator

@zachseidner1 zachseidner1 left a comment

Choose a reason for hiding this comment

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

Nice job overall, but getting an issue when trying to login which is making this hard to test completely. Lmk what you think!

@Json(name = "wait_times") val waitTimes: List<WaitTimeDay>? = null,
@Json(name = "alerts") val alerts: List<Alert>? = null,
) {
// todo - investigate unused methods
Copy link
Collaborator

Choose a reason for hiding this comment

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

If there are methods that are completely unused, we can just get rid of them

val eateries = getAllEateries()
_eateryFlow.value = EateryApiResponse.Success(eateries)
eateryApiCache.update { map ->
eateryApiCache.update { _ ->
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: we should be able to just remove the _ -> here?

}

suspend fun getDeviceId(): String? {
val id: String? = userPreferencesFlow.first().deviceId
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer firstOrNull to avoid crashes (the string is nullable anyway!)

Comment on lines 12 to 15
/**
* The currently loaded user. Null if no user is logged in.
*/
var loadedUser: User? = null
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should be done with a MutableStateFlow<User>, having one that is private to the repository, and then exposing a StateFlow<User> that the VMs can read from to find the loaded user. We definitely should not be setting a public variable on the repository like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching this. Apparently I somehow forgot about flows when I wrote this.

val bearerToken = "Bearer $sessionId"
val authorizedUser = networkApi.authorizeUser(
sessionId = bearerToken,
loginRequest = LoginRequest(deviceId = deviceId, pin = 1234, fcmToken = fcmToken)
Copy link
Collaborator

Choose a reason for hiding this comment

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

what's the deal with this arbitrary pin? Also, what server URL is this using? When I test this I get this bad request 400 error: {"error":"deviceId, pin required"}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was told by backend to keep that there for now, but I'll check in with them again on that. I am using https://eatery-dev.cornellappdev.com/ for testing.

ExperimentalFoundationApi::class,
ExperimentalAnimationApi::class
)
private fun AccountPageContent(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you for extracting this and denesting the UI! Could we get a preview for this 🥺

onSettingsClicked: () -> Unit,
accountTypeBalance: AccountBalances,
accountFilter: TransactionAccountType,
coroutineScope: CoroutineScope,
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: we can just get this with rememberCoroutineScope

)
_state.value = newState
} catch (e: Exception) {
// todo - error state
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we make a github issue about this so it isn't forgotten? I feel like an error state for failed login is fairly important.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, done.

Comment on lines 161 to 162
val user = userRepository.getUser(sessionId, deviceId, fcmToken)
userRepository.loadedUser = user
Copy link
Collaborator

Choose a reason for hiding this comment

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

we shouldn't have to be doing this setting up of the user. Ideally we should just read the user flow from the repository.

@caleb-bit caleb-bit changed the title Caleb/login refactor Login Refactor 1 Nov 20, 2025
Copy link
Collaborator

@zachseidner1 zachseidner1 left a comment

Choose a reason for hiding this comment

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

This could be working, but due to the BE refactor it cannot be tested. As we discussed this PR will stay in this branch, and you can make another PR into this one for the updated code

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.

3 participants