Panahashi Backend uses Firebase Authentication to verify every request to a protected endpoint. Clients authenticate through Firebase on the device and send the resulting ID token to the server. The server validates that token using the Firebase Admin SDK and, if valid, identifies the requesting user by their Firebase UID.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/AndrewwCO/Panahashi-Backend/llms.txt
Use this file to discover all available pages before exploring further.
How Firebase ID tokens work
A Firebase ID token is a short-lived JSON Web Token (JWT) issued by Firebase after a user signs in. It contains the user’s UID, email, sign-in provider, and other claims — all cryptographically signed by Google. When a client callsuser.getIdToken(), Firebase returns this JWT. The Panahashi Backend receives it in the Authorization header, calls FirebaseAuth.getInstance().verifyIdToken(token), and extracts the UID to identify the caller. No session state is stored on the server — every request is validated independently.
Getting an ID token on the client
Obtain an ID token by signing the user in with the Firebase client SDK for your platform. The token is available immediately after a successful sign-in and can be refreshed at any time.- Web (firebase/auth)
- React Native (@react-native-firebase/auth)
Passing the token in API requests
Include the ID token in theAuthorization header of every request to a protected endpoint. Use the Bearer scheme — a space separates Bearer from the token string.
fetch in JavaScript:
Token expiry and refresh
Firebase ID tokens expire after 1 hour. Sending an expired token returns401 Unauthorized. You must refresh the token before making further requests.
Refreshing on demand
CallgetIdToken(true) with forceRefresh: true to get a fresh token immediately, regardless of whether the current token has expired:
- Web (firebase/auth)
- React Native (@react-native-firebase/auth)
Automatic refresh with an auth state listener
The recommended pattern is to listen for auth state changes and always read the token from the current user object. Firebase refreshes the underlying token automatically in the background:Public vs protected endpoints
Some endpoints are intentionally public — they do not require anAuthorization header and return data to any caller. All other endpoints require a valid Firebase ID token.
| Endpoint | Method | Auth required |
|---|---|---|
/health | GET | No |
/api/v1/bakeries | GET | No |
/api/v1/bakeries/nearby | GET | No |
/api/v1/bakeries/{id} | GET | No |
/api/v1/products | GET (with ?bakeryId=) | No |
/api/v1/reviews | GET (with ?bakeryId=) | No |
/api/v1/promotions | GET (with ?bakeryId=) | No |
/api/v1/search | GET | No |
/api/v1/users/* | ALL | Yes |
/api/v1/orders/* | ALL | Yes |
/api/v1/cart/* | ALL | Yes |
/api/v1/favorites/* | ALL | Yes |
/api/v1/loyalty/* | ALL | Yes |
/api/v1/payments/* | ALL | Yes |
/api/v1/upload | ALL | Yes |
/api/v1/stats/* | ALL | Yes |
/api/v1/bakeries/* (write) | POST, PUT, DELETE | Yes |
/api/v1/products/* (write) | POST, PUT, DELETE | Yes |
/api/v1/reviews/* (write) | POST, PUT, DELETE | Yes |
/api/v1/promotions/* (write) | POST, PUT, DELETE | Yes |
Even for public read endpoints, passing a valid token is harmless and may enable additional personalized data in the response (for example, whether a bakery is in the user’s favorites list).
Error responses
The server returns standard HTTP status codes for authentication and authorization failures.401 Unauthorized
Returned when no token is provided, the token is malformed, or the token has expired.- The
Authorizationheader is missing entirely. - The header value does not start with
Bearer. - The token string is truncated or corrupted.
- The token has expired (older than 1 hour) and was not refreshed.
403 Forbidden
Returned when the token is valid but the authenticated user’s role does not permit the requested action. For example, aCUSTOMER attempting to access baker-only or admin-only endpoints.
500 Internal server error
If token verification fails due to a misconfigured Firebase Admin SDK (for example, a missing or invalidserviceAccountKey.json), the server returns a 500. Check the server logs for a FirebaseException or IOException from FirebaseConfig.
Code examples by environment
- React Native
- Web (firebase/auth)
- cURL
Next steps
API reference
Browse every endpoint and see which role is required for each operation.
Roles & permissions
Understand the CUSTOMER, BAKER, and ADMIN role system and how roles are assigned.