質問編集履歴

1

質問の変更

2018/03/09 18:02

投稿

ruby_0ct
ruby_0ct

スコア57

test CHANGED
@@ -1 +1 @@
1
- Rail GoogleログインでNot found. Authentication passthru.
1
+ Rail Googleログイン後のview表示について
test CHANGED
@@ -1,17 +1,137 @@
1
- deviseとomniauth-google-oauth2を利用して、以下のサトと全く同じ通り設定したのですが、Googleでログインするボタンをクリックした後に
1
+ deviseとomniauth-google-oauth2を利用してログンは可能なったのですが、
2
2
 
3
- ```ここに言語を入力
4
-
5
- Not found. Authentication passthru.
3
+ ログイン後の表示がdeviseのメールアドレスとパスワードのログイン画面となってしまい、ログイン完了のviewが表示されません。
6
-
7
- ```
8
-
9
- と表示されうまくできません。
10
4
 
11
5
 
6
+
7
+ ルーティングの問題でしょうか。どのようにしたら、ログイン完了画面が表示されるのか教えていただけると幸いです。
8
+
9
+
10
+
11
+ ちなみに、下記のサイトを参照しました。
12
12
 
13
13
  [Qiita - deviseとomniauthを使ったGoogle認証の流れ](https://qiita.com/s-show/items/9de77de4eb480f779aa4)
14
14
 
15
15
 
16
16
 
17
+ ### コントローラ
18
+
19
+ user_controller.rb
20
+
21
+ ```ここに言語を入力
22
+
23
+ class UserController < ApplicationController
24
+
25
+ def user_cal
26
+
27
+ end
28
+
29
+ end
30
+
31
+ ```
32
+
33
+ welcome_controller.rb
34
+
35
+ ```ここに言語を入力
36
+
37
+ class WelcomeController < ApplicationController
38
+
39
+ def index
40
+
41
+ end
42
+
43
+ end
44
+
45
+ ```
46
+
47
+
48
+
49
+
50
+
51
+ ### model
52
+
53
+ user.rb
54
+
55
+ ```ここに言語を入力
56
+
57
+ class User < ApplicationRecord
58
+
59
+ devise :database_authenticatable, :registerable,
60
+
61
+ :recoverable, :rememberable, :trackable, :validatable, :omniauthable
62
+
63
+
64
+
65
+ def self.find_for_google_oauth2(auth)
66
+
67
+ user = User.where(email: auth.info.email).first
68
+
69
+ unless user
70
+
71
+ user = User.create(name: auth.info.name,
72
+
73
+ provider: auth.provider,
74
+
75
+ uid: auth.uid,
76
+
17
- 原因わかりますでしょうか?ご回答頂ければ幸いです。
77
+ email: auth.info.email,
78
+
79
+ token: auth.credentials.token,
80
+
81
+ password: Devise.friendly_token[0, 20])
82
+
83
+ end
84
+
85
+ user
86
+
87
+ end
88
+
89
+ end
90
+
91
+
92
+
93
+ ```
94
+
95
+
96
+
97
+ ### view
98
+
99
+ welcome/index.html.erb
100
+
101
+ ```ここに言語を入力
102
+
103
+ <%= link_to "Googleでログイン", user_google_oauth2_omniauth_authorize_path %>
104
+
105
+ ```
106
+
107
+ user/user_cal.html.erb
108
+
109
+ ```ここに言語を入力
110
+
111
+ <p>ログイン完了</p>
112
+
113
+ ```
114
+
115
+
116
+
117
+ ### ルーティング
118
+
119
+ ```ここに言語を入力
120
+
121
+ Rails.application.routes.draw do
122
+
123
+ devise_for :users, controllers: {
124
+
125
+ omniauth_callbacks: "users/omniauth_callbacks"
126
+
127
+ }
128
+
129
+
130
+
131
+ get 'user/cal', as: 'user_root'
132
+
133
+ root to: 'welcome#index'
134
+
135
+ end
136
+
137
+ ```