21 lines
410 B
Go
21 lines
410 B
Go
package directives
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"git.farahty.com/nimer/go-mongo/app"
|
|
"git.farahty.com/nimer/go-mongo/models"
|
|
"github.com/99designs/gqlgen/graphql"
|
|
)
|
|
|
|
func HasRole(ctx context.Context, obj any, next graphql.Resolver, role models.Role) (res any, err error) {
|
|
|
|
if _, err := app.CurrentUser(ctx); err != nil {
|
|
return nil, fmt.Errorf("access denied, %s", err.Error())
|
|
}
|
|
|
|
return next(ctx)
|
|
|
|
}
|