Documentation 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.
src/services/storage.js is a typed helper layer that wraps @react-native-async-storage/async-storage with named, purpose-specific functions. Rather than calling AsyncStorage.getItem and JSON.parse directly throughout the app, all persistence logic is centralised here. The file covers four concerns: user account registration, session management, favourited doctors, and a local appointment cache. Every function is async and returns a structured result object or typed value — never a raw string.
Storage Keys
| Constant | Key | Stores |
|---|---|---|
USERS_KEY | @registered_users | JSON array of all registered UserObjects |
SESSION_KEY | @logged_in_user | JSON-serialised UserObject of the active session |
FAVOURITE_KEY | @favourite_doctors | JSON array of favourite doctor ID strings |
Appoinment_key | @appoinments | JSON array of locally cached Appointment objects |
The
@appoinments key contains a deliberate typo (single p in
appointments). This matches the constant name Appoinment_key in the
source file. Do not “correct” it in your own reads or writes — changing the
key would orphan any data already stored under the original string.User Account Functions
saveUser(userData)
Appends a new user to the @registered_users array. Reads the existing array first so no data is overwritten.
The user object to persist. Should contain at minimum
email or mobile
(for future lookup) and password. Any additional fields are stored as-is.Promise<{ success: boolean, error?: string }>
getAllUsers()
Reads and deserialises the entire @registered_users array from storage.
Returns Promise<UserObject[]> — an empty array [] if no users have been registered yet, or if a read error occurs.
getUser(emailOrPhone)
Finds a single user by matching the provided string against both user.email and user.mobile fields.
The email address or mobile number to search for. The lookup is
case-sensitive and matches using strict equality (
===).Promise<UserObject | undefined> — undefined if no matching user is found.
validateUser(emailOrPhone, password)
Looks up a user by emailOrPhone and compares the provided password against the stored value. Returns a structured result rather than throwing on credential failure.
The email address or mobile number to look up.
The plaintext password to compare against
user.password.Promise<{ success: boolean, user?: UserObject, error?: string }>
| Scenario | success | user | error |
|---|---|---|---|
| User found, password matches | true | user object | — |
| User not found | false | — | 'User not found. Please sign up first.' |
| Password mismatch | false | — | 'Incorrect password.' |
| Unexpected error | false | — | error.message |
Session Functions
saveLoggedInUser(userData)
Serialises and stores the given user object under @logged_in_user, establishing an active session. Overwrites any previously stored session.
The user object to store as the active session. Typically the object
returned by
validateUser or passed into signupUser.Promise<{ success: boolean, error?: string }>
getLoggedInUser()
Reads the active session from @logged_in_user. Called by the checkAuthSession thunk on every app launch.
Returns Promise<UserObject | null> — null if no session exists or if a read error occurs.
logoutUser()
Removes the @logged_in_user key from AsyncStorage, ending the session. Note that this does not remove the user’s account from @registered_users — they can log in again later.
Returns Promise<{ success: boolean, error?: string }>
Favourites Functions
saveFavourites(ids)
Serialises the given array of doctor ID strings to @favourite_doctors, replacing any previously saved list.
The complete array of doctor IDs to persist. Pass an empty array
[] to
clear all favourites.Promise<void> — errors are caught and logged to the console; no error value is surfaced.
loadFavourites()
Reads and deserialises the favourites list from @favourite_doctors.
Returns Promise<string[]> — an empty array [] if no favourites have been saved yet, or if a read error occurs.
Appointment Functions
saveAppointment(appointment)
Appends a single appointment to the local @appoinments cache. This provides an offline-safe copy independent of the REST API.
The appointment object to append. Should match the shape used by
addAppointment / the REST API.Promise<void> — errors are caught and logged; no error value is surfaced.
getAppoinments()
Reads and deserialises the locally cached appointments list from @appoinments.
The function name
getAppoinments (single p) reflects the spelling in the
source file and must be used exactly as-is when importing. The underlying
storage key @appoinments has the same spelling — both are consistent with
each other.Promise<Appointment[]> — an empty array [] if no appointments are cached, or if a read error occurs.