-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirebase.go
44 lines (33 loc) · 848 Bytes
/
firebase.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package firebase
import (
"context"
"fmt"
"time"
firebase "firebase.google.com/go/v4"
"firebase.google.com/go/v4/auth"
"google.golang.org/api/option"
"github.com/kokoichi206/awesome-chat-app/backend/repository"
)
type admin struct {
app *firebase.App
authClient *auth.Client
sessionLifetime time.Duration
}
func New(ctx context.Context, credentialPath string) (repository.Firebase, error) {
opt := option.WithCredentialsFile(credentialPath)
app, err := firebase.NewApp(ctx, nil, opt)
if err != nil {
return nil, fmt.Errorf("failed to initialize app: %w", err)
}
ac, err := app.Auth(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get auth client : %w", err)
}
admin := &admin{
app: app,
authClient: ac,
// 5 days
sessionLifetime: 60 * 60 * 24 * 5 * time.Second,
}
return admin, nil
}