Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get omniauth to work (error in redirect_callbacks) #139

Closed
davidtlee opened this issue Feb 8, 2015 · 4 comments
Closed

Can't get omniauth to work (error in redirect_callbacks) #139

davidtlee opened this issue Feb 8, 2015 · 4 comments

Comments

@davidtlee
Copy link

Hi, I've been trying to set up devise_token_auth and can't figure out what's wrong. I have a simple button for signing in with Google. When I click the button and sign in, I get this error. Does anyone know why?

image

Thanks! Also, just as an fyi, I didn't separately install devise (not sure if that's necessary); I just followed the directions from the README. It seems like Devise.mappings is nil, but not sure how I can fix that...

@lynndylanhurley
Copy link
Owner

What do your routes look like?

@davidtlee
Copy link
Author

This is my rails routes file. Really appreciate your help!

Rails.application.routes.draw do

  root 'angular_app#index'

  mount_devise_token_auth_for 'User', at: '/auth'

  namespace :api, defaults: { format: 'json' } do

    # List a user's rooms, create and show a room (including the messages within it)
    resources :rooms, only: [:index, :create, :show] do
      # Create and retrieve a message
      resources :messages, only: [:create], shallow: true do
      end
    end

    # Join and leave a room
    resources :participations, only: [:create, :destroy] do
    end
  end

  get '/omniauth/:provider/callback', to: 'devise_token_auth/omniauth_callbacks#redirect_callbacks'
  get '*path', to: 'angular_app#index'
end

Note that I explicitly repeated the get redirect_callbacks route. Without that, for some reason, the route gets listed after the angular_app route which means it gets routed into angular instead of being handled by rails.

@lynndylanhurley
Copy link
Owner

This may be the issue:

get '/omniauth/:provider/callback', to: 'devise_token_auth/omniauth_callbacks#redirect_callbacks'

The route needs to be mounted within a devise_scope, otherwise it won't know which mapping to use.

I would recommend finding a more precise way to do this:

get '*path', to: 'angular_app#index'

so as to avoid route collisions.

@davidtlee
Copy link
Author

Thanks @lynndylanhurley! That does it. I changed to:

get '*path', to: 'angular_app#index', constraints: { path: /(?:(?!omniauth\/).)*/ }

to avoid the omniauth callbacks collision and that seems to do it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants