Implement Firebase Authentication for Server and Client
Summary
This pull request introduces Firebase authentication for both server-side and client-side. It includes the initialization and configuration of Firebase, as well as the implementation of authentication functions and token handling.
Changes
Dependencies Installation
Ran npm i firebase firebase-admin command to install necessary dependencies.
Firebase Configuration
Added Firebase Admin SDK initialization with service account credentials in server.js.
Configured Firebase app and Auth with API key and project settings.
Exported Firebase Admin and Auth instances for use in the application in server.js.
Authentication Implementation
Implemented loginWithFirebaseToken and generateFirebaseToken functions in userController.js.
Integrated token generation functionality into registerUser and loginUser controllers.
Implemented returning Firebase token in response object for registerUser and loginUser controllers.
Added validation and error handling to protect middleware based on token, decodedToken, and non-existing user.
Code Cleanup and Refactoring
Removed redundant imports and Firebase configuration from server.js.
Changed server-side auth to depend on admin authentication in server.js.
Removed redundant import and client-side authentication from registerUser controller in userController.js.
Fixes and Enhancements
Fixed loginWithFirebaseToken auth process, returning user from successful authentication and error handling in userController.js.
Added ID to string conversion, validation, and error handling to generateFirebaseToken in userController.js.
Client-Side Integration
Implemented client-side Firebase configuration in firebaseConfig.js.
Integrated Firebase token generation, user data validation, and error handling into authentication functions in authService.js.
Testing
Performed manual tests for evaluating Firebase token generation.
Additional Information
These changes enhance the security and reliability of the authentication process by leveraging Firebase's robust authentication system.
Proper error handling and validation ensure that the system is protected against invalid tokens and unauthorized access.
Title
Implement Firebase Authentication for Server and Client
Summary
This pull request introduces Firebase authentication for both server-side and client-side. It includes the initialization and configuration of Firebase, as well as the implementation of authentication functions and token handling.
Changes
Dependencies Installation
npm i firebase firebase-admin
command to install necessary dependencies.Firebase Configuration
server.js
.server.js
.Authentication Implementation
loginWithFirebaseToken
andgenerateFirebaseToken
functions inuserController.js
.registerUser
andloginUser
controllers.registerUser
andloginUser
controllers.Code Cleanup and Refactoring
server.js
.server.js
.registerUser
controller inuserController.js
.Fixes and Enhancements
loginWithFirebaseToken
auth process, returning user from successful authentication and error handling inuserController.js
.generateFirebaseToken
inuserController.js
.Client-Side Integration
firebaseConfig.js
.authService.js
.Testing
Additional Information