Skip to content

Commit

Permalink
fix: detect unique violation on MySQL
Browse files Browse the repository at this point in the history
  • Loading branch information
hperl committed Nov 14, 2023
1 parent dd52765 commit e2922c4
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions persistence/sql/persister_consent.go
Original file line number Diff line number Diff line change
Expand Up @@ -787,17 +787,23 @@ func (p *Persister) FlushInactiveLoginConsentRequests(ctx context.Context, notAf
}

func (p *Persister) mySQLConfirmLoginSession(ctx context.Context, session *flow.LoginSession) error {
err := p.Connection(ctx).Create(session)
err := sqlcon.HandleError(p.Connection(ctx).Create(session))
if err == nil {
return nil
}

if !errors.Is(err, sqlcon.ErrUniqueViolation) {
return err
}

n, err := p.Connection(ctx).
Where("id = ? and nid = ?", session.ID, session.NID).
UpdateQuery(session, "authenticated_at", "subject", "identity_provider_session_id", "remember")
if err != nil {
n, err := p.Connection(ctx).
Where("id = ? and nid = ?", session.ID, session.NID).
UpdateQuery(session, "authenticated_at", "subject", "identity_provider_session_id", "remember")
if err != nil {
return errors.WithStack(sqlcon.HandleError(err))
}
if n == 0 {
return errorsx.WithStack(x.ErrNotFound)
}
return errors.WithStack(sqlcon.HandleError(err))
}
if n == 0 {
return errorsx.WithStack(x.ErrNotFound)
}

return nil
Expand Down

0 comments on commit e2922c4

Please sign in to comment.