commonMain.com.plusmobileapps.firebase.auth.FirebaseAuth.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of auth-jvm Show documentation
Show all versions of auth-jvm Show documentation
A kotlin multiplatform mobile library for authenticating with Firebase for Android, iOS, and JVM
The newest version!
package com.plusmobileapps.firebase.auth
import com.plusmobileapps.firebase.auth.model.FirebaseUser
import com.plusmobileapps.firebase.auth.model.network.models.ChangePasswordResult
import com.plusmobileapps.firebase.auth.model.network.models.ForgotPasswordResult
import com.plusmobileapps.firebase.auth.model.network.models.SignInResult
import com.plusmobileapps.firebase.auth.model.network.models.SignUpResult
import com.plusmobileapps.firebase.auth.util.DateTimeUtilImpl
import com.russhwolf.settings.Settings
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.IO
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
/** firebase-auth-kmp API */
interface FirebaseAuth {
val authState: StateFlow
val isAuthenticated: Flow
fun signOut()
suspend fun signUp(email: String, password: String): SignUpResult
suspend fun signIn(
email: String,
password: String,
): SignInResult
/**
* Send a forgot password request to the following email
*
* @param email User's email address
*/
suspend fun forgotPassword(email: String): ForgotPasswordResult
/**
* Change the password for a user
*
* @param idToken A Firebase Auth ID token for the user.
* @param newPassword User's new password.
*/
suspend fun changePassword(idToken: String, newPassword: String): ChangePasswordResult
suspend fun deleteAccount(): Result
/**
* Get current JSON Web Token that authenticates a user with firebase
* services
*
* @return
*/
suspend fun getJWT(): String?
suspend fun updateProfile(displayName: String?, photoUrl: String?)
suspend fun refreshProfile(): Result
suspend fun refreshJWT(): String?
}
/**
* Create an instance of firebase auth sdk
*
* @param apiKey
* @return
*/
fun createFirebaseAuth(apiKey: String): FirebaseAuth {
val engine = createHttpClientEngine()
val apiClient = ApiClientImpl(
engine = engine,
apiKey = apiKey,
ioContext = Dispatchers.IO
)
return FirebaseAuthImpl(
apiClient = apiClient,
dateTimeUtil = DateTimeUtilImpl(),
cache = CacheImpl(Settings()),
)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy