How to write Firebase's instance in Kotlin

Viewed 44
@Module
@InstallIn(ViewModelComponent::class)
class HiltModule {

    @Provides
    fun provideAuthentication(): FirebaseAuth = Firebase.auth
}

Now I'm learning Kotlin. I think if I want to use an instance, I should do it below.

@Module
@InstallIn(ViewModelComponent::class)
class HiltModule {

    @Provides
    fun provideAuthentication(){
       FirebaseAuth = Firebase.auth()
    }
}

But this is not right. why not use Firebase.auth(), using Firebase.auth issue it's instance?

And I have another question. why not using "{}" in fun provideAuthentication(),using only ":" gets property?

1 Answers

The simplest way in which you can do that in Kotlin would be:

@Provides
fun provideFirebaseAuth() = Firebase.auth

So the object that will be injected would be of type FirebaseAuth.

Related