Skip to content

Commit

Permalink
リファクタリングする
Browse files Browse the repository at this point in the history
  • Loading branch information
yocchan-git committed Mar 20, 2024
1 parent 0e71bc5 commit 54981ca
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 10 deletions.
4 changes: 0 additions & 4 deletions app/controllers/discord_authentications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,4 @@ def callback
redirect_to root_path, alert: 'Discordの連携に失敗しました'
end
end

def failure
redirect_to root_path, alert: 'Discord認証をキャンセルしました'
end
end
4 changes: 4 additions & 0 deletions app/controllers/user_sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,8 @@ def callback
redirect_to root_path
end
# rubocop:enable Metrics/MethodLength

def failure
redirect_to root_path, alert: 'キャンセルしました'
end
end
6 changes: 1 addition & 5 deletions config/initializers/omniauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,5 @@
provider :github, ENV["GITHUB_KEY"], ENV["GITHUB_SECRET"], scope: 'user:email'
provider :discord, ENV['DISCORD_CLIENT_ID'], ENV['DISCORD_CLIENT_SECRET']

OmniAuth.config.on_failure = proc do |env|
error_type = env['omniauth.error.type']
new_path = "/auth/failure?message=#{error_type}"
[302, {'Location' => new_path, 'Content-Type'=> 'text/html'}, []]
end
OmniAuth.config.on_failure = proc { |_env| [302, {'Location' => '/auth/failure', 'Content-Type'=> 'text/html'}, []] }
end
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
get "login" => "user_sessions#new", as: :login
get "auth/github/callback" => "user_sessions#callback"
get "auth/discord/callback", to: "discord_authentications#callback"
get 'auth/failure', to: "discord_authentications#failure"
get 'auth/failure', to: "user_sessions#failure"
post "user_sessions" => "user_sessions#create"
get "logout" => "user_sessions#destroy", as: :logout
get "thanks", to: "static_pages#thanks"
Expand Down

0 comments on commit 54981ca

Please sign in to comment.