Repository navigation
Feat(authentication) login and secure session restoration - #17
Open
diego31anaya wants to merge 18 commits into
Open
diego31anaya wants to merge 18 commits into
diego31anaya wants to merge 18 commits into
Conversation
…r session restoration failure
…h face AuthGateway
…if there is an error
…nd Spinner when loading
…nction used when users session expires. Removed fake AuthGateway
…g, and TokenStore
15 of 20 tasks
…ary AppErro to TokenStore.ts until API is merged. Other files updated their imports to these 2 for now.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Resolves #7 : Connect login and implement secure session restoration
Added files:
src/features/auth/components/error-screen.tsx- Shows Retry and Sign Out actions when session restoration fails.src/services/auth/AuthGateway.ts- Connects login and validation to the shared API client; has logout.src/services/auth/decodeJWT.ts- Decodes JWT payload claims used to populate the session user.src/services/storage/TokenStore.ts- Reads, saves, and deletes the token through Expo SecureStore.src/types/authGateway.ts- Gateway interface and login response type.test/authentication.test.tsx- Covers the issue’s login, restoration, expiry, storage, logout, and protected-navigation cases.test/fixtures/renderAnonymous.ts- Helper router for testingUpdated:
app/(app)/(tabs)/profile.tsx- Added loading and error handling for Sign Out.app/(public)/sign-in.tsx- Connected the Sign In button, added field validation and error handling, kept dev loginapp/_layout.tsx- Added the session-restoration error screen and routed expired sessions to Sign In.src/providers/SessionProvider.tsx- Added login, token restoration, expiry, sign-out cleanup, and fake student/mentor sessions.src/state/session.ts- Added expired and recoverable error states and their SessionAction.test/SessionProvider.test.tsx- Updated provider tests for QueryProvider and asynchronous session changes.test/navigation.test.tsx- Moved its anonymous-router totest/fixtures/renderAnonymous.tsto be exported and used intest/authentication.test.tsxas well.test/session.test.ts- Changed id to username for SessionUserSigning in makes a request to the backend, gets the token and secures it using expo secure store.
On launch we read and check if a user has a saved token. If so we validate it and if it's valid we then authenticate the user.
Sign out deletes the stored token and clears query cache.
Screenshots
Loading while signing in

Error state when signing in

Connection error when signing in

Error screen if an error is thrown while restoring session on app launch

Test
Run test with:

npm test -- authentication.test.tsx
Result:
Notes
UI for the error screen needs some work.
All of these files depend on Brandons API and will need to be updated once his branch is merged. For now I created fake version of Brandons code and the files imported them:
app/(app)/(tabs)/profile.tsx- imports AppError from TokenStore.tsapp/(public)/sign-in.tsx- imports AppError from TokenStore.tssrc/providers/SessionProvider.tsx- imports AppError from TokenStore.tssrc/services/auth/AuthGateway.ts- Contains temporary fakeApiClientsrc/services/storage/TokenStore.ts- Contains temporary AppErrortest/authentication.test.tsx- imports AppError from TokenStore.ts