Search code examples
firebasekotlinaws-amplifykotlin-multiplatform

Kotlin Multiplatform application that connects to serverless backend, neither AWS Amplify nor Firebase can be used


I have the following setup, a Kotlin Multiplatform application that connects to a serverless backend (serverless framework, aws lambda, dynamodb). Now I'd like to get analytics, authentication and push notifications down the line. Both firebase and amplify would do the job just fine, but there's a problem with both. Firebase while it works on Multiplatform common code, it doesn't work well on the serverside with the serverless approach. While amplify doesn't work with the common code at all. What are my options?

I share all of the business logic, only the UI code is done natively.


Solution

  • For anything lacking in the Kotlin Multiplatform world, you can rely on dependency inversion.

    So in common code you'd have & use

    interface AmplifyAnalytics {
        fun sendEvent(event: Event)
    }
    

    In Android & iOS

    class AmplifyAnalyticsImpl : AmplifyAnalytics {
        // My overridden functions
    }
    

    And you can hook up that up to common code by injecting the implementation.