Multiplatform Firebase Auth Wrapper For Android, iOS & Js. This library can be used either as a KMM dependency or installed as a standalone library for Android via Maven, iOS with the Swift package manager
and Js with npm
The library exposes a kotlin object called Authentication
that provides instances of the AuthentionController
, a class that makes thread safe asynchronous calls to the AuthenticationService
. A class that makes calls to the Kotlin Firebase SDK @gitlive/firebase-kotlin-sdk
import io.github.mwaibanda.authentication.di.Authentication
import io.github.mwaibanda.authentication.di.initialize
override fun onCreate() {
super.onCreate()
Authentication.initializeApp() // <-- Call `initialize` to init FirebaseApp
}
Use the Authetication object to access the shared AuthenticationController.
val auth: AuthenticationController = Authentication.controller
auth.signInWithEmail(email, password) { authResult ->
when(authResult) {
is AuthResult.Success -> {
onSuccess(authResult.data)
}
is AuthResult.Failure -> {
onFailure(authResult.message)
}
}
}
import Authentication // Needed when using standalone library
@main
struct iOSApp: App {
init() {
Authentication.initialize() // <-- Call `initialize` to init FirebaseApp
}
var body: some Scene {
WindowGroup {
ContentView()
...
Use the Authetication class to access the shared instance of the AuthenticationController.
val controller = Authentication.shared.controller
controller.signInWithEmail(email: email, password: password) { authResult in
if let user = authResult.data {
onSuccess(user)
} else if let error = authResult.message {
// Handle error
}
}
...
Use the to access the shared instance of the AuthenticationController
interface AuthenticationController {
fun signInWithEmail(email: String, password: String, onCompletion: (AuthResult<UserResponse>) -> Unit)
fun signUpWithEmail(email: String, password: String, onCompletion: (AuthResult<UserResponse>) -> Unit)
fun signInAsGuest(onCompletion: (AuthResult<UserResponse>) -> Unit)
fun checkAuthAndSignAsGuest(onCompletion: (AuthResult<UserResponse>) -> Unit)
fun getCurrentUser(onCompletion: (AuthResult<UserResponse>) -> Unit)
fun isUserSignedIn(onCompletion: (Boolean) -> Unit)
fun deleteUser()
fun signOut()
}
Some calls to the AuthenticationController return this response Object
data class UserResponse(
val uid: String,
val email: String?,
val isAnonymous: Boolean
)
Check the table below for the compatibilty across Kotlin versions
Library | Kotlin |
---|---|
1.0.0 | 1.6.21 |
1.0.5+ | 1.8.21 |
1.0.6+ | 2.1.0 |
Add the repository on your Project-level gradle
allprojects {
repositories {
...
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/MwaiBanda/Authentication")
credentials {
username = \* GITHUB ACCESS EMAIL *\
password = \* GITHUB ACCESS TOKEN *\
}
}
...
On the module-level, add the library as a dependency
kotlin {
...
sourceSets["commonMain"].dependencies {
api("io.github.mwaibanda:authentication:1.0.5")
}
}
File > Swift Packages > Add Package Dependency
Add https://github.com/MwaiBanda/Authentication.git
branch origin
npm i https://github.com/MwaiBanda/authentication
- Mwai Banda - [email protected]
Feel free to dive in! Open an issue or submit PRs.
MIT license © Mwai Banda