fix: couple session deletion with user deletion

This commit is contained in:
Lakhan Samani
2022-07-12 08:42:32 +05:30
parent 1fe0d65874
commit bfbeb6add2
11 changed files with 32 additions and 55 deletions

View File

@@ -6,7 +6,6 @@ import (
"github.com/authorizerdev/authorizer/server/db/models"
"github.com/google/uuid"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo/options"
)
@@ -26,13 +25,3 @@ func (p *provider) AddSession(ctx context.Context, session models.Session) error
}
return nil
}
// DeleteSession to delete session information from database
func (p *provider) DeleteSession(ctx context.Context, userId string) error {
sessionCollection := p.db.Collection(models.Collections.Session, options.Collection())
_, err := sessionCollection.DeleteMany(ctx, bson.M{"user_id": userId}, options.Delete())
if err != nil {
return err
}
return nil
}

View File

@@ -57,6 +57,12 @@ func (p *provider) DeleteUser(ctx context.Context, user models.User) error {
return err
}
sessionCollection := p.db.Collection(models.Collections.Session, options.Collection())
_, err = sessionCollection.DeleteMany(ctx, bson.M{"user_id": user.ID}, options.Delete())
if err != nil {
return err
}
return nil
}