1515
1616class SocialProvider extends Controller
1717{
18- public mixed $ user ;
18+ private ? User $ user ;
1919
2020 public function __construct ()
2121 {
2222 $ this ->user = Auth::user ();
2323 }
2424
25- public function google (Request $ request ): RedirectResponse
25+ public function redirect (Request $ request, string $ provider ): RedirectResponse
2626 {
27- $ this ->createSession ($ request, ' google ' );
27+ $ this ->createSession ($ request );
2828
29- return Socialite::driver ('google ' )->redirect ();
30- }
31-
32- public function github (Request $ request ): RedirectResponse
33- {
34- $ this ->createSession ($ request , 'github ' );
35-
36- return Socialite::driver ('github ' )->redirect ();
29+ return Socialite::driver ($ provider )->redirect ();
3730 }
3831
3932 public function callback (string $ provider ): RedirectResponse
@@ -56,15 +49,15 @@ public function callback(string $provider): RedirectResponse
5649 return $ this ->redirectBack ();
5750 }
5851
59- $ socialAccountByEmail = Social::getUserBySocialAccoutEmail ($ provider , $ socialite ->email );
52+ $ socialAccountByEmail = Social::getUserBySocialAccountEmail ($ provider , $ socialite ->email );
6053
6154 if ($ socialAccountByEmail ->first ()) {
6255 throw new Exception ('Can \'t unlink social account with different email address. ' );
6356 }
6457
65- $ socialAccontsByUserId = Social::getUserBySocialUserId ($ provider , $ this ->user ->id );
58+ $ socialAccountsByUserId = Social::getUserBySocialUserId ($ provider , $ this ->user ->id );
6659
67- if ($ socialAccontsByUserId ->first ()) {
60+ if ($ socialAccountsByUserId ->first ()) {
6861 throw new Exception ('Can \'t unlink social account with different email address. ' );
6962 }
7063
@@ -82,7 +75,7 @@ public function callback(string $provider): RedirectResponse
8275 return $ this ->redirectBack ();
8376 }
8477
85- $ loginUsingSocialAccount = Social::getUserBySocialAccountsId ($ provider , $ socialite ->id )->first ();
78+ $ loginUsingSocialAccount = Social::getUserBySocialAccountId ($ provider , $ socialite ->id )->first ();
8679
8780 if ($ loginUsingSocialAccount ) {
8881 $ user = User::where ('id ' , $ loginUsingSocialAccount ->user_id )->first ();
@@ -178,10 +171,10 @@ private function redirectBack(): RedirectResponse
178171 return Redirect::to ($ intended );
179172 }
180173
181- $ socialite = Session::get ('url.socialite ' );
174+ $ socialiteUrl = Session::get ('url.socialite ' );
182175
183- if ($ socialite ) {
184- return Redirect::to ($ socialite );
176+ if ($ socialiteUrl ) {
177+ return Redirect::to ($ socialiteUrl );
185178 }
186179
187180 return Redirect::route ('profile ' );
0 commit comments