Skip to content

Commit

Permalink
feat: use add dummy instance id so we can use the compound index
Browse files Browse the repository at this point in the history
  • Loading branch information
joel authored and joel committed Feb 26, 2024
1 parent f29e89d commit 7c750fd
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/models/refresh_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func RevokeTokenFamily(tx *storage.Connection, token *RefreshToken) error {

func FindTokenBySessionID(tx *storage.Connection, sessionId *uuid.UUID) (*RefreshToken, error) {
refreshToken := &RefreshToken{}
err := tx.Q().Where("session_id = ?", sessionId).Order("created_at asc").First(refreshToken)
err := tx.Q().Where("instance_id = ? and session_id = ?", uuid.Nil, sessionId).Order("created_at asc").First(refreshToken)
if err != nil {
if errors.Cause(err) == sql.ErrNoRows {
return nil, RefreshTokenNotFoundError{}
Expand Down Expand Up @@ -168,5 +168,5 @@ func createRefreshToken(tx *storage.Connection, user *User, oldToken *RefreshTok
// Deprecated. For backward compatibility, some access tokens may not have a sessionId. Use models.Logout instead.
// LogoutAllRefreshTokens deletes all sessions for a user.
func LogoutAllRefreshTokens(tx *storage.Connection, userId uuid.UUID) error {
return tx.RawQuery("DELETE FROM "+(&pop.Model{Value: RefreshToken{}}).TableName()+" WHERE user_id = ?", userId).Exec()
return tx.RawQuery("DELETE FROM "+(&pop.Model{Value: RefreshToken{}}).TableName()+" WHERE instance_id = ? and user_id = ?", uuid.Nil, userId).Exec()
}

0 comments on commit 7c750fd

Please sign in to comment.