From 88a45c13b8c4e4ae11608363ae74886874f18be2 Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Sat, 11 Oct 2025 09:58:50 +0100 Subject: [PATCH] appview/oauth: restore posthog Signed-off-by: oppiliappan --- appview/oauth/handler.go | 11 +++++++++++ appview/oauth/oauth.go | 5 ++++- appview/state/state.go | 12 ++++++------ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/appview/oauth/handler.go b/appview/oauth/handler.go index 2172ab13..7fc0209d 100644 --- a/appview/oauth/handler.go +++ b/appview/oauth/handler.go @@ -7,6 +7,7 @@ import ( "github.com/go-chi/chi/v5" "github.com/lestrrat-go/jwx/v2/jwk" + "github.com/posthog/posthog-go" ) func (o *OAuth) Router() http.Handler { @@ -61,5 +62,15 @@ func (o *OAuth) callback(w http.ResponseWriter, r *http.Request) { return } + if !o.Config.Core.Dev { + err = o.Posthog.Enqueue(posthog.Capture{ + DistinctId: sessData.AccountDID.String(), + Event: "signin", + }) + if err != nil { + log.Println("failed to enqueue posthog event:", err) + } + } + http.Redirect(w, r, "/", http.StatusFound) } diff --git a/appview/oauth/oauth.go b/appview/oauth/oauth.go index 19f293a2..63aea77c 100644 --- a/appview/oauth/oauth.go +++ b/appview/oauth/oauth.go @@ -13,10 +13,11 @@ import ( xrpc "github.com/bluesky-social/indigo/xrpc" "github.com/gorilla/sessions" "github.com/lestrrat-go/jwx/v2/jwk" + "github.com/posthog/posthog-go" "tangled.org/core/appview/config" ) -func New(config *config.Config) (*OAuth, error) { +func New(config *config.Config, ph posthog.Client) (*OAuth, error) { var oauthConfig oauth.ClientConfig var clientUri string @@ -46,6 +47,7 @@ func New(config *config.Config) (*OAuth, error) { Config: config, SessStore: sessStore, JwksUri: jwksUri, + Posthog: ph, }, nil } @@ -54,6 +56,7 @@ type OAuth struct { SessStore *sessions.CookieStore Config *config.Config JwksUri string + Posthog posthog.Client } func (o *OAuth) SaveSession(w http.ResponseWriter, r *http.Request, sessData *oauth.ClientSessionData) error { diff --git a/appview/state/state.go b/appview/state/state.go index ae911092..63ec043d 100644 --- a/appview/state/state.go +++ b/appview/state/state.go @@ -77,20 +77,20 @@ func Make(ctx context.Context, config *config.Config) (*State, error) { res = idresolver.DefaultResolver() } + posthog, err := posthog.NewWithConfig(config.Posthog.ApiKey, posthog.Config{Endpoint: config.Posthog.Endpoint}) + if err != nil { + return nil, fmt.Errorf("failed to create posthog client: %w", err) + } + pages := pages.NewPages(config, res) cache := cache.New(config.Redis.Addr) sess := session.New(cache) - oauth2, err := oauth.New(config) + oauth2, err := oauth.New(config, posthog) if err != nil { return nil, fmt.Errorf("failed to start oauth handler: %w", err) } validator := validator.New(d, res, enforcer) - posthog, err := posthog.NewWithConfig(config.Posthog.ApiKey, posthog.Config{Endpoint: config.Posthog.Endpoint}) - if err != nil { - return nil, fmt.Errorf("failed to create posthog client: %w", err) - } - repoResolver := reporesolver.New(config, enforcer, res, d) wrapper := db.DbWrapper{Execer: d} -- 2.51.2