Hello, I am following a documentation to learn the authentication with rails and graphql ( https://www.howtographql.com/graphql-ruby/4-authentication/ ) everything was fine until a mutation had to be made for the usersignin, it is supposed to Once the user verifies the object, it should return a token, but it gives me an error.
{
"error": { "message": "undefined method `credentials' for #<GraphqlTutorial::Application:0x000055a348f9c3d8>",
}
The configuration I followed is this:
module Mutations
class SignInUser < BaseMutation
null true
argument :email, Types::AuthProviderEmailInput, required: false
field :token, String, null: true
field :user, Types::UserType, null: true
def resolve(email: nil)
return unless email
user = User.find_by email: email[:email]
return unless user
return unless user.authenticate(email[:password])
crypt = ActiveSupport::MessageEncryptor.new(Rails.application.credentials.secret_key_base.byteslice(0..31))
token = crypt.encrypt_and_sign("user-id:#{ user.id }")
{ user: user, token: token }
end
end
end
I am sensing that it may be on the line for the crypt variable that the token is created.
I am assuming you are using an old version of rails, as it
Rails.application.credentials
is available since rails 5.2 .You are probably using
config/secrets.yml
, for which you should access usingRails.application.secrets.nombre_de_tu_key
, if not, any fixed string should work, since it generallyActiveSupport::MessageEncryptor.new
requires a string that is always the same, and then uses it to generate the user token.