Monorepo for Tangled tangled.org

appview/oauth: restore posthog

Signed-off-by: oppiliappan <me@oppi.li>

oppi.li 88a45c13 1fd8374f

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