sourcegraph/cmd/frontend/internal/auth/gitlaboauth/user.go
Erik Seliger 7a116a2a15
Merge enterprise and oss frontend (#56476)
This is a big one! Merged the enterprise frontend with the OSS one, to get yet another step closer to getting rid of the enterprise directory :)
2023-09-11 14:16:38 +02:00

28 lines
704 B
Go

package gitlaboauth
import (
"context"
"github.com/sourcegraph/sourcegraph/internal/extsvc/gitlab"
"github.com/sourcegraph/sourcegraph/lib/errors"
)
// unexported key type prevents collisions
type key int
const userKey key = iota
// WithUser returns a copy of ctx that stores the GitLab User.
func WithUser(ctx context.Context, user *gitlab.AuthUser) context.Context {
return context.WithValue(ctx, userKey, user)
}
// UserFromContext returns the GitLab User from the ctx.
func UserFromContext(ctx context.Context) (*gitlab.AuthUser, error) {
user, ok := ctx.Value(userKey).(*gitlab.AuthUser)
if !ok {
return nil, errors.Errorf("gitlab: Context missing GitLab User")
}
return user, nil
}