@@ -21,8 +21,20 @@ public function show()
2121
2222 public function login ()
2323 {
24+ // Determine callback URL based on current domain
25+ $ currentHost = request ()->getHost ();
26+ $ isCatchEmAll = $ currentHost === config ('fcea.domain ' );
27+
28+ if ($ isCatchEmAll ) {
29+ $ protocol = str_contains ($ currentHost , 'localhost ' ) ? 'http ' : 'https ' ;
30+ $ callbackUrl = $ protocol . ':// ' . $ currentHost . '/auth/callback ' ;
31+ } else {
32+ $ callbackUrl = rtrim (config ('app.url ' ), '/ ' ) . '/auth/callback ' ;
33+ }
34+
2435 $ url = Socialite::driver ('identity ' )
2536 ->scopes (['openid ' , 'profile ' , 'email ' , 'groups ' , 'offline ' , 'offline_access ' ])
37+ ->redirectUrl ($ callbackUrl )
2638 ->redirect ();
2739
2840 // Use Interia location instead
@@ -32,9 +44,31 @@ public function login()
3244 public function loginCallback ()
3345 {
3446 try {
35- $ socialLiteUser = Socialite::driver ('identity ' )->user ();
47+ // Ensure callback URL matches the one used during login redirect
48+ $ currentHost = request ()->getHost ();
49+ $ isCatchEmAll = $ currentHost === config ('fcea.domain ' );
50+
51+ if ($ isCatchEmAll ) {
52+ $ protocol = str_contains ($ currentHost , 'localhost ' ) ? 'http ' : 'https ' ;
53+ $ callbackUrl = $ protocol . ':// ' . $ currentHost . '/auth/callback ' ;
54+ } else {
55+ $ callbackUrl = rtrim (config ('app.url ' ), '/ ' ) . '/auth/callback ' ;
56+ }
57+
58+ $ socialLiteUser = Socialite::driver ('identity ' )
59+ ->redirectUrl ($ callbackUrl )
60+ ->user ();
3661 } catch (\Exception $ e ) {
37- return redirect ()->route ('auth.login ' );
62+ // Redirect to login on the same domain
63+ $ currentHost = request ()->getHost ();
64+ $ isCatchEmAll = $ currentHost === config ('fcea.domain ' );
65+
66+ if ($ isCatchEmAll ) {
67+ $ protocol = str_contains ($ currentHost , 'localhost ' ) ? 'http ' : 'https ' ;
68+ return redirect ($ protocol . ':// ' . $ currentHost . '/auth/login ' );
69+ } else {
70+ return redirect ()->route ('auth.login ' );
71+ }
3872 }
3973
4074 $ attendeeListResponse = \Illuminate \Support \Facades \Http::attsrv ()
@@ -45,8 +79,16 @@ public function loginCallback()
4579 $ regId = $ attendeeListResponse ['ids ' ][0 ] ?? null ;
4680
4781 if (isset ($ attendeeListResponse ['ids ' ][0 ]) === false ) {
48- return redirect ()->route ('welcome ' )->with ('message ' ,
49- 'Please register for the Convention first before trying to obtain a fursuit badge. ' );
82+ $ currentHost = request ()->getHost ();
83+ $ isCatchEmAll = $ currentHost === config ('fcea.domain ' );
84+
85+ if ($ isCatchEmAll ) {
86+ return redirect ()->route ('catch-em-all.introduction ' )->with ('message ' ,
87+ 'Please register for the Convention first before trying to play Catch-Em-All. ' );
88+ } else {
89+ return redirect ()->route ('welcome ' )->with ('message ' ,
90+ 'Please register for the Convention first before trying to obtain a fursuit badge. ' );
91+ }
5092 }
5193
5294 $ isNewUser = User::where ('remote_id ' , $ socialLiteUser ->getId ())->doesntExist ();
@@ -130,24 +172,49 @@ public function loginCallback()
130172 }
131173
132174 Auth::login ($ user , true );
133- if (Session::exists ('catch-em-all-redirect ' )) {
134- Session::forget ('catch-em-all-redirect ' );
135175
136- return redirect ()->route ('catch-em-all.catch ' );
137- }
176+ // Redirect based on current domain
177+ $ currentHost = request ()->getHost ();
178+ $ isCatchEmAll = $ currentHost === config ('fcea.domain ' );
138179
139- return redirect ()->route ('dashboard ' );
180+ if ($ isCatchEmAll ) {
181+ // Redirect to introduction page for new users, or home for returning users
182+ return redirect ()->route ('catch-em-all.introduction ' );
183+ } else {
184+ return redirect ()->route ('dashboard ' );
185+ }
140186 }
141187
142188 public function logout ()
143189 {
144- return Inertia::location ('https://identity.eurofurence.org/oauth2/sessions/logout ' );
190+ $ currentHost = request ()->getHost ();
191+ $ isCatchEmAll = $ currentHost === config ('fcea.domain ' );
192+
193+ if ($ isCatchEmAll ) {
194+ // Include post logout redirect for Catch-Em-All
195+ $ protocol = str_contains ($ currentHost , 'localhost ' ) ? 'http ' : 'https ' ;
196+ $ returnUrl = $ protocol . ':// ' . $ currentHost ;
197+ return Inertia::location ('https://identity.eurofurence.org/oauth2/sessions/logout?post_logout_redirect_uri= ' . urlencode ($ returnUrl ));
198+ } else {
199+ return Inertia::location ('https://identity.eurofurence.org/oauth2/sessions/logout ' );
200+ }
145201 }
146202
147203 // Frontchannel Logout
148204 public function logoutCallback ()
149205 {
150206 Auth::logout ();
151207 Session::flush ();
208+
209+ // Optional: redirect based on domain
210+ $ currentHost = request ()->getHost ();
211+ $ isCatchEmAll = $ currentHost === config ('fcea.domain ' );
212+
213+ if ($ isCatchEmAll ) {
214+ $ protocol = str_contains ($ currentHost , 'localhost ' ) ? 'http ' : 'https ' ;
215+ return redirect ($ protocol . ':// ' . $ currentHost );
216+ }
217+
218+ // For main domain, just complete the logout (no redirect needed)
152219 }
153220}
0 commit comments