Skip to content

Commit

Permalink
fix: add login succeeded event to post registration hook (#3739)
Browse files Browse the repository at this point in the history
  • Loading branch information
sashatalalasha authored Feb 22, 2024
1 parent 037bdf8 commit b685fa5
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions selfservice/hook/session_issuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import (
"context"
"net/http"

"go.opentelemetry.io/otel/trace"

"github.com/ory/kratos/identity"
"github.com/ory/kratos/ui/node"
"github.com/ory/kratos/x/events"

"github.com/pkg/errors"

Expand All @@ -21,9 +24,7 @@ import (
"github.com/ory/x/otelx"
)

var (
_ registration.PostHookPostPersistExecutor = new(SessionIssuer)
)
var _ registration.PostHookPostPersistExecutor = new(SessionIssuer)

type (
sessionIssuerDependencies interface {
Expand Down Expand Up @@ -70,6 +71,14 @@ func (e *SessionIssuer) executePostRegistrationPostPersistHook(w http.ResponseWr
Identity: s.Identity,
ContinueWith: a.ContinueWithItems,
})

trace.SpanFromContext(r.Context()).AddEvent(events.NewLoginSucceeded(r.Context(), &events.LoginSucceededOpts{
SessionID: s.ID,
IdentityID: s.Identity.ID,
FlowType: string(a.Type),
Method: a.Active.String(),
}))

return errors.WithStack(registration.ErrHookAbortFlow)
}

Expand All @@ -78,6 +87,13 @@ func (e *SessionIssuer) executePostRegistrationPostPersistHook(w http.ResponseWr
return err
}

trace.SpanFromContext(r.Context()).AddEvent(events.NewLoginSucceeded(r.Context(), &events.LoginSucceededOpts{
SessionID: s.ID,
IdentityID: s.Identity.ID,
FlowType: string(a.Type),
Method: a.Active.String(),
}))

// SPA flows additionally send the session
if x.IsJSONRequest(r) {
e.r.Writer().Write(w, r, &registration.APIFlowResponse{
Expand Down

0 comments on commit b685fa5

Please sign in to comment.