The Kryptonian App is an application crafted by CelestialCoders to manage user authentication, incorporating Two-Factor Authentication (2FA) with One-Time Passwords (OTP), and secure file uploads. The application follows contemporary RESTful API design principles and utilizes various technologies to guarantee security and efficiency.
-
Kryptonian Registration and Authentication:
- User Registration: Allows new users to register with merely an email address.
- Sends a confirmation email.
- User Login: Authenticates users with email and password.
- Checks if the user's email is confirmed before allowing login.
- Generates an OTP and sends it to the user's email for successful login, also generates a temporary token.
- OTP Generation and Validation: Ensures secure login by generating and validating OTPs.
- Checks if an existing OTP is still valid before generating a new one.
- JWT Token Handling: Issues JWT tokens for authenticated sessions.
- Temporary JWT token issued for OTP validation.
- User Registration: Allows new users to register with merely an email address.
-
File Upload Service:
- Users can upload image files using their API key.
- Uploaded files are stored as Base64 strings in the database.
- Uploaded files are deleted from the system after being stored.
- Only image files are allowed.
-
Image Access:
- Images can be accessed without authentication, as required.
-
Register
-
Registers a new user and sends a confirmation email.
-
POST api/auth/register
-
Request:
{ "email": "[email protected]" }
-
Response:
{ "message": "User registered." }
-
-
Verify OTP
-
Verifies the OTP and logs in the user.
-
POST api/auth/confirm-email
-
Request:
{ "email": "[email protected]", "otp": "198876" }
-
Response:
{ "message": "OTP verified" }
-
- Upload File
- Uploads an image file and associates it with the user.
POST /api/files/upload
- Headers:
{ "x-api-key": "your_api_key" }
- Request: (using Form-data)
Key: file Value: (Select an image file from your system)
- Response:
{ "message": "File uploaded" }
-
Generate Key
-
Generates an API key on Request.
-
POST /api-key/create
-
Response:
{ "apiKey": { "key": "your-api-key", "version": 1, "invalidated": false } }
-
-
Get All Images
- Retrieves all images.
GET /api/images
- Response:
{ "data": [ { "_id": "image_id", "base64": "base64_string_of_image1" }, { "_id": "image_id", "base64": "base64_string_of_image2" } ] }
-
Get Single Image
- Retrieves a single image.
GET /api/images/:id
- Response:
{ "data": { "_id": "image_id", "base64": "base64_string_of_the_image" } }
-
Clone the Repository:
git clone https://github.com/izzdwizz/Kryptonite.git cd Kryptonite
-
Install Dependencies:
npm install
-
Environment Variables: - Create a
.env
file in the root directory. - Add the following environment variables:env PORT=3000 MONGODB_URI=mongodb+srv://uchenduizu:[email protected]/?retryWrites=true&w=majority&appName=Cluster0 REDIS_HOST=127.0.0.1 REDIS_PORT=6379 EMAIL_HOST=gmail [email protected] EMAIL_PASS=nsoptanpcsnjihao
-
Run the Application:
npm start
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Commit your changes (
git commit -m 'Add new feature'
). - Push to the branch (
git push origin feature-branch
). - Open a Pull Request.