This project integrates multiple social login options, including Google, Facebook, and Twitter, using the OAuth 2.0 protocol to authenticate users in a simple and secure way.
- Integration of multiple social login providers.
- Secure user authentication and session management.
- Utilizes OAuth 2.0 protocol for secure delegated access.
- Backend API to manage user sessions and retrieve user information.
- Docker for running MongoDB and Mongo Express containers.
- Node.js (version 14 or higher recommended).
-
Navigate to the backend directory:
cd backend
-
Install the dependencies:
npm install
-
Start MongoDB and Mongo Express using Docker:
Ensure Docker is running, then execute:
docker-compose up -d
-
Set up environment variables:
Copy the environment variables listed at the end of this README into a
.env
file in the backend directory. -
Start the backend server:
For development:
npm run dev
For production:
npm run build npm start
-
Navigate to the frontend directory:
cd frontend
-
Install the dependencies:
npm install
-
Set up environment variables:
Copy the environment variables listed at the end of this README into a
.env.local
file in the frontend directory. -
Start the frontend application:
npm run dev
The application will be available at http://localhost:5173.
The application uses the OAuth 2.0 protocol for authentication with various social login providers. The flow is as follows:
- User initiates login via the frontend, selecting their preferred social login provider.
- Frontend redirects the user to the provider's OAuth 2.0 authorization endpoint.
- User consents to grant the application access to their information.
- Provider redirects back to the frontend with an authorization code.
- Frontend sends the authorization code to the backend.
- Backend exchanges the authorization code for an access token.
- Backend retrieves user information using the access token and creates a session.
- User is logged in, with session information stored in an HttpOnly cookie for security.
Below is what you need to change.
COOKIE_SECRET=cookie_secret_here
JWT_SECRET=jwt_secret_here
GOOGLE_CLIENT_ID=your_google_client_id_here
GOOGLE_CLIENT_SECRET=your_google_client_secret_here
GITHUB_CLIENT_ID=your_github_client_id_here
GITHUB_CLIENT_SECRET=your_github_client_secret_here
VITE_GOOGLE_CLIENT_ID=your_google_client_id_here
VITE_GITHUB_CLIENT_ID=your_github_client_id_here
Adjust the paths, environment variables, and other configurations as necessary for your project. This README provides a comprehensive guide to setting up and running both the backend and frontend parts of your project, along with a brief overview of the OAuth 2.0 login flow.