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
importio.github.mwaibanda.authentication.di.Authenticationimportio.github.mwaibanda.authentication.di.initializeoverridefunonCreate() {
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) {
isAuthResult.Success-> {
onSuccess(authResult.data)
}
isAuthResult.Failure-> {
onFailure(authResult.message)
}
}
}import Authentication // Needed when using standalone library
@mainstruct iOSApp:App{init(){Authentication.initialize() // <-- Call `initialize` to init FirebaseApp
}var body:someScene{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 iniflet user = authResult.data {onSuccess(user)}elseiflet error = authResult.message {
// Handle error
}}...Use the to access the shared instance of the AuthenticationController
interfaceAuthenticationController {
funsignInWithEmail(email:String, password:String, onCompletion: (AuthResult<UserResponse>) ->Unit)
funsignUpWithEmail(email:String, password:String, onCompletion: (AuthResult<UserResponse>) ->Unit)
funsignInAsGuest(onCompletion: (AuthResult<UserResponse>) ->Unit)
funcheckAuthAndSignAsGuest(onCompletion: (AuthResult<UserResponse>) ->Unit)
fungetCurrentUser(onCompletion: (AuthResult<UserResponse>) ->Unit)
funisUserSignedIn(onCompletion: (Boolean) ->Unit)
fundeleteUser()
funsignOut()
}Some calls to the AuthenticationController return this response Object
data classUserResponse(
valuid:String,
valemail:String?,
valisAnonymous: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 = \*GITHUBACCESSEMAIL*\
password = \*GITHUBACCESSTOKEN*\
}
}
... 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 - mwai.developer@gmail.com
Feel free to dive in! Open an issue or submit PRs.
MIT license © Mwai Banda