setup firebase custom token
This commit is contained in:
+23
-10
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"cloud.google.com/go/firestore"
|
||||
"cloud.google.com/go/storage"
|
||||
firebase "firebase.google.com/go/v4"
|
||||
pbaero "github.com/flowy-live/llink/genproto/aero"
|
||||
"github.com/flowy-live/llink/internal"
|
||||
"github.com/flowy-live/llink/internal/auth"
|
||||
@@ -62,7 +63,19 @@ func main() {
|
||||
defer aeroServer.Close()
|
||||
aeroSvc := pbaero.NewPrimaryClient(aeroServer)
|
||||
|
||||
authSvc := auth.NewAuthService(redisClient, aeroSvc)
|
||||
gcpProject := utils.MustGetEnv("GCP_PROJECT")
|
||||
fbApp, err := firebase.NewApp(ctx, &firebase.Config{ProjectID: gcpProject})
|
||||
if err != nil {
|
||||
slog.Error("failed to init Firebase Admin app", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fbAuth, err := fbApp.Auth(ctx)
|
||||
if err != nil {
|
||||
slog.Error("failed to create Firebase auth client", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
authSvc := auth.NewAuthService(redisClient, aeroSvc, fbAuth)
|
||||
humanSvc := human.NewService(db.Pool())
|
||||
|
||||
billingSvc, err := billing.NewService(ctx, db.Pool(), billing.Config{
|
||||
@@ -78,7 +91,14 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
networkSvc := network.NewService(db.Pool(), aeroSvc, billingSvc)
|
||||
firestoreClient, err := firestore.NewClient(ctx, gcpProject)
|
||||
if err != nil {
|
||||
slog.Error("failed to create Firestore client", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer firestoreClient.Close()
|
||||
|
||||
networkSvc := network.NewService(db.Pool(), aeroSvc, billingSvc, firestoreClient)
|
||||
particleSvc := particle.NewService(db.Pool(), networkSvc)
|
||||
depotSvc := depot.NewService(db.Pool(), storageClient, depot.Config{
|
||||
GoogleServiceAccountEmail: utils.MustGetEnv("GOOGLE_SERVICE_ACCOUNT_EMAIL"),
|
||||
@@ -87,14 +107,6 @@ func main() {
|
||||
waitlistSvc := waitlist.NewService(db.Pool(), aeroSvc)
|
||||
livekitClient := livekit.NewClient()
|
||||
|
||||
gcpProject := utils.MustGetEnv("GCP_PROJECT")
|
||||
firestoreClient, err := firestore.NewClient(ctx, gcpProject)
|
||||
if err != nil {
|
||||
slog.Error("failed to create Firestore client", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer firestoreClient.Close()
|
||||
|
||||
h := handler.NewHandler(authSvc, humanSvc, networkSvc, particleSvc, depotSvc, waitlistSvc, billingSvc, livekitClient, firestoreClient)
|
||||
|
||||
withAuth := func(hf http.HandlerFunc) http.Handler {
|
||||
@@ -125,6 +137,7 @@ func main() {
|
||||
// Auth
|
||||
mux.Handle("POST /auth/sign-out", withAuth(h.SignOut))
|
||||
mux.Handle("GET /auth/me", withAuth(h.GetCurrentHuman))
|
||||
mux.Handle("POST /auth/firebase-token", withAuth(h.FirebaseToken))
|
||||
|
||||
// Settings
|
||||
mux.Handle("PATCH /humans/me/settings", withAuth(h.UpdateSettings))
|
||||
|
||||
Reference in New Issue
Block a user