Skip to content

feat(mobile): Zustand auth store for authentication state management (#115)#146

Merged
Oluwaseyi89 merged 4 commits intoNFTopia-Foundation:mainfrom
KevinMB0220:feature/zustand-auth-store-115
Mar 29, 2026
Merged

feat(mobile): Zustand auth store for authentication state management (#115)#146
Oluwaseyi89 merged 4 commits intoNFTopia-Foundation:mainfrom
KevinMB0220:feature/zustand-auth-store-115

Conversation

@KevinMB0220
Copy link
Copy Markdown
Contributor

Closes #115

Summary

Implements a Zustand store for managing authentication state across the mobile app, including user data, wallet info, and authentication status.

  • src/stores/types.tsUser interface and AuthState type contract
  • src/stores/authStore.tsuseAuthStore with persist middleware (AsyncStorage)
  • src/stores/__tests__/authStore.test.ts — 25 integration tests covering all actions

Store design

Concern Decision
Persistence Only user and isAuthenticated are persisted to AsyncStorage via partialize. Wallet keys stay exclusively in SecureStorage — storing key material in plain AsyncStorage would be a security risk.
loginWithWallet Saves wallet to SecureStorage, sets isAuthenticated: true
checkAuth Checks AsyncStorage for a token first, then falls back to SecureStorage wallet — both auth paths are restored on app relaunch
logout Clears both storages and resets all state; storage errors are swallowed so local state is always reset
loginWithEmail / registerWithEmail Stubbed with clear TODO comments for when the API auth service is available
Loading guard All complex actions check isLoading at entry to prevent duplicate in-flight requests

Test plan

  • All 61 tests pass (npx jest --no-coverage)
  • loginWithWallet — success, SecureStorage write, storage error, loading guard
  • loginWithEmail / registerWithEmail — not-implemented error, loading guard
  • logout — state reset, SecureStorage deletion, AsyncStorage removal, error resilience
  • checkAuth — no session, token present, wallet-only session, storage error

Atomic commits

Commit Scope
chore(mobile) Add zustand + async-storage dependencies
feat(mobile) Auth store implementation (types.ts + authStore.ts)
test(mobile) 25 integration tests

KevinMB0220 and others added 3 commits March 28, 2026 10:40
Install zustand for state management and @react-native-async-storage/async-storage
for persistent storage middleware required by the auth store.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Implement useAuthStore with persist middleware (AsyncStorage) covering:
- user, wallet, isAuthenticated, isLoading, error state fields
- loginWithWallet: saves to SecureStorage and marks session authenticated
- loginWithEmail / registerWithEmail: stubbed for future auth service integration
- logout: clears both AsyncStorage token and SecureStorage wallet
- checkAuth: restores session from stored token or wallet on app launch
- Sensitive wallet data is excluded from AsyncStorage persistence (partialize)

Closes NFTopia-Foundation#115

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Cover all store actions with mocked expo-secure-store and AsyncStorage:
- initial state shape
- all simple setters (setUser, setWallet, setAuthenticated, setLoading, setError, clearError)
- loginWithWallet: success, secure storage write, storage error, loading guard
- loginWithEmail / registerWithEmail: not-implemented error, loading guard
- logout: state reset, SecureStorage deletion, AsyncStorage removal, error resilience
- checkAuth: no session, token present, wallet-only session, storage error

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 28, 2026

@KevinMB0220 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@KevinMB0220
Copy link
Copy Markdown
Contributor Author

@Oluwaseyi89 done can you review please?

@Oluwaseyi89
Copy link
Copy Markdown
Contributor

@KevinMB0220 please, resolve the merge conflict. Contact me once done.

@KevinMB0220
Copy link
Copy Markdown
Contributor Author

@KevinMB0220 please, resolve the merge conflict. Contact me once done.

Done can you review @Oluwaseyi89

@Oluwaseyi89 Oluwaseyi89 merged commit 0d10c2a into NFTopia-Foundation:main Mar 29, 2026
1 check passed
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.

Implement Zustand store for managing authentication state across the mobile app

2 participants