create-prisma-php-app 1.11.18 → 1.11.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -213,38 +213,59 @@ class Auth
213
213
  // Save user data to the database
214
214
  }
215
215
 
216
- public function authProviders(GithubProvider | null $githubProvider = null, GoogleProvider | null $googleProvider = null)
216
+ private function findProvider(array $providers, string $type): ?object
217
+ {
218
+ foreach ($providers as $provider) {
219
+ if ($provider instanceof $type) {
220
+ return $provider;
221
+ }
222
+ }
223
+ return null;
224
+ }
225
+
226
+ public function authProviders(...$providers)
217
227
  {
218
228
  global $isGet, $dynamicRouteParams;
219
229
 
220
- if ($isGet && in_array('signin', $dynamicRouteParams[self::PPHPAUTH]) && in_array('github', $dynamicRouteParams[self::PPHPAUTH]) && $githubProvider) {
221
- $githubAuthUrl = "https://github.com/login/oauth/authorize?scope=user:email%20read:user&client_id=$githubProvider->clientId";
222
- redirect($githubAuthUrl);
223
- } elseif ($isGet && in_array('signin', $dynamicRouteParams[self::PPHPAUTH]) && in_array('google', $dynamicRouteParams[self::PPHPAUTH]) && $googleProvider) {
224
- $googleAuthUrl = "https://accounts.google.com/o/oauth2/v2/auth?"
225
- . "scope=" . urlencode('email profile') . "&"
226
- . "response_type=code&"
227
- . "client_id=" . urlencode($googleProvider->clientId) . "&"
228
- . "redirect_uri=" . urlencode($googleProvider->redirectUri);
229
-
230
- redirect($googleAuthUrl);
230
+ if ($isGet && in_array('signin', $dynamicRouteParams[self::PPHPAUTH])) {
231
+ foreach ($providers as $provider) {
232
+ if ($provider instanceof GithubProvider && in_array('github', $dynamicRouteParams[self::PPHPAUTH])) {
233
+ $githubAuthUrl = "https://github.com/login/oauth/authorize?scope=user:email%20read:user&client_id={$provider->clientId}";
234
+ redirect($githubAuthUrl);
235
+ } elseif ($provider instanceof GoogleProvider && in_array('google', $dynamicRouteParams[self::PPHPAUTH])) {
236
+ $googleAuthUrl = "https://accounts.google.com/o/oauth2/v2/auth?"
237
+ . "scope=" . urlencode('email profile') . "&"
238
+ . "response_type=code&"
239
+ . "client_id=" . urlencode($provider->clientId) . "&"
240
+ . "redirect_uri=" . urlencode($provider->redirectUri);
241
+ redirect($googleAuthUrl);
242
+ }
243
+ }
231
244
  }
232
245
 
233
246
  $authCode = Validator::validateString($_GET['code'] ?? '');
234
247
 
235
- if (
236
- $isGet && in_array('callback', $dynamicRouteParams[self::PPHPAUTH]) &&
237
- in_array('github', $dynamicRouteParams[self::PPHPAUTH]) && isset($authCode)
238
- ) {
239
- return $this->githubProvider($githubProvider, $authCode);
240
- } elseif (
241
- $isGet && in_array('callback', $dynamicRouteParams[self::PPHPAUTH]) &&
242
- in_array('google', $dynamicRouteParams[self::PPHPAUTH]) && isset($authCode)
243
- ) {
244
- return $this->googleProvider($googleProvider, $authCode);
245
- } else {
246
- exit("Error occurred. Please try again.");
248
+ if ($isGet && in_array('callback', $dynamicRouteParams[self::PPHPAUTH]) && isset($authCode)) {
249
+ if (in_array('github', $dynamicRouteParams[self::PPHPAUTH])) {
250
+ $provider = $this->findProvider($providers, GithubProvider::class);
251
+
252
+ if (!$provider) {
253
+ exit("Error occurred. Please try again.");
254
+ }
255
+
256
+ return $this->githubProvider($provider, $authCode);
257
+ } elseif (in_array('google', $dynamicRouteParams[self::PPHPAUTH])) {
258
+ $provider = $this->findProvider($providers, GoogleProvider::class);
259
+
260
+ if (!$provider) {
261
+ exit("Error occurred. Please try again.");
262
+ }
263
+
264
+ return $this->googleProvider($provider, $authCode);
265
+ }
247
266
  }
267
+
268
+ exit("Error occurred. Please try again.");
248
269
  }
249
270
 
250
271
  private function githubProvider(GithubProvider $githubProvider, string $authCode)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma-php-app",
3
- "version": "1.11.18",
3
+ "version": "1.11.19",
4
4
  "description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",