📖
AppKickstarter docs
  • Get Started
    • Get started
    • Initialize third parties
    • Project organization
    • Application initialization
  • Tech things
    • Multi modules Architecture
    • Dependency injection
    • Library management
    • Secrets and Build Config
    • Backend as an implementation detail
  • Tutorials
    • Add a login page
    • Add a screen with tab bars
    • Add a settings screen
    • Display an In-App Changelog for a new published version
    • Update localizations
    • Update theme
    • Customize onboarding
    • Setup your paywall
    • Setup your first notifications
    • Format dates and save on database
    • Using a Different Backend Instead of Firebase
    • Make an infinite list with pagination
  • Features
    • Onboarding
    • Authentication
    • Firebase support
    • Offline support
    • Monetization
    • Whats new feature
    • Navigation in AppKickstarter
    • Theme
    • UI Kit
    • Dates management
    • Platform specific
    • Offline cache
    • Translations
    • Analytics
    • User management
    • Logger
    • Platform utilities
    • Maps and locations
    • Secured AI Backend Proxy
    • Settings
    • Application monitoring
    • Notifications
  • UI Kit
    • Adaptive
    • Advanced Components
    • Animated Components
    • Badges
    • Buttons
    • Cards
    • Containers
    • Dialogs
    • EmptyStates
    • Icons
    • Images
    • Lists
    • Modals
    • Tabs
    • Texts
    • Text fields
    • Toasts
    • Toggles
  • Other
    • Known issues
Powered by GitBook
On this page
  • Initialization
  • Authentication
  • Data transfer objects

Was this helpful?

  1. Features

Firebase support

Learn how to use the AppKickstarter Firebase in a multi-platform project for authentication and data transfer objects management.

This documentation outlines the usage of Firebase wrapper in a multi-platform project that supports both Android and iOS platforms. The Firebase module is defined using Koin and provides a set of authentication functions through the KickstarterAuth interface, which can be called by both platforms. Additionally, the KickstarterFirebaseFirestore class provides methods to perform CRUD operations on data transfer objects.

Initialization

Firebase is set up as the default initialization in AppKickstarter. However, the project is designed to allow for the possibility of plugging in other backends like Supabase, Ktor, and others.

To initialize Firebase in the Android project, Koin is used along with the initFirebase function:

initFirebase(this)

initKoin {
    modules(
        listOf(
            module { androidContext(this@KickstarterApplication) },
            androidAppModule,
            firebaseModule
        )
    )
}

The firebaseModule is defined as:

val firebaseModule = module {
    single { Firebase.firestore }
    single { Firebase.auth }
    singleOf(::KickstarterFirebaseAuth).bind(KickstarterAuth::class)
    singleOf(::KickstarterFirebaseFirestore).bind(KickstarterRemoteDB::class)
}

Authentication

The KickstarterAuth interface defines all the possible actions of the backend responsible for authentication. These actions include :

suspend fun signout()
suspend fun getCurrentUser(): CurrentUser?
suspend fun observeAuthStateChanged(): Flow<CurrentUser?>
suspend fun observeSessionStatus(): Flow<SessionStatus>
suspend fun signInAnonymously(): CurrentUser?
suspend fun resetPassword(email: String)
suspend fun updateProfile(displayName: String?, photoUrl: String?)

@Throws(
    BadEmailFormatException::class,
    PasswordInvalidException::class,
    EmptyOrNullValueException::class,
    EmailAlreadyUsedException::class,
    CancellationException::class
)
suspend fun createUserWithEmailAndPassword(email: String, password: String): CurrentUser?

@Throws(
    BadEmailFormatException::class,
    PasswordInvalidException::class,
    EmptyOrNullValueException::class,
    CancellationException::class
)
suspend fun signInWithEmailAndPassword(email: String, password: String): CurrentUser?

Data transfer objects

The KickstarterFirebaseFirestore class provides methods to perform CRUD operations on data transfer objects. For example, the uploadPost(post: Post) function allows creating or updating a post. It uses the PostDto class to handle data transfer objects. The getAllPosts() function fetches all the posts from the Firestore database.

class KickstarterFirebaseFirestore(
    private val firestore: FirebaseFirestore,
    private val auth: KickstarterAuth,
) : KickstarterRemoteDB {

    override suspend fun uploadPost(post: Post): String {
        val postDto = post.toDto() 
        return if (postDto.remoteId == null) {
            create(postDto) 
        } else {
            update(postDto) 
        }
    }

    override suspend fun getAllPosts(): List<PostDto> {
        return getAll("posts")
            .map {
                it.data(strategy = PostDto.serializer()).toPost()
            }
    }
}
PreviousAuthenticationNextOffline support

Last updated 1 year ago

Was this helpful?