This is a Kotlin Multiplatform project targeting Android, iOS, Web, Desktop, Server.
-
/composeApp
is for code that will be shared across your Compose Multiplatform applications. It contains several subfolders:commonMain
is for code that’s common for all targets.- Other folders are for Kotlin code that will be compiled for only the platform indicated in the folder name.
For example, if you want to use Apple’s CoreCrypto for the iOS part of your Kotlin app,
iosMain
would be the right folder for such calls.
-
/iosApp
contains iOS applications. Even if you’re sharing your UI with Compose Multiplatform, you need this entry point for your iOS app. This is also where you should add SwiftUI code for your project. -
/server
is for the Ktor server application. -
/shared
is for the code that will be shared between all targets in the project. The most important subfolder iscommonMain
. If preferred, you can add code to the platform-specific folders here too.
Learn more about Kotlin Multiplatform, Compose Multiplatform, Kotlin/Wasm…
Note: Compose/Web is Experimental and may be changed at any time. Use it only for evaluation purposes. We would appreciate your feedback on Compose/Web and Kotlin/Wasm in the public Slack channel #compose-web. If you face any issues, please report them on GitHub.
You can open the web application by running the :composeApp:wasmJsBrowserDevelopmentRun
Gradle task.
- UI: Common Jetpack Compose
- Navigation: Compose Navigation
- Dependency Injection: Koin
- Database: Room Database
- Date Handling: Platform-specific library
- Shared ViewModel: SharedViewModel across all platforms
- Background Work: Coroutines
- ** Work in Progress
Check Daily Update |
---|
Screen.Recording.2024-07-16.at.10.59.07.AM.mp4 |
Landing | Sign In | Sign Up | Error on Sign In |
---|---|---|---|
![]() |
![]() |
![]() |
![]() |
Loading | Home | Add Task |
---|---|---|
![]() |
![]() |
![]() |
Landing | Sign In | Sign Up | Error on Sign In |
---|---|---|---|
![]() |
![]() |
![]() |
![]() |
Loading | Home | Add Task |
---|---|---|
![]() |
![]() |
![]() |
Landing | Sign In | Sign Up | Error on Sign In |
---|---|---|---|
![]() |
![]() |
![]() |
![]() |
Loading | Home | Add Task |
---|---|---|
![]() |
![]() |
![]() |
This project is a Ktor-based web application that provides user authentication and protected routes. The application allows users to sign up, sign in, and access a protected endpoint.
- Getting Started
- Running the Application
- API Endpoints
- Sign Up
- Sign In
- Protected Route
- Configuration
- Built With
- License
These instructions will help you set up and run the application on your local machine for development and testing purposes.
- JDK 8+
- Gradle
- MongoDB Atlas account (for storing user data)
- Clone the repository:
git clone https://github.com/your-username/ktor-application.git
cd ktor-application
- Configure your environment variables:
Create a .env
file in the root directory and add the following environment variables:
JWT_ISSUER=https://your-domain.com/
JWT_AUDIENCE=your-audience
JWT_REALM=your-realm
JWT_SECRET=your-secret
MONGO_PW=your-mongodb-password
- Build the project:
./gradlew build
To run the application, use the following command:
./gradlew run
The server will start on http://localhost:5500
.
URL: http://localhost:5500/signup
Method: POST
Body:
{
"name": "shiv",
"email": "[email protected]",
"password": "test1234"
}
Response:
200 OK
: User successfully registered and returns a JWT token.400 Bad Request
: Invalid request data.
URL: http://localhost:5500/signin
Method: POST
Body:
{
"name": "",
"email": "[email protected]",
"password": "test1234"
}
Response:
200 OK
: Returns a JWT token for authentication.401 Unauthorized
: Invalid credentials.
URL: http://localhost:5500/secret
Method: GET
Headers:
Authorization: Bearer <JWT Token>
Response:
200 OK
: Access to the protected resource.401 Unauthorized
: Invalid or missing JWT token.
The application is configured using the application.conf
file located in the resources
directory. Ensure that the following properties are correctly set:
ktor {
deployment {
port = 5500
}
application {
modules = [ online.nsandroid.ApplicationKt.module ]
}
security {
jwt {
issuer = ${?JWT_ISSUER}
audience = ${?JWT_AUDIENCE}
realm = ${?JWT_REALM}
secret = ${?JWT_SECRET}
}
}
}
The Application.kt
file includes TODO items to enhance the functionality and security of the application. Ensure to address the following:
- TODO: Add proper error handling for all routes.
- TODO: Implement user password hashing before storing in the database.
- TODO: Add logging to monitor application behavior and errors.
- TODO: Secure the
/secret
route to ensure only authenticated users can access it. - TODO: Validate user input to prevent SQL injection and other attacks.
- TODO: Configure CORS to allow requests from trusted origins.
- TODO: Pass database name
val dbName = ""
- TODO: Configure before testing it:
connectionString = "mongodb+srv://<username>:<password>@<cluster-url>/<dbname>?retryWrites=true&w=majority"
- TODO: Before running pass JWT secret here:
const val JWT_SECRET = ""
- TODO: Add MongoDB password here:
const val MONGO_PW = ""
- Ktor - Framework for building asynchronous servers and clients in connected systems.
- KMongo - Kotlin toolkit for MongoDB.
- Gradle - Build tool.
This project is licensed under the MIT License - see the LICENSE file for details.