-
Notifications
You must be signed in to change notification settings - Fork 2
Backend Migration #203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Backend Migration #203
Changes from all commits
Commits
Show all changes
88 commits
Select commit
Hold shift + click to select a range
a885feb
Initial login refactor
caleb-bit 6e81124
Merge branch 'main' into Caleb/LoginRefactor
caleb-bit 526b824
Merge branch 'main' of https://github.com/cuappdev/eatery-blue-androi…
caleb-bit 900f4b5
Initial login route refactor
caleb-bit 890cafa
Merge branch 'main' of https://github.com/cuappdev/eatery-blue-androi…
caleb-bit 1e1529d
Remove netID from settings
caleb-bit 44a3e15
Implement transactions retrieval plus internal refactoring
caleb-bit 3e6528a
Fix exposed loadedUser variable, use firstOrNull, plus other minor fi…
caleb-bit 8aebb23
Initial migration to new backend
caleb-bit 1aff093
Remove no longer used buildConfigFields
caleb-bit 306a021
Fix financials and login routes and use flows for account page
caleb-bit 810228c
Fix time zone issue with transaction times
caleb-bit b95817e
Keep user logged in
caleb-bit 00eb765
Fix favoriting routes
caleb-bit 06c3021
Complete favoriting logic
caleb-bit 60f3e33
Fix logout behavior
caleb-bit b756317
Fix meal filter formatting
caleb-bit b5af0f4
Fix capitalized meal times in details screen
caleb-bit c995b42
Improve code quality in Eatery
caleb-bit a99f6cd
Refresh favorites when HomeScreen opens
caleb-bit 4928943
Implement in-app updates
caleb-bit edb57ac
Clean up comments
caleb-bit 8c33e01
Clean up logging
caleb-bit 33c51da
Merge pull request #206 from cuappdev/Caleb/inAppUpdate
caleb-bit 4cba7b2
Revert favoriting to local
caleb-bit d13617c
Merge pull request #207 from cuappdev/Caleb/revert-favoriting
caleb-bit fb20b81
Implement error handling system for networking calls
caleb-bit bd9063e
Implement toast error handling
caleb-bit 7bf04e8
Initial plan
Copilot 9f18541
Fix: only call getFinancials() when linkGETAccount succeeds
Copilot 60fb166
Merge pull request #208 from cuappdev/copilot/sub-pr-203
caleb-bit cb7a73b
Remove redundant UUID creation
caleb-bit 42d0f9f
Make LoginViewModel correctly observe userRepository
caleb-bit 38016cb
Create VM for settings
caleb-bit a4cd589
Fix issue with menuItemsToEateries
caleb-bit fc0be18
Use safer calls
caleb-bit e8c2e95
Fix incorrect documentation
caleb-bit dbbc137
Initial plan
Copilot 23dfd55
Fix memory leak: store and unregister flexible update listener in Mai…
Copilot dd37573
Remove redundant preview
caleb-bit 69ac9aa
Minor code improvements to LoginViewModel
caleb-bit 17c11fe
Extract unregistering listener logic
caleb-bit 78c1f03
Merge pull request #209 from cuappdev/copilot/sub-pr-203
caleb-bit 7bc2278
Remove runBlocking call
caleb-bit 1987c22
Improve redundant computation
caleb-bit e5c5ce3
Use null-safe access
caleb-bit 892c76d
Remove debugging variable
caleb-bit 9cf0dc7
Reuse function
caleb-bit c319240
Fix visibility issue
caleb-bit 8f72059
Fix typo
caleb-bit 84717d4
Use setPref helper
caleb-bit fb6cf94
Fix import issue
caleb-bit d977e0c
Merge
caleb-bit 4629308
Simplify function
caleb-bit 3115631
Import UUID
caleb-bit eed01f9
Use flows in UserPreferencesRepository
caleb-bit b78ecef
Fix name typo
caleb-bit fe03d2c
Simplify collection transformation
caleb-bit 70690dd
Clean up EateryMenusBottomSheet.kt
caleb-bit 4af08a1
Add preview for EateryDetailScreen
caleb-bit f281e01
Prevent race condition from getDeviceId
caleb-bit 61becf2
Use collectAsStateWithLifecycle
caleb-bit 7943032
Unregister listener in onStop
caleb-bit 8a25535
Improve flow practice
caleb-bit feead08
Add limit count and duplicate checking to recent searches
caleb-bit 8ca48fe
Extract AuthTokenRepository from UserRepository
caleb-bit bcb87c7
Remove redundant comments
caleb-bit 116c7b2
Remove one-item column
caleb-bit 4be93e9
Remove duplicate statusBarPadding
caleb-bit b89f021
Fix index issue
caleb-bit 17168e8
Add preview for EateryMenusBottomSheet
caleb-bit 3101ba4
Replace spacer with divider
caleb-bit 1d12c4f
Hoist filterText
caleb-bit daefb4b
Add key for lazycolumn
caleb-bit c63bb3b
Replace spacers with dividers
caleb-bit 2fa4e39
Hoist date formatting logic
caleb-bit 5ae05e6
Fix inefficient recomputation
caleb-bit 3b52440
Prevent passing state down
caleb-bit 275a709
Use firstOrNull() instead of first()
caleb-bit aba118d
Fix logout behavior
caleb-bit 6ea6e01
Initial plan
Copilot 4b3725d
Encrypt sensitive auth credentials stored in DataStore at rest
Copilot 8e51104
Implement OkHttp interceptor
caleb-bit aca978c
Extract functionality
caleb-bit 4ebe6e5
Remove unnecessary legacy handling
caleb-bit 8ae1fe7
Ensure backward compatibility in user_prefs
caleb-bit ead488c
Merge branch 'Caleb/LoginRefactor' of https://github.com/cuappdev/eat…
caleb-bit 93edb40
Merge pull request #210 from cuappdev/copilot/sub-pr-203
caleb-bit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
app/src/main/java/com/cornellappdev/android/eatery/data/AuthInterceptor.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package com.cornellappdev.android.eatery.data | ||
|
|
||
| import com.cornellappdev.android.eatery.data.repositories.AuthTokenRepository | ||
| import kotlinx.coroutines.runBlocking | ||
| import okhttp3.Interceptor | ||
| import okhttp3.Request | ||
| import okhttp3.Response | ||
| import javax.inject.Inject | ||
| import javax.inject.Provider | ||
|
|
||
| /** | ||
| * OkHttp interceptor that automatically adds Bearer token to authenticated requests. | ||
| * Also handles token refresh on 401 responses. | ||
| * | ||
| * Uses Provider<AuthTokenRepository> to avoid circular dependency | ||
| */ | ||
| class AuthInterceptor @Inject constructor( | ||
| private val authTokenRepositoryProvider: Provider<AuthTokenRepository> | ||
| ) : Interceptor { | ||
|
|
||
| companion object { | ||
| private val PUBLIC_ENDPOINTS = setOf( | ||
| "/eateries/", | ||
| "/auth/verify-token", | ||
| "/auth/refresh-token" | ||
| ) | ||
| } | ||
|
|
||
| override fun intercept(chain: Interceptor.Chain): Response { | ||
| val request = chain.request() | ||
|
|
||
| if (!isPublicEndpoint(request)) { | ||
| val requestWithToken = addTokenToRequest(request) | ||
| var response = chain.proceed(requestWithToken) | ||
|
|
||
| if (response.code == 401) { | ||
| response.close() | ||
| try { | ||
| runBlocking { | ||
| authTokenRepositoryProvider.get().refreshTokens() | ||
| } | ||
| val retryRequest = addTokenToRequest(request) | ||
| response = chain.proceed(retryRequest) | ||
| } catch (_: Exception) { | ||
| return chain.proceed(request) | ||
| } | ||
| } | ||
|
|
||
| return response | ||
| } | ||
|
|
||
| return chain.proceed(request) | ||
| } | ||
|
|
||
| private fun addTokenToRequest(request: Request): Request { | ||
| return try { | ||
| val token = runBlocking { | ||
| authTokenRepositoryProvider.get().getAccessToken() | ||
| } | ||
| request.newBuilder() | ||
| .header("Authorization", token) | ||
| .build() | ||
| } catch (_: Exception) { | ||
| request | ||
| } | ||
| } | ||
|
|
||
| private fun isPublicEndpoint(request: Request): Boolean { | ||
| val path = request.url.encodedPath | ||
| return PUBLIC_ENDPOINTS.any { path.startsWith(it) } | ||
| } | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.