martin-markovic / learn-connect

Multi-feature platform designed to enhance the online learning experience.
MIT License
0 stars 0 forks source link

Chat #21

Closed martin-markovic closed 1 month ago

martin-markovic commented 1 month ago

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

  1. Dependencies Installation

    • Ran npm i firebase firebase-admin command to install necessary dependencies.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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

Additional Information