+11
appview/oauth/handler.go
+11
appview/oauth/handler.go
···
7
7
8
8
"github.com/go-chi/chi/v5"
9
9
"github.com/lestrrat-go/jwx/v2/jwk"
10
+
"github.com/posthog/posthog-go"
10
11
)
11
12
12
13
func (o *OAuth) Router() http.Handler {
···
59
60
if err := o.SaveSession(w, r, sessData); err != nil {
60
61
http.Error(w, err.Error(), http.StatusInternalServerError)
61
62
return
63
+
}
64
+
65
+
if !o.Config.Core.Dev {
66
+
err = o.Posthog.Enqueue(posthog.Capture{
67
+
DistinctId: sessData.AccountDID.String(),
68
+
Event: "signin",
69
+
})
70
+
if err != nil {
71
+
log.Println("failed to enqueue posthog event:", err)
72
+
}
62
73
}
63
74
64
75
http.Redirect(w, r, "/", http.StatusFound)
+4
-1
appview/oauth/oauth.go
+4
-1
appview/oauth/oauth.go
···
13
13
xrpc "github.com/bluesky-social/indigo/xrpc"
14
14
"github.com/gorilla/sessions"
15
15
"github.com/lestrrat-go/jwx/v2/jwk"
16
+
"github.com/posthog/posthog-go"
16
17
"tangled.org/core/appview/config"
17
18
)
18
19
19
-
func New(config *config.Config) (*OAuth, error) {
20
+
func New(config *config.Config, ph posthog.Client) (*OAuth, error) {
20
21
21
22
var oauthConfig oauth.ClientConfig
22
23
var clientUri string
···
46
47
Config: config,
47
48
SessStore: sessStore,
48
49
JwksUri: jwksUri,
50
+
Posthog: ph,
49
51
}, nil
50
52
}
51
53
···
54
56
SessStore *sessions.CookieStore
55
57
Config *config.Config
56
58
JwksUri string
59
+
Posthog posthog.Client
57
60
}
58
61
59
62
func (o *OAuth) SaveSession(w http.ResponseWriter, r *http.Request, sessData *oauth.ClientSessionData) error {
+6
-6
appview/state/state.go
+6
-6
appview/state/state.go
···
77
77
res = idresolver.DefaultResolver()
78
78
}
79
79
80
+
posthog, err := posthog.NewWithConfig(config.Posthog.ApiKey, posthog.Config{Endpoint: config.Posthog.Endpoint})
81
+
if err != nil {
82
+
return nil, fmt.Errorf("failed to create posthog client: %w", err)
83
+
}
84
+
80
85
pages := pages.NewPages(config, res)
81
86
cache := cache.New(config.Redis.Addr)
82
87
sess := session.New(cache)
83
-
oauth2, err := oauth.New(config)
88
+
oauth2, err := oauth.New(config, posthog)
84
89
if err != nil {
85
90
return nil, fmt.Errorf("failed to start oauth handler: %w", err)
86
91
}
87
92
validator := validator.New(d, res, enforcer)
88
-
89
-
posthog, err := posthog.NewWithConfig(config.Posthog.ApiKey, posthog.Config{Endpoint: config.Posthog.Endpoint})
90
-
if err != nil {
91
-
return nil, fmt.Errorf("failed to create posthog client: %w", err)
92
-
}
93
93
94
94
repoResolver := reporesolver.New(config, enforcer, res, d)
95
95