Skip to content

Commit

Permalink
fix: properly fetch identity for session
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Aug 25, 2020
1 parent 08c8c78 commit 7be4086
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions persistence/sql/persister_session.go
Expand Up @@ -14,9 +14,17 @@ var _ session.Persister = new(Persister)

func (p *Persister) GetSession(ctx context.Context, sid uuid.UUID) (*session.Session, error) {
var s session.Session
if err := p.GetConnection(ctx).Eager("Identity").Find(&s, sid); err != nil {
if err := p.GetConnection(ctx).Find(&s, sid); err != nil {
return nil, sqlcon.HandleError(err)
}

// This is needed because of how identities are fetched from the store (if we use eager not all fields are
// available!).
i, err := p.GetIdentity(ctx, s.IdentityID)
if err != nil {
return nil, err
}
s.Identity = i
return &s, nil
}

Expand All @@ -37,9 +45,17 @@ func (p *Persister) DeleteSessionsFor(ctx context.Context, identityID uuid.UUID)

func (p *Persister) GetSessionFromToken(ctx context.Context, token string) (*session.Session, error) {
var s session.Session
if err := p.GetConnection(ctx).Eager("Identity").Where("token = ?", token).First(&s); err != nil {
if err := p.GetConnection(ctx).Where("token = ?", token).First(&s); err != nil {
return nil, sqlcon.HandleError(err)
}

// This is needed because of how identities are fetched from the store (if we use eager not all fields are
// available!).
i, err := p.GetIdentity(ctx, s.IdentityID)
if err != nil {
return nil, err
}
s.Identity = i
return &s, nil
}

Expand Down

0 comments on commit 7be4086

Please sign in to comment.