Ktor Firebase API is a server-side application built using Kotlin and Ktor that integrates Firebase Authentication and Firestore for secure user registration, login, and profile management.
- 🛡️ Secure Authentication: Firebase Authentication for user sign-up and sign-in.
- 🗄️ Firestore Integration: Store and manage user data securely in Firebase Firestore.
- 🌐 Ktor Framework: Utilize the powerful and flexible Ktor framework for building your API.
- 🔐 User Registration - Sign up new users and store their data in Firestore.
- 🔓 User Login - Authenticate existing users using Firebase Authentication.
- 📄 User Profile - Retrieve and update user profile information stored in Firestore.
- 🔒 Add Password Hashing: Enhance security by hashing user passwords before storing them.
- 🕒 Implement Sessions: Manage user sessions for persistent and secure authentication.
- 📈 Add Analytics: Integrate Firebase Analytics to track user interactions and app performance.
- 🔄 Improve Error Handling: Implement robust error handling and logging mechanisms.
- Endpoint:
/
- Method:
GET
- Description: Returns a simple "Hello World!" message.
- Endpoint:
/signUpFirebase
- Method:
POST
- Description: Registers a new user and stores their data in Firestore.
- Request Body:
{ "username": "string", "email": "string", "password": "string" }
- Responses:
200 OK
: User registered successfully.400 Bad Request
: User already exists or an error occurred.
- Endpoint:
/signInFirebase
- Method:
GET
- Description: Logs in an existing user using their email and password.
- Parameters:
email
: User's email address.password
: User's password.
- Responses:
200 OK
: User logged in successfully.400 Bad Request
: User does not exist or an error occurred.
- Endpoint:
/userProfile
- Method:
GET
- Description: Retrieves the profile information of a logged-in user.
- Parameters:
email
: User's email address.password
: User's password.
- Responses:
200 OK
: User profile retrieved successfully.400 Bad Request
: User does not exist or an error occurred.
- Endpoint:
/updateUser
- Method:
POST
- Description: Updates user information in Firestore.
- Request Body:
{ "username": "string", "email": "string", "password": "string" }
- Responses:
200 OK
: User information updated successfully.400 Bad Request
: User already exists or an error occurred.
The API documentation is available at /swagger
. Access it by navigating to http://localhost:8080/swagger
after starting your Ktor server.
Name | Description |
---|---|
Kotlin |
Programming language used for development. |
Ktor |
Framework for building server-side applications. |
Firebase |
Backend platform for authentication and storage. |
Swagger UI |
API documentation and testing interface. |
-
Create a Firebase Project
- Go to the Firebase Console.
- Click on "Add project" and follow the steps to create a new Firebase project.
-
Obtain Firebase Project ID and Web API Key
- Navigate to Project Settings in the Firebase Console.
- Under the General tab, locate your Project ID and Web API Key.
-
Set up environment variables for your project:
apiKey
: Your Firebase Web API KeyprojectId
: Your Firebase Project ID
For Windows:
set apiKey=your_firebase_api_key set projectId=your_firebase_project_id
For macOS/Linux:
export apiKey=your_firebase_api_key export projectId=your_firebase_project_id
-
Clone the Repository
git clone https://github.com/yourusername/ktor-firebase-api.git cd ktor-firebase-api
-
Build and Run
./gradlew run
That's it! You're now ready to test the api. 🫶🏻