guilhermesad / rspotify

A ruby wrapper for the Spotify Web API
MIT License
717 stars 290 forks source link

No route matches [GET] "/auth/spotify" #243

Closed fakefarm closed 2 years ago

fakefarm commented 2 years ago

Hello, thank you for a great GEM!

I'm having trouble firing the request for for user auth. Any suggestions why I'm getting: No route matches [GET] "/auth/spotify"? (This is a clean install of rails (7.0.0.rc1) ​to try out RSpotify.)

# application.html.erb
<%= link_to 'Sign in with Spotify', '/auth/spotify' %>
# routes.rb
get '/auth/spotify/callback', to: 'users#spotify'
# works in rails c
>  RSpotify::authenticate("secret", "secret")
=> true
# have a user
$ rails g scaffold users email username
# added initializers
require 'rspotify/oauth'

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :spotify, "mycreds", "mycreds", scope: 'user-read-email 
playlist-modify-public user-library-read user-library-modify'
end
# added to application.rb
RSpotify::authenticate("cred", "cred")
fakefarm commented 2 years ago

Update / Solved.

I solved it by doing the following 2 things:

1. I changed the link...

from:

# mentioned in README
<%= link_to 'link in with Spotify', '/auth/spotify' %>

to:

<%= button_to 'Sign in with Spotify', '/auth/spotify' %>

Sidenote:

I tried to add the method: post to link_to but it didn't take. (Maybe User Error)

# This didn't work for me..
   <%= link_to 'link in with Spotify', '/auth/spotify', method: 'post' %>

2. Added the following gems:

gem "omniauth-rails_csrf_protection"
gem 'omniauth-spotify-oauth2', '~> 1.0'

Does this seem right to you? If so, I'd be happy to submit a PR to update README (if that helps.)