@@ -15,7 +15,8 @@ defmodule AlgoraWeb.OAuthCallbackController do
15
15
end
16
16
17
17
def new ( conn , % { "provider" => "github" , "code" => code , "state" => state } = params ) do
18
- with { :ok , info } <- Github.OAuth . exchange_access_token ( code: code , state: state ) ,
18
+ with { :ok , _data } <- Github . verify_oauth_state ( state ) ,
19
+ { :ok , info } <- Github.OAuth . exchange_access_token ( code: code , state: state ) ,
19
20
% { info: info , primary_email: primary , emails: emails , token: token } = info ,
20
21
{ :ok , user } <- Accounts . register_github_user ( primary , info , emails , token ) do
21
22
conn =
@@ -29,14 +30,21 @@ defmodule AlgoraWeb.OAuthCallbackController do
29
30
|> put_flash ( :info , welcome_message ( user ) )
30
31
|> AlgoraWeb.UserAuth . log_in_user ( user )
31
32
else
33
+ { :error , :invalid } ->
34
+ conn
35
+ |> put_flash ( :error , "Unable to verify your login request. Please try signing in again." )
36
+ |> redirect ( to: "/" )
37
+
38
+ { :error , :expired } ->
39
+ conn
40
+ |> put_flash ( :error , "Your login link has expired. Please request a new one to continue." )
41
+ |> redirect ( to: "/" )
42
+
32
43
{ :error , % Ecto.Changeset { } = changeset } ->
33
44
Logger . debug ( "failed GitHub insert #{ inspect ( changeset . errors ) } " )
34
45
35
46
conn
36
- |> put_flash (
37
- :error ,
38
- "We were unable to fetch the necessary information from your GitHub account"
39
- )
47
+ |> put_flash ( :error , "We were unable to fetch the necessary information from your GitHub account" )
40
48
|> redirect ( to: "/" )
41
49
42
50
{ :error , reason } ->
0 commit comments