teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

質問の変更

2018/03/09 18:02

投稿

ruby_0ct
ruby_0ct

スコア57

title CHANGED
@@ -1,1 +1,1 @@
1
- Rail GoogleログインでNot found. Authentication passthru.
1
+ Rail Googleログイン後のview表示について
body CHANGED
@@ -1,9 +1,69 @@
1
- deviseとomniauth-google-oauth2を利用して、以下のサトと全く同じ通り設定したのですが、Googleでログインするボタンをクリックした後に
1
+ deviseとomniauth-google-oauth2を利用してログンは可能なったのですが、
2
+ ログイン後の表示がdeviseのメールアドレスとパスワードのログイン画面となってしまい、ログイン完了のviewが表示されません。
3
+
4
+ ルーティングの問題でしょうか。どのようにしたら、ログイン完了画面が表示されるのか教えていただけると幸いです。
5
+
6
+ ちなみに、下記のサイトを参照しました。
7
+ [Qiita - deviseとomniauthを使ったGoogle認証の流れ](https://qiita.com/s-show/items/9de77de4eb480f779aa4)
8
+
9
+ ### コントローラ
10
+ user_controller.rb
2
11
  ```ここに言語を入力
3
- Not found. Authentication passthru.
12
+ class UserController < ApplicationController
13
+ def user_cal
14
+ end
15
+ end
4
16
  ```
17
+ welcome_controller.rb
5
- と表示されうまくできません。
18
+ ```ここに言語を入力
19
+ class WelcomeController < ApplicationController
20
+ def index
21
+ end
22
+ end
23
+ ```
6
24
 
7
- [Qiita - deviseとomniauthを使ったGoogle認証の流れ](https://qiita.com/s-show/items/9de77de4eb480f779aa4)
8
25
 
26
+ ### model
27
+ user.rb
28
+ ```ここに言語を入力
29
+ class User < ApplicationRecord
30
+ devise :database_authenticatable, :registerable,
31
+ :recoverable, :rememberable, :trackable, :validatable, :omniauthable
32
+
33
+ def self.find_for_google_oauth2(auth)
34
+ user = User.where(email: auth.info.email).first
35
+ unless user
36
+ user = User.create(name: auth.info.name,
37
+ provider: auth.provider,
38
+ uid: auth.uid,
9
- 原因わかりますでしょうか?ご回答頂ければ幸いです。
39
+ email: auth.info.email,
40
+ token: auth.credentials.token,
41
+ password: Devise.friendly_token[0, 20])
42
+ end
43
+ user
44
+ end
45
+ end
46
+
47
+ ```
48
+
49
+ ### view
50
+ welcome/index.html.erb
51
+ ```ここに言語を入力
52
+ <%= link_to "Googleでログイン", user_google_oauth2_omniauth_authorize_path %>
53
+ ```
54
+ user/user_cal.html.erb
55
+ ```ここに言語を入力
56
+ <p>ログイン完了</p>
57
+ ```
58
+
59
+ ### ルーティング
60
+ ```ここに言語を入力
61
+ Rails.application.routes.draw do
62
+ devise_for :users, controllers: {
63
+ omniauth_callbacks: "users/omniauth_callbacks"
64
+ }
65
+
66
+ get 'user/cal', as: 'user_root'
67
+ root to: 'welcome#index'
68
+ end
69
+ ```