fix: use correct context keys when retrieving userID & role
This commit is contained in:
@ -17,6 +17,7 @@ import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/jordanknott/taskcafe/internal/auth"
|
||||
"github.com/jordanknott/taskcafe/internal/db"
|
||||
"github.com/jordanknott/taskcafe/internal/utils"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -108,13 +109,13 @@ func NewPlaygroundHandler(endpoint string) http.Handler {
|
||||
|
||||
// GetUserID retrieves the UserID out of a context
|
||||
func GetUserID(ctx context.Context) (uuid.UUID, bool) {
|
||||
userID, ok := ctx.Value("userID").(uuid.UUID)
|
||||
userID, ok := ctx.Value(utils.UserIDKey).(uuid.UUID)
|
||||
return userID, ok
|
||||
}
|
||||
|
||||
// GetUserRole retrieves the user role out of a context
|
||||
func GetUserRole(ctx context.Context) (auth.Role, bool) {
|
||||
role, ok := ctx.Value("org_role").(auth.Role)
|
||||
role, ok := ctx.Value(utils.OrgRoleKey).(auth.Role)
|
||||
return role, ok
|
||||
}
|
||||
|
||||
@ -127,7 +128,7 @@ func GetUser(ctx context.Context) (uuid.UUID, auth.Role, bool) {
|
||||
|
||||
// GetRestrictedMode retrieves the restricted mode code out of a context
|
||||
func GetRestrictedMode(ctx context.Context) (auth.RestrictedMode, bool) {
|
||||
restricted, ok := ctx.Value("restricted_mode").(auth.RestrictedMode)
|
||||
restricted, ok := ctx.Value(utils.RestrictedModeKey).(auth.RestrictedMode)
|
||||
return restricted, ok
|
||||
}
|
||||
|
||||
|
@ -892,7 +892,7 @@ func (r *queryResolver) Projects(ctx context.Context, input *ProjectsFilter) ([]
|
||||
|
||||
visibleProjects, err := r.Repository.GetAllVisibleProjectsForUserID(ctx, userID)
|
||||
if err != nil {
|
||||
log.Info("user id was not found from middleware")
|
||||
log.WithField("userID", userID).Info("error getting visible projects for user")
|
||||
return []db.Project{}, nil
|
||||
}
|
||||
for _, project := range visibleProjects {
|
||||
@ -942,7 +942,7 @@ func (r *queryResolver) Teams(ctx context.Context) ([]db.Team, error) {
|
||||
|
||||
visibleProjects, err := r.Repository.GetAllVisibleProjectsForUserID(ctx, userID)
|
||||
if err != nil {
|
||||
log.Info("user id was not found from middleware")
|
||||
log.WithField("userID", userID).Info("error while getting visible projects")
|
||||
return []db.Team{}, err
|
||||
}
|
||||
for _, project := range visibleProjects {
|
||||
@ -951,7 +951,7 @@ func (r *queryResolver) Teams(ctx context.Context) ([]db.Team, error) {
|
||||
log.WithFields(log.Fields{"projectID": project.ProjectID.String()}).Info("adding visible project")
|
||||
team, err := r.Repository.GetTeamByID(ctx, project.TeamID)
|
||||
if err != nil {
|
||||
log.Info("user id was not found from middleware")
|
||||
log.WithField("teamID", project.TeamID).Info("error getting team by id")
|
||||
return []db.Team{}, err
|
||||
}
|
||||
teams[project.TeamID.String()] = team
|
||||
|
Reference in New Issue
Block a user