通过user_id的Lighthouse GraphQL数据所有权

问题描述

我有一个允许多个用户的应用程序。每个用户都是彼此完全隔离的;这意味着不是数据库用户的所有内容都有一个export const customArray = createSelector( arrayCustomizations,(entities: Dictionary<Customizations>,props: { id: string }) => { const customizations = entities[props.id]; return customizations.allCustoms; },).pipe( filter(object => object.name !== null) ); 列,并且只允许登录用户查看,更新或删除它们。此外,用户无法使用其他人的user_id创建行。

是否有内置方法可通过流明/灯塔解决此问题?这是我已经完成的工作,并且可以运行,但是我想知道是否重新发明了轮子:

  1. 每个模型都具有user_id关系,如下所示:
user
  1. 我为这些模型添加了public function user(): BelongsTo { return $this->belongsTo(User::class); } ,内容如下:
HasOwnerTrait
  1. 最后,在我的架构定义中:
public static function boot()
{
    parent::boot();

    static::creating(function (Model $model) {
        $model->user_id = Auth::user()->id;
    });

    static::saving(function (Model $model) {
        if ($model->user_id !== Auth::user()->id) {
            $exception = new ModelNotFoundException();
            $exception->setModel(self::class,$model->id);
            throw $exception;
        }
    });

    static::deleting(function (Model $model) {
        if ($model->user_id !== Auth::user()->id) {
            $exception = new ModelNotFoundException();
            $exception->setModel(self::class,$model->id);
            throw $exception;
        }
    });
}

public function scopeIsOwner($query)
{
    return $query->where('user_id',Auth::user()->id);
}

再次,这是可行的,但是是否需要像这样临时进行,还是有更好的方法?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)