All authentication side-effects in AMS are managed through async thunks created with Redux Toolkit’sDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Jay-byte389/AMS/llms.txt
Use this file to discover all available pages before exploring further.
createAsyncThunk. Each thunk lives in src/redux/thunk/authThunk.js and interacts with the src/services/storage.js layer to read and write session data from @react-native-async-storage/async-storage. The authSlice extra reducers respond to the pending, fulfilled, and rejected lifecycle actions of every thunk, keeping the Redux state in sync without any manual boilerplate.
Redux State Shape
| Field | Type | Description |
|---|---|---|
user | object | null | The currently logged-in user object |
isAuthenticated | boolean | true when a valid session is active |
loading | boolean | true during any in-flight async operation |
error | string | null | The most recent error message, or null |
loading is initialised to true (not false) so the app can display a
splash/loading screen while checkAuthSession resolves on first launch
without a flash of the unauthenticated UI.Thunks
checkAuthSession
Reads the persisted session from storage and restores the user into Redux state. This is the very first thunk dispatched in the application — called inside a useEffect on mount in the root navigator.
| Action type | auth/checkAuthSession |
| Parameters | None |
| Returns (fulfilled) | UserObject | null — the stored user, or null if no session exists |
| Returns (rejected) | rejectWithValue(error.message) |
| Case | loading | user | isAuthenticated |
|---|---|---|---|
pending | true | — | — |
fulfilled (user found) | false | user object | true |
fulfilled (no session) | false | null | false |
rejected | false | — | — |
signupUser
Registers a new user by persisting the account to local storage and immediately creating an active session for them.
| Action type | auth/signupUser |
| Returns (fulfilled) | The original userData object |
| Returns (rejected) | rejectWithValue(result.error) from saveUser, or rejectWithValue(error.message) on unexpected throws |
The full user object to register. Must include at minimum
email or mobile
and password fields to allow future login via validateUser.Save account
Calls
saveUser(userData), which appends the new user to the
@registered_users array in AsyncStorage. Returns { success: false, error } if storage fails.Create session
On success, calls
saveLoggedInUser(userData) to write the user under
the @logged_in_user key, establishing an active session.| Case | loading | user | isAuthenticated | error |
|---|---|---|---|---|
pending | true | — | — | null |
fulfilled | false | userData | true | — |
rejected | false | — | — | error string |
loginUser
Validates an existing user’s credentials against local storage and, on success, persists the session.
| Action type | auth/loginuser |
| Returns (fulfilled) | UserObject — the matched user from storage |
| Returns (rejected) | rejectWithValue(result.error) on credential mismatch, or rejectWithValue(error.message) on unexpected throws |
The action type string is
'auth/loginuser' (all-lowercase user) — note
the inconsistency with signupUser and logoutUser. Use the exported thunk
reference directly rather than matching on the string literal to avoid typos.The email address or mobile number used during registration. Passed directly
to
validateUser() in the storage service.The plaintext password to check against the stored user record.
Validate credentials
Calls
validateUser(emailOrPhone, password). Returns
{ success: false, error } if the user is not found or the password does
not match.Persist session
On success, calls
saveLoggedInUser(result.user) to write the session
under @logged_in_user.| Case | loading | user | isAuthenticated | error |
|---|---|---|---|---|
pending | true | — | — | null |
fulfilled | false | user object | true | — |
rejected | false | — | — | error string |
logoutUser
Ends the current session by removing @logged_in_user from AsyncStorage and resetting auth state.
| Action type | auth/logoutUser |
| Parameters | None |
| Returns (fulfilled) | true |
| Case | user | isAuthenticated | loading |
|---|---|---|---|
fulfilled | null | false | false |
Synchronous Actions
clearAuthError
Resets state.error to null. Dispatch this before a new login or signup
attempt to clear any previous error message from the UI.