Skip to content

Repository files navigation

Authentication

GitHub licensebadgebadgebadge

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

Usage

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

Kotlin

Firebase Initilization

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)
}
}
}

Swift

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
}}...

AuthenticationController

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()
}

UserResponse

Some calls to the AuthenticationController return this response Object

data classUserResponse(
valuid:String,
valemail:String?,
valisAnonymous:Boolean
)

Installation

Check the table below for the compatibilty across Kotlin versions

LibraryKotlin
1.0.01.6.21
1.0.5+1.8.21
1.0.6+2.1.0

Android & KMM

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*\
}
}
... 

KMM

On the module-level, add the library as a dependency

kotlin {
...
sourceSets["commonMain"].dependencies {
api("io.github.mwaibanda:authentication:1.0.5")
}
}

iOS

Swift Package Manager

File > Swift Packages > Add Package Dependency
Add https://github.com/MwaiBanda/Authentication.git
branch origin

JS

npm

npm i https://github.com/MwaiBanda/authentication

Maintainers

Contributing

Feel free to dive in! Open an issue or submit PRs.

License

MIT license © Mwai Banda

About

Multiplatform Firebase Auth Wrapper(Android, iOS & JS)

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages