No route matches [GET] "/auth/auth0"

I have seen this issue get brought up in other posts, but I cannot find a way to remedy it with my app. I keep getting this error when I click on “login” rather than being directed to a login page. I don’t know where the issue can be, as I followed the documentation very carefully. Below are my routes:

Rails.application.routes.draw do
  get "dashboard/show"
  root "home#show"
  get "home/show"
  resources :saved_games
  resources :saved_videos
  resources :saved_quotes
  resources :games
  resources :videos
  resources :users
  resources :quotes
  get "auth/auth0/callback" => "auth0#callback"
  get "auth/failure" => "auth0#failure"
  # post "auth/auth0" => "dashboard#create"
  get "dashboard" => "dashboard#show"

  get "/quotes" => "quotes#index"
  get "/quotes/:id" => "quotes#show"

  get "/games" => "games#index"
  get "/quotes/:id" => "games#show"

  get "/videos" => "videos#index"
  get "/videos/:id" => "videos#show
end

my auth0.rb:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider(
    :auth0,
    "AUTH0_CLIENT_KEY",
    "AUTH0_CLIENT_SECRET",
    "almanac.auth0.com",
    callback_path: "/auth/auth0/callback",
    authorize_params: {
      scope: "openid email profile",
    },
  )
end

my gemfile:

gem 'omniauth-auth0', '~> 2.2'
gem 'omniauth-rails_csrf_protection', '~> 0.1'

Please help!

IIRC, for Rails there’s a recommendation that the login action should be an HTTP POST (Auth0 Ruby On Rails SDK Quickstarts: Login) instead of a GET so it’s somewhat unexpected for the error to mention the GET verb. How are you implementing the login action?

1 Like

Below is how I implemented on the show.html.erb page as directed in the tutorial!

<img src="https://cdn.auth0.com/styleguide/1.0.0/img/badge.svg">

<h1>RoR Auth0 Sample</h1>

<p>Step 1 - Login.</p>

<%= link_to 'Login', 'auth/auth0', method: :post %>

I am wondering if I am missing some obvious step? I saw in another troubleshooting question that the login route is something the omniauth gem should set up by default, however I do not get rerouted to login when I click on the link.

Have you already tried with a button_to instead of a link_to? The code sample in the linked I mentioned before uses button_to although I’m now noticing that a warning panel in the quickstart does mention the link_to which is confusing. Let me know if button_to improves the situation as if it does and the issue is in the link_to we need to fix the quickstart info.

1 Like

When I try to use button_to instead of link_to, I am met with an error that reads ActionController::InvalidAuthenticityToken.

I uncommented out the content in my application controller, however I still receive this error.

class ApplicationController < ActionController::Base
  protect_from_forgery with: :null_session
end

Have you checked if you are missing (<%= csrf_meta_tags %>) in the main application layout as mentioned in (ruby on rails - ActionController::InvalidAuthenticityToken - Stack Overflow).

I figured it out! Once I added a / before auth/auth0 it worked!

<%= link_to 'Login', '/auth/auth0', method: :post %>
1 Like

Oh, nice, thanks for posting the update; I confess I would likely never notice that missing slash.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.