新手问题 mongoid、graphql 环境下,求推荐一种安全认证方式

lukefan · December 29, 2020 · Last by xinyuewaisong replied at January 02, 2021 · 299 hits

业余程序员,想要做一个基于 mongoid 和 graphql 的服务端。 然后用 react 和 flutter 做 web 和移动的前端。 想要找一种认证方法,可以让用户登录,并只为认证用户提供服务。 有什么比较简单的方案吗?

尝试了 graphql_devise,改到 mongoid 下,就各种错误。 graphql_auth,还没看明白。

可以自己实现认证就行

检查认证的话,比如 Mutation,在 ready 处理下

class Mutations::BaseMutation < GraphQL::Schema::RelayClassicMutation
  def ready?(**args)
    if !context[:current_admin]
      raise GraphQL::ExecutionError.new "需要管理员认证"
    else
      true
    end
  end
end
Reply to lidashuang

没太明白,我希望可以实现登录、注册,以及每一次 query 或 mutation 请求之前,都进行认证。

Reply to lukefan

你之前 restful api 怎么实现登入注册,现在基本也怎么实现,只是换成 mutation 和 query 了

以及每一次 query 或 mutation 请求之前,都进行认证

就是 用 ready? 之类的,比如 BaseMutation 定义一个 ready?

Reply to lidashuang

看来需要慢慢研究了。

You need to Sign in before reply, if you don't have an account, please Sign up first.