graphql-devise / graphql_devise

GraphQL interface on top devise_token_auth
MIT License
200 stars 39 forks source link

Undefined method `user_confirmation_url' #172

Closed tiopi closed 3 years ago

tiopi commented 3 years ago

Describe the bug

I am unable to resolve the user_confirmation_url. I get

ActionView::Template::Error (undefined method `user_confirmation_url' for #<ActionDispatch::Routing::RoutesProxy:0x00007f9f7f2a8cf0 @scope=#<TestMailer:0x00000000008fe8>, @routes=#<ActionDispatch::Routing::RouteSet:0x00007f9f76d11b00>, @helpers=#<Module:0x00007f9f737efe40>, @script_namer=nil>)

when I try to access a user.send_confirmation_instructions. Am I missing something, and if so how can I go about debugging this issue?

Environment

(paste the link(s) to the Gemfile and Gemfile.lock files.)

source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby "3.0.0"

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem "rails", "~> 6.1.3", ">= 6.1.3.1"
# Use postgresql as the database for Active Record
gem "pg", "~> 1.1"
# Use Puma as the app server
gem "webrick"
gem "puma"
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Active Storage variant
# gem 'image_processing', '~> 1.2'

# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", ">= 1.4.4", require: false
gem "graphql", "~> 1.12", ">= 1.12.6"

# Use interactors
gem "interactor-rails", "~> 2.0"

# Location services
gem "geocoder"

# User authentication
gem "graphql_devise"

# Mailers
gem 'actionview-encoded_mail_to'
gem 'sidekiq'
gem 'redis-rails'

# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
# gem 'rack-cors'

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem "byebug", platforms: [:mri, :mingw, :x64_mingw]
  gem "standard"
  gem "rspec-rails", "~> 5.0.0"
  gem "factory_bot_rails"
  gem "faker"
end

group :development do
  gem "listen", "~> 3.3"
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem "spring"
  gem "graphiql-rails"
end

group :test do
  gem "shoulda-matchers", "~> 4.0"
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby]

Steps to reproduce

(Write your steps here:)

  1. Setup graphql-devise
  2. Use the graphql loader:
    use GraphqlDevise::SchemaPlugin.new(
    query: Types::QueryType,
    mutation: Types::MutationType,
    resource_loaders: [
      GraphqlDevise::ResourceLoader.new(
        "User",
        operations: {
          sign_up: Users::CreateMutation
        }
      )
    ]
    )
  3. Call user.send_confirmation_instructions in console for a user that requires a confirmation.

Expected behavior

The email would get sent out with a confirmation code.

Actual behavior

Got an error about user_confirmation_url not found.

Reproducible demo

TBD.

00dav00 commented 3 years ago

Hi @tiopi , this looks like this devise issue. That method is not added by this gem but Devise.

tiopi commented 3 years ago

I noticed the issue does disappear when I added devise_for :users in my routes. I thought that adding items like
:confirm_account and such setup the routes required.

mcelicalderon commented 3 years ago

Hey @tiopi! Actually you should never need the missing method user_confirmation_url if you are only using this gem. If you are calling the send confirmation instructions manually, take a look at our mutation as you need to pass additional params in order for the method to use our email templates https://github.com/graphql-devise/graphql_devise/blob/590222d2622e9c209ba794450862191d1d89f456/lib/graphql_devise/mutations/sign_up.rb#L33

If you are using the newer password recovery flow no need to pass schema_url to the send_confirmation_instructions method. Let me know if that was it.

tiopi commented 3 years ago

Hey @tiopi! Actually you should never need the missing method user_confirmation_url if you are only using this gem. If you are calling the send confirmation instructions manually, take a look at our mutation as you need to pass additional params in order for the method to use our email templates

https://github.com/graphql-devise/graphql_devise/blob/590222d2622e9c209ba794450862191d1d89f456/lib/graphql_devise/mutations/sign_up.rb#L33

If you are using the newer password recovery flow no need to pass schema_url to the send_confirmation_instructions method. Let me know if that was it.

Oh this looks about right. I was using send_confirmation without any arguments. Will the redirect url setup the graphql query?

mcelicalderon commented 3 years ago

It depends on the password recovery flow you use. For the preferred one the redirect_url is a client url that will be contained in the email together with the reset password token. Take a look at this as reference. Also take a look at both our reset password mutations to see how the send_confirmation_instructions is used.

mcelicalderon commented 3 years ago

Closing this one as it looks like the problem was resolved. Feel free to reopen if you found something else ;)