This project implements a secure authentication system using 42's OAuth service. It provides a simple and efficient way to authenticate users through their 42 accounts, built with Express.js and TypeScript.
- 🔐 Secure OAuth2 authentication with 42
- 🎨 Clean and responsive UI
- 🔄 Session management
- 👤 User profile viewing
- 📱 Mobile-friendly design
- 🛡️ TypeScript implementation for better code safety
Before you begin, ensure you have installed:
- Node.js (v14 or higher)
- npm (v6 or higher)
- A 42 API application (credentials required)
-
Clone the repository:
git clone https://github.com/ygalsk/42LogIn_TypeScript.git cd 42LogIn_TypeScript -
Install dependencies:
npm install express express-session passport passport-42 dotenv npm install --save-dev typescript ts-node @types/express @types/express-session @types/passport nodemon
-
Create
.envfile in the root directory and add your 42 API credentials:CLIENT_ID=your_42_client_id CLIENT_SECRET=your_42_client_secret REDIRECT_URI=http://localhost:8000/auth/42/callback COOKIE_KEY=your_random_secret_key
-
Running the Application:
- Start the development server:
make docker-build && make docker-up
- Start the development server:
-
Access the Application:
- Open your browser and visit:
http://localhost:8000
- Open your browser and visit:
-
Authentication:
- Click on the "Log in with 42" button to authenticate using your 42 credentials.
-
start: Runs the production build of the application.make start
-
dev: Runs the application in development mode usingnodemonfor auto-restart on changes.make dev
-
build: Compiles the TypeScript code to JavaScript.make build
-
watch-ts: Continuously compiles TypeScript code on changes.make watch-ts
-
docker:build: Builds Docker containers usingdocker-compose.make docker-build
-
docker:up: Starts Docker containers usingdocker-compose.make docker-up
-
docker:down: Stops Docker containers usingdocker-compose.make docker-down
-
docker:prod:build: Builds Docker containers for production usingdocker-compose.prod.yaml.make docker-prod-build
-
docker:prod:up: Starts Docker containers for production usingdocker-compose.prod.yaml.make docker-prod-up
-
docker:prod:down: Stops Docker containers for production usingdocker-compose.prod.yaml.make docker-prod-down
-
typeorm: Runs TypeORM CLI commands usingts-node.make typeorm
-
migration:generate: Generates a new migration file.make migration-generate
-
migration:run: Runs pending migrations.make migration-run
-
migration:revert: Reverts the last executed migration.make migration-revert
For detailed information on how the 42 API works, please refer to the 42 API Documentation.
-
Start the Docker containers:
make docker-up
-
Connect to the Node.js container:
docker exec -it <container_name> sh
Replace
<container_name>with the name of your Node.js container.
- Run the migration script inside the container:
make migration-run
- Development Server: The app runs with
nodemonfor automatic restart on code changes. - TypeScript: Ensure TypeScript is properly configured in your
tsconfig.json.
Feel free to suggest further improvements or ask any questions!