Skip to content

Feat(authentication) login and secure session restoration - #17

Open
diego31anaya wants to merge 18 commits into
mainfrom
feat(Authentication)-login-and-secure-session-restoration
Open

diego31anaya wants to merge 18 commits into
mainfrom
feat(Authentication)-login-and-secure-session-restoration

Conversation

@diego31anaya

@diego31anaya diego31anaya commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator

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 testing

Updated:

  • 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 login
  • app/_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 to test/fixtures/renderAnonymous.ts to be exported and used in test/authentication.test.tsx as well.
  • test/session.test.ts - Changed id to username for SessionUser

Signing 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
Simulator Screenshot - iPhone 15 Pro - 2026-10-10 at 22 48 16

Error state when signing in
Simulator Screenshot - iPhone 15 Pro - 2026-10-10 at 22 43 54

Connection error when signing in
Simulator Screenshot - iPhone 15 Pro - 2026-10-10 at 22 55 13

Error screen if an error is thrown while restoring session on app launch
Simulator Screenshot - iPhone 15 Pro - 2026-10-10 at 22 50 13

Test

Run test with:
npm test -- authentication.test.tsx
Result:
Screenshot 2026-10-10 at 11 01 04 PM

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.ts
  • app/(public)/sign-in.tsx - imports AppError from TokenStore.ts
  • src/providers/SessionProvider.tsx - imports AppError from TokenStore.ts
  • src/services/auth/AuthGateway.ts - Contains temporary fakeApiClient
  • src/services/storage/TokenStore.ts - Contains temporary AppError
  • test/authentication.test.tsx - imports AppError from TokenStore.ts

…nction used when users session expires. Removed fake AuthGateway
@diego31anaya diego31anaya linked an issue Oct 11, 2026 that may be closed by this pull request
15 of 20 tasks
…ary AppErro to TokenStore.ts until API is merged. Other files updated their imports to these 2 for now.
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: Connect login and implement secure session restoration

1 participant