Files
KS Jannette 2c86bba235
Some checks are pending
check / check (push) Waiting to run
general cleanup - removed old comments, enforced naming conventions etc
2026-03-04 23:29:58 -05:00

52 lines
938 B
Go

package firebase
import (
"context"
"fmt"
"sync"
fb "firebase.google.com/go/v4"
"firebase.google.com/go/v4/auth"
"google.golang.org/api/option"
)
var ( //nolint:gochecknoglobals
authClient *auth.Client //nolint:gochecknoglobals
once sync.Once //nolint:gochecknoglobals
errInit error //nolint:gochecknoglobals
)
func Init(projectID string) error {
once.Do(func() {
ctx := context.Background()
var app *fb.App
var err error
if projectID != "" {
cfg := &fb.Config{ProjectID: projectID}
app, err = fb.NewApp(ctx, cfg, option.WithoutAuthentication())
} else {
app, err = fb.NewApp(ctx, nil)
}
if err != nil {
errInit = fmt.Errorf("initialize firebase app: %w", err)
return
}
authClient, err = app.Auth(ctx)
if err != nil {
errInit = fmt.Errorf("initialize firebase auth: %w", err)
return
}
})
return errInit
}
func Auth() *auth.Client {
return authClient
}