forked from tangled.org/core
Monorepo for Tangled — https://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
···
"github.com/go-chi/chi/v5"
"github.com/lestrrat-go/jwx/v2/jwk"
)
func (o *OAuth) Router() http.Handler {
···
if err := o.SaveSession(w, r, sessData); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.Redirect(w, r, "/", http.StatusFound)
···
"github.com/go-chi/chi/v5"
"github.com/lestrrat-go/jwx/v2/jwk"
+
"github.com/posthog/posthog-go"
)
func (o *OAuth) Router() http.Handler {
···
if err := o.SaveSession(w, r, sessData); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
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)
+4 -1
appview/oauth/oauth.go
···
xrpc "github.com/bluesky-social/indigo/xrpc"
"github.com/gorilla/sessions"
"github.com/lestrrat-go/jwx/v2/jwk"
"tangled.org/core/appview/config"
)
-
func New(config *config.Config) (*OAuth, error) {
var oauthConfig oauth.ClientConfig
var clientUri string
···
Config: config,
SessStore: sessStore,
JwksUri: jwksUri,
}, nil
}
···
SessStore *sessions.CookieStore
Config *config.Config
JwksUri string
}
func (o *OAuth) SaveSession(w http.ResponseWriter, r *http.Request, sessData *oauth.ClientSessionData) error {
···
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, ph posthog.Client) (*OAuth, error) {
var oauthConfig oauth.ClientConfig
var clientUri string
···
Config: config,
SessStore: sessStore,
JwksUri: jwksUri,
+
Posthog: ph,
}, nil
}
···
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 {
+6 -6
appview/state/state.go
···
res = idresolver.DefaultResolver()
}
pages := pages.NewPages(config, res)
cache := cache.New(config.Redis.Addr)
sess := session.New(cache)
-
oauth2, err := oauth.New(config)
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)
···
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, posthog)
if err != nil {
return nil, fmt.Errorf("failed to start oauth handler: %w", err)
}
validator := validator.New(d, res, enforcer)
repoResolver := reporesolver.New(config, enforcer, res, d)