navidjalali / auth

ZIO REST client for Firebase authentication.

Version Matrix

Firebase Auth

REST client for Firebase authentication.

Exposes a ZIO interface. HTTP client is based on Akka Http.

import io.github.navidjalali.auth.client.HttpClient
import io.github.navidjalali.auth.firebase.FirebaseAuth
import zio.console.{Console, putStrLn}
import zio.{ExitCode, Managed, Task, URIO, ZIO, ZLayer}

object Main extends zio.App {

  val secret = "such secret read from config"

  val email = ""
  val password = "such secure password"

  val live: ZLayer[Any, Throwable, Console with FirebaseAuth] = and
      ZLayer.fromManaged(Managed.make(Task(ActorSystem("system")))(sys =>
        Task.fromFuture(_ => sys.terminate()).either)) >>> >>>

  val app: ZIO[Console with FirebaseAuth, FirebaseAuth.AuthError, Unit] = for {
    auth <- ZIO.access[FirebaseAuth](_.get)
    signIn <- auth.signIn(email, password)
    userData <- auth.getUserData(signIn.idToken)
    _ <- putStrLn(userData.users.toString())
  } yield ()

  override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] =
      .catchAllCause(cause => putStrLn(cause.prettyPrint))