6
6
use Illuminate \Auth \Events \Registered ;
7
7
use Illuminate \Foundation \Http \FormRequest ;
8
8
use Illuminate \Support \Facades \Auth ;
9
+ use Inertia \Inertia ;
9
10
use Laravel \WorkOS \User ;
10
11
use Laravel \WorkOS \WorkOS ;
12
+ use Symfony \Component \HttpFoundation \Response ;
11
13
use WorkOS \UserManagement ;
12
14
13
15
class AuthKitAuthenticationRequest extends FormRequest
@@ -34,7 +36,7 @@ public function authenticate(?callable $findUsing = null, ?callable $createUsing
34
36
$ user ->user ,
35
37
$ user ->access_token ,
36
38
$ user ->refresh_token ,
37
- $ user ->organization_id ,
39
+ $ user ->organizationId ,
38
40
];
39
41
40
42
$ user = new User (
@@ -66,6 +68,20 @@ public function authenticate(?callable $findUsing = null, ?callable $createUsing
66
68
return $ existingUser ;
67
69
}
68
70
71
+ /**
72
+ * Redirect the user to the previous or default URL.
73
+ */
74
+ public function redirect (string $ default = '/ ' ): Response
75
+ {
76
+ $ url = rtrim (base64_decode ($ this ->session ()->get ('state ' )), '/ ' ) ?: null ;
77
+
78
+ $ to = $ url !== null && $ url !== url ('/ ' ) ? $ url : $ default ;
79
+
80
+ return class_exists (Inertia::class)
81
+ ? Inertia::location ($ to )
82
+ : redirect ($ to );
83
+ }
84
+
69
85
/**
70
86
* Find the user with the given WorkOS ID.
71
87
*/
@@ -104,7 +120,7 @@ protected function updateUsing(AppUser $user, User $userFromWorkOS): AppUser
104
120
*/
105
121
protected function ensureStateIsValid (): void
106
122
{
107
- $ state = json_decode ($ this ->query ('state ' ), true )['state ' ] ?? false ;
123
+ $ state = json_decode ($ this ->query ('state ' ), true )['state ' ] ?? null ;
108
124
109
125
if ($ state !== $ this ->session ()->get ('state ' )) {
110
126
abort (403 );
0 commit comments