This backend currently supports:
- Email/phone + password auth with session cookie
- Google login via
POST /auth/google - Facebook login via
POST /auth/facebook - Generic Firebase OAuth login via
POST /auth/firebase - Auto upsert registered form users to Firebase Auth Users (best effort)
- Copy
.env.exampleto.envand fill values. - Install dependencies:
npm install- Run server:
npm run devPOST /auth/registerwith body{ "identifier": "email-or-phone", "password": "...", "displayName": "..." }POST /auth/loginwith body{ "identifier": "email-or-phone", "password": "..." }POST /auth/email-otp/requestwith body{ "email": "user@gmail.com", "purpose": "register|reset" }POST /auth/email-otp/verify-registerwith body{ "email": "user@gmail.com", "code": "123456", "password": "...", "displayName": "..." }POST /auth/email-otp/verify-resetwith body{ "email": "user@gmail.com", "code": "123456", "newPassword": "..." }POST /auth/firebasewith body{ "idToken": "FIREBASE_ID_TOKEN" }POST /auth/googlewith body{ "idToken": "FIREBASE_ID_TOKEN" }POST /auth/facebookwith body{ "idToken": "FIREBASE_ID_TOKEN" }GET /auth/mePOST /auth/logout
- OTP is only for email flow (register by email and forgot-password by email).
- Phone OTP is not implemented (no SMS service configured).
- If mail sender is not configured, API still creates OTP and returns
debugCodein development mode.
- Open Firebase Console.
- Create a project (or use existing one).
- In
Project settings > General, note project id.
- Go to
Authentication > Sign-in method. - Enable
Email/Passwordprovider. - Enable
Googleprovider. - Enable
Facebookprovider:- Enter App ID and App Secret from Meta for Developers.
- Add OAuth redirect URI from Firebase screen to your Facebook app config.
- Go to
Authentication > Templates > SMTP settings. - Turn on
Enable. - Fill fields with your SMTP provider values:
- Sender address: e.g.
support@yourdomain.com - SMTP server host: e.g.
smtp.gmail.com - SMTP server port:
587(STARTTLS) or465(SSL/TLS) - SMTP account username/password: your SMTP credentials
- SMTP security mode:
STARTTLS(for 587) orSSL(for 465)
- Sender address: e.g.
- Save.
- In
Templates, editEmail address verificationandPassword resetcontent/language.
- Go to
Project settings > Service accounts. - Click
Generate new private key. - Download JSON key.
- Configure backend with one option:
- Put key JSON in
FIREBASE_SERVICE_ACCOUNT_JSONas one-line string, or - Set
GOOGLE_APPLICATION_CREDENTIALSto file path.
- Put key JSON in
- User signs in with Firebase Auth (Google/Facebook) on Flutter.
- Flutter gets ID token from Firebase user.
- Flutter calls backend
POST /auth/firebasewith{ idToken }. - Backend verifies token and creates a session cookie.
- This project intentionally uses session cookie only (no custom JWT refresh flow).
- OAuth accounts do not use local password in backend.
POST /auth/registernow includesfirebaseSyncin response body to indicate Firebase upsert status.- Email register/login/reset now uses Firebase Auth email flow:
- Register email: Firebase sends verification email.
- Forgot password: Firebase sends password reset email.
- After email is verified, app exchanges Firebase ID token with backend
/auth/firebaseto create backend session.