FirebaseApp Client in Scala
How to properly load the FirebaseAuth Java client in Scala
import com.google.auth.oauth2.GoogleCredentials
import com.google.firebase.{ FirebaseOptions, FirebaseApp }
import scala.util.Try
object FirebaseAppLoader {
def apply(credentials: GoogleCredentials): FirebaseApp = {
Try(FirebaseApp.getInstance()).toEither match {
// App hasn't been initialized yet, so we initialize it
case Left(_: IllegalStateException) =>
FirebaseApp.initializeApp(
new FirebaseOptions.Builder()
.setCredentials(credentials)
.build
)
// Reuse the already-initialized app
case Right(app) => app
// Some other exception occurred
case Left(e) => throw e
}
}
}Last updated