create-prisma-php-app 1.11.15 → 1.11.17
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.
- package/composer.json +2 -1
- package/dist/index.js +1 -1
- package/dist/prisma/schema.prisma +2 -0
- package/dist/prisma-client-php/index.enc +1 -1
- package/dist/prisma-php.js +100 -100
- package/dist/src/Lib/Auth/Auth.php +259 -1
- package/package.json +1 -1
package/dist/prisma-php.js
CHANGED
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import chalk from"chalk";import{spawn}from"child_process";import fs from"fs";import path from"path";import prompts from"prompts";import{fileURLToPath}from"url";const __filename=fileURLToPath(import.meta.url),__dirname=path.dirname(__filename),args=process.argv.slice(2),readJsonFile=e=>{const t=fs.readFileSync(e,"utf8");return JSON.parse(t)},executeCommand=(e,t=[],o={})=>new Promise(((r,a)=>{const s=spawn(e,t,Object.assign({stdio:"inherit",shell:!0},o));s.on("error",(e=>{a(e)})),s.on("close",(e=>{0===e?r():a(new Error(`Process exited with code ${e}`))}))}));async function getAnswer(){const e=[{type:"toggle",name:"shouldProceed",message:`This command will update the ${chalk.blue("create-prisma-php-app")} package and overwrite all default files. ${chalk.blue("Do you want to proceed")}?`,initial:!1,active:"Yes",inactive:"No"}],t=await prompts(e,{onCancel:()=>{process.exit(0)}});return 0===Object.keys(t).length?null:t}const commandsToExecute={generateClass:"npx php generate class",update:"npx php update project"};
|
|
3
|
-
const main = async () => {
|
|
4
|
-
if (args.length === 0) {
|
|
5
|
-
console.log("No command provided.");
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
const formattedCommand = `npx php ${args.join(" ")}`;
|
|
9
|
-
const commandsArray = Object.values(commandsToExecute);
|
|
10
|
-
if (!commandsArray.includes(formattedCommand)) {
|
|
11
|
-
console.log("Command not recognized or not allowed.");
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
if (formattedCommand === commandsToExecute.update) {
|
|
15
|
-
try {
|
|
16
|
-
const answer = await getAnswer();
|
|
17
|
-
if (
|
|
18
|
-
!(answer === null || answer === void 0 ? void 0 : answer.shouldProceed)
|
|
19
|
-
) {
|
|
20
|
-
console.log(chalk.red("Operation cancelled by the user."));
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
const currentDir = process.cwd();
|
|
24
|
-
const configPath = path.join(currentDir, "prisma-php.json");
|
|
25
|
-
if (!fs.existsSync(configPath)) {
|
|
26
|
-
console.error(
|
|
27
|
-
chalk.red(
|
|
28
|
-
"The configuration file 'prisma-php.json' was not found in the current directory."
|
|
29
|
-
)
|
|
30
|
-
);
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
const localSettings = readJsonFile(configPath);
|
|
34
|
-
const commandArgs = [localSettings.projectName];
|
|
35
|
-
if (localSettings.tailwindcss) commandArgs.push("--tailwindcss");
|
|
36
|
-
if (localSettings.websocket) commandArgs.push("--websocket");
|
|
37
|
-
if (localSettings.prisma) commandArgs.push("--prisma");
|
|
38
|
-
console.log("Executing command...\n");
|
|
39
|
-
await executeCommand("npx", [
|
|
40
|
-
"create-prisma-php-app@latest",
|
|
41
|
-
...commandArgs,
|
|
42
|
-
]);
|
|
43
|
-
} catch (error) {
|
|
44
|
-
if (error instanceof Error) {
|
|
45
|
-
if (error.message.includes("no such file or directory")) {
|
|
46
|
-
console.error(
|
|
47
|
-
chalk.red(
|
|
48
|
-
"The configuration file 'prisma-php.json' was not found in the current directory."
|
|
49
|
-
)
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
} else {
|
|
53
|
-
console.error("Error in script execution:", error);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
if (formattedCommand === commandsToExecute.generateClass) {
|
|
58
|
-
try {
|
|
59
|
-
const currentDir = process.cwd();
|
|
60
|
-
const configPath = path.join(currentDir, "prisma-php.json");
|
|
61
|
-
if (!fs.existsSync(configPath)) {
|
|
62
|
-
console.error(
|
|
63
|
-
chalk.red(
|
|
64
|
-
"The configuration file 'prisma-php.json' was not found in the current directory."
|
|
65
|
-
)
|
|
66
|
-
);
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
const localSettings = readJsonFile(configPath);
|
|
70
|
-
if (!localSettings.prisma) {
|
|
71
|
-
console.error(
|
|
72
|
-
chalk.red(
|
|
73
|
-
"Install the 'Prisma PHP ORM' package by running the command 'npx php update project'."
|
|
74
|
-
)
|
|
75
|
-
);
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
const prismaClientPath = path.join(
|
|
79
|
-
__dirname,
|
|
80
|
-
"prisma-client-php",
|
|
81
|
-
"index.js"
|
|
82
|
-
);
|
|
83
|
-
if (!fs.existsSync(prismaClientPath)) {
|
|
84
|
-
console.error(
|
|
85
|
-
chalk.red(
|
|
86
|
-
"The 'prisma-client-php' package was not found in the current directory."
|
|
87
|
-
)
|
|
88
|
-
);
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
console.log("Executing command...\n");
|
|
92
|
-
await executeCommand("node", [prismaClientPath]);
|
|
93
|
-
} catch (error) {
|
|
94
|
-
console.error("Error in script execution:", error);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
main().catch((error) => {
|
|
99
|
-
console.error("Unhandled error in main function:", error);
|
|
100
|
-
});
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import chalk from"chalk";import{spawn}from"child_process";import fs from"fs";import path from"path";import prompts from"prompts";import{fileURLToPath}from"url";const __filename=fileURLToPath(import.meta.url),__dirname=path.dirname(__filename),args=process.argv.slice(2),readJsonFile=e=>{const t=fs.readFileSync(e,"utf8");return JSON.parse(t)},executeCommand=(e,t=[],o={})=>new Promise(((r,a)=>{const s=spawn(e,t,Object.assign({stdio:"inherit",shell:!0},o));s.on("error",(e=>{a(e)})),s.on("close",(e=>{0===e?r():a(new Error(`Process exited with code ${e}`))}))}));async function getAnswer(){const e=[{type:"toggle",name:"shouldProceed",message:`This command will update the ${chalk.blue("create-prisma-php-app")} package and overwrite all default files. ${chalk.blue("Do you want to proceed")}?`,initial:!1,active:"Yes",inactive:"No"}],t=await prompts(e,{onCancel:()=>{process.exit(0)}});return 0===Object.keys(t).length?null:t}const commandsToExecute={generateClass:"npx php generate class",update:"npx php update project"};
|
|
3
|
+
const main = async () => {
|
|
4
|
+
if (args.length === 0) {
|
|
5
|
+
console.log("No command provided.");
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
const formattedCommand = `npx php ${args.join(" ")}`;
|
|
9
|
+
const commandsArray = Object.values(commandsToExecute);
|
|
10
|
+
if (!commandsArray.includes(formattedCommand)) {
|
|
11
|
+
console.log("Command not recognized or not allowed.");
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (formattedCommand === commandsToExecute.update) {
|
|
15
|
+
try {
|
|
16
|
+
const answer = await getAnswer();
|
|
17
|
+
if (
|
|
18
|
+
!(answer === null || answer === void 0 ? void 0 : answer.shouldProceed)
|
|
19
|
+
) {
|
|
20
|
+
console.log(chalk.red("Operation cancelled by the user."));
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const currentDir = process.cwd();
|
|
24
|
+
const configPath = path.join(currentDir, "prisma-php.json");
|
|
25
|
+
if (!fs.existsSync(configPath)) {
|
|
26
|
+
console.error(
|
|
27
|
+
chalk.red(
|
|
28
|
+
"The configuration file 'prisma-php.json' was not found in the current directory."
|
|
29
|
+
)
|
|
30
|
+
);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const localSettings = readJsonFile(configPath);
|
|
34
|
+
const commandArgs = [localSettings.projectName];
|
|
35
|
+
if (localSettings.tailwindcss) commandArgs.push("--tailwindcss");
|
|
36
|
+
if (localSettings.websocket) commandArgs.push("--websocket");
|
|
37
|
+
if (localSettings.prisma) commandArgs.push("--prisma");
|
|
38
|
+
console.log("Executing command...\n");
|
|
39
|
+
await executeCommand("npx", [
|
|
40
|
+
"create-prisma-php-app@latest",
|
|
41
|
+
...commandArgs,
|
|
42
|
+
]);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
if (error instanceof Error) {
|
|
45
|
+
if (error.message.includes("no such file or directory")) {
|
|
46
|
+
console.error(
|
|
47
|
+
chalk.red(
|
|
48
|
+
"The configuration file 'prisma-php.json' was not found in the current directory."
|
|
49
|
+
)
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
console.error("Error in script execution:", error);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (formattedCommand === commandsToExecute.generateClass) {
|
|
58
|
+
try {
|
|
59
|
+
const currentDir = process.cwd();
|
|
60
|
+
const configPath = path.join(currentDir, "prisma-php.json");
|
|
61
|
+
if (!fs.existsSync(configPath)) {
|
|
62
|
+
console.error(
|
|
63
|
+
chalk.red(
|
|
64
|
+
"The configuration file 'prisma-php.json' was not found in the current directory."
|
|
65
|
+
)
|
|
66
|
+
);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const localSettings = readJsonFile(configPath);
|
|
70
|
+
if (!localSettings.prisma) {
|
|
71
|
+
console.error(
|
|
72
|
+
chalk.red(
|
|
73
|
+
"Install the 'Prisma PHP ORM' package by running the command 'npx php update project'."
|
|
74
|
+
)
|
|
75
|
+
);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const prismaClientPath = path.join(
|
|
79
|
+
__dirname,
|
|
80
|
+
"prisma-client-php",
|
|
81
|
+
"index.js"
|
|
82
|
+
);
|
|
83
|
+
if (!fs.existsSync(prismaClientPath)) {
|
|
84
|
+
console.error(
|
|
85
|
+
chalk.red(
|
|
86
|
+
"The 'prisma-client-php' package was not found in the current directory."
|
|
87
|
+
)
|
|
88
|
+
);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
console.log("Executing command...\n");
|
|
92
|
+
await executeCommand("node", [prismaClientPath]);
|
|
93
|
+
} catch (error) {
|
|
94
|
+
console.error("Error in script execution:", error);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
main().catch((error) => {
|
|
99
|
+
console.error("Unhandled error in main function:", error);
|
|
100
|
+
});
|
|
@@ -6,13 +6,18 @@ use Firebase\JWT\JWT;
|
|
|
6
6
|
use Firebase\JWT\Key;
|
|
7
7
|
use DateInterval;
|
|
8
8
|
use DateTime;
|
|
9
|
+
use Lib\Validator;
|
|
10
|
+
use GuzzleHttp\Client;
|
|
11
|
+
use GuzzleHttp\Exception\RequestException;
|
|
12
|
+
use Lib\Prisma\Classes\Prisma;
|
|
9
13
|
|
|
10
14
|
class Auth
|
|
11
15
|
{
|
|
12
16
|
public const PAYLOAD_NAME = 'role';
|
|
13
17
|
public const ROLE_NAME = '';
|
|
14
18
|
public const PAYLOAD = 'payload';
|
|
15
|
-
public const COOKIE_NAME = '
|
|
19
|
+
public const COOKIE_NAME = 'pphp_aut_token';
|
|
20
|
+
private const PPHPAUTH = 'pphpauth';
|
|
16
21
|
|
|
17
22
|
private $secretKey;
|
|
18
23
|
private $defaultTokenValidity = '1h'; // Default to 1 hour
|
|
@@ -182,4 +187,257 @@ class Auth
|
|
|
182
187
|
|
|
183
188
|
return null;
|
|
184
189
|
}
|
|
190
|
+
|
|
191
|
+
private function exchangeCode($data, $apiUrl)
|
|
192
|
+
{
|
|
193
|
+
try {
|
|
194
|
+
$client = new Client();
|
|
195
|
+
$response = $client->post($apiUrl, [
|
|
196
|
+
'headers' => [
|
|
197
|
+
'Accept' => 'application/json',
|
|
198
|
+
],
|
|
199
|
+
'form_params' => $data,
|
|
200
|
+
]);
|
|
201
|
+
|
|
202
|
+
if ($response->getStatusCode() === 200) {
|
|
203
|
+
return json_decode($response->getBody()->getContents());
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return false;
|
|
207
|
+
} catch (RequestException) {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
public function authProviders(GithubProvider | null $githubProvider = null, GoogleProvider | null $googleProvider = null)
|
|
213
|
+
{
|
|
214
|
+
global $isGet, $dynamicRouteParams;
|
|
215
|
+
|
|
216
|
+
if ($isGet && in_array('signin', $dynamicRouteParams[self::PPHPAUTH]) && in_array('github', $dynamicRouteParams[self::PPHPAUTH]) && $githubProvider) {
|
|
217
|
+
$githubAuthUrl = "https://github.com/login/oauth/authorize?scope=user:email%20read:user&client_id=$githubProvider->clientId";
|
|
218
|
+
redirect($githubAuthUrl);
|
|
219
|
+
} elseif ($isGet && in_array('signin', $dynamicRouteParams[self::PPHPAUTH]) && in_array('google', $dynamicRouteParams[self::PPHPAUTH]) && $googleProvider) {
|
|
220
|
+
$googleAuthUrl = "https://accounts.google.com/o/oauth2/v2/auth?"
|
|
221
|
+
. "scope=" . urlencode('email profile') . "&"
|
|
222
|
+
. "response_type=code&"
|
|
223
|
+
. "client_id=" . urlencode($googleProvider->clientId) . "&"
|
|
224
|
+
. "redirect_uri=" . urlencode($googleProvider->redirectUri);
|
|
225
|
+
|
|
226
|
+
redirect($googleAuthUrl);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
$authCode = Validator::validateString($_GET['code'] ?? '');
|
|
230
|
+
|
|
231
|
+
if (
|
|
232
|
+
$isGet && in_array('callback', $dynamicRouteParams[self::PPHPAUTH]) &&
|
|
233
|
+
in_array('github', $dynamicRouteParams[self::PPHPAUTH]) && isset($authCode)
|
|
234
|
+
) {
|
|
235
|
+
return $this->githubProvider($githubProvider, $authCode);
|
|
236
|
+
} elseif (
|
|
237
|
+
$isGet && in_array('callback', $dynamicRouteParams[self::PPHPAUTH]) &&
|
|
238
|
+
in_array('google', $dynamicRouteParams[self::PPHPAUTH]) && isset($authCode)
|
|
239
|
+
) {
|
|
240
|
+
return $this->googleProvider($googleProvider, $authCode);
|
|
241
|
+
} else {
|
|
242
|
+
exit("Error occurred. Please try again.");
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
private function githubProvider(GithubProvider $githubProvider, string $authCode)
|
|
247
|
+
{
|
|
248
|
+
$gitToken = [
|
|
249
|
+
'client_id' => $githubProvider->clientId,
|
|
250
|
+
'client_secret' => $githubProvider->clientSecret,
|
|
251
|
+
'code' => $authCode,
|
|
252
|
+
];
|
|
253
|
+
|
|
254
|
+
$apiUrl = 'https://github.com/login/oauth/access_token';
|
|
255
|
+
$tokenData = (object)$this->exchangeCode($gitToken, $apiUrl);
|
|
256
|
+
|
|
257
|
+
if (!$tokenData) {
|
|
258
|
+
exit("Error occurred. Please try again.");
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (isset($tokenData->error)) {
|
|
262
|
+
exit("Error occurred. Please try again.");
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (isset($tokenData->access_token)) {
|
|
266
|
+
$client = new Client();
|
|
267
|
+
$emailResponse = $client->get('https://api.github.com/user/emails', [
|
|
268
|
+
'headers' => [
|
|
269
|
+
'Authorization' => 'Bearer ' . $tokenData->access_token,
|
|
270
|
+
'Accept' => 'application/json',
|
|
271
|
+
],
|
|
272
|
+
]);
|
|
273
|
+
|
|
274
|
+
$emails = json_decode($emailResponse->getBody()->getContents(), true);
|
|
275
|
+
|
|
276
|
+
$primaryEmail = array_reduce($emails, function ($carry, $item) {
|
|
277
|
+
return ($item['primary'] && $item['verified']) ? $item['email'] : $carry;
|
|
278
|
+
}, null);
|
|
279
|
+
|
|
280
|
+
$response = $client->get('https://api.github.com/user', [
|
|
281
|
+
'headers' => [
|
|
282
|
+
'Accept' => 'application/json',
|
|
283
|
+
'Authorization' => 'Bearer ' . $tokenData->access_token,
|
|
284
|
+
],
|
|
285
|
+
]);
|
|
286
|
+
|
|
287
|
+
if ($response->getStatusCode() == 200) {
|
|
288
|
+
$responseInfo = json_decode($response->getBody()->getContents());
|
|
289
|
+
|
|
290
|
+
$accountData = [
|
|
291
|
+
'provider' => 'github',
|
|
292
|
+
'type' => 'oauth',
|
|
293
|
+
'providerAccountId' => "$responseInfo->id",
|
|
294
|
+
'access_token' => $tokenData->access_token,
|
|
295
|
+
'expires_at' => $tokenData->expires_at ?? null,
|
|
296
|
+
'token_type' => $tokenData->token_type,
|
|
297
|
+
'scope' => $tokenData->scope,
|
|
298
|
+
];
|
|
299
|
+
|
|
300
|
+
$prisma = new Prisma();
|
|
301
|
+
$foundUser = $prisma->user->findUnique([
|
|
302
|
+
'where' => [
|
|
303
|
+
'email' => $primaryEmail,
|
|
304
|
+
],
|
|
305
|
+
]);
|
|
306
|
+
|
|
307
|
+
if (!$foundUser) {
|
|
308
|
+
$userData = [
|
|
309
|
+
'name' => $responseInfo->login,
|
|
310
|
+
'email' => $primaryEmail,
|
|
311
|
+
'image' => $responseInfo->avatar_url,
|
|
312
|
+
'emailVerified' => $primaryEmail ? date("Y-m-d H:i:s") : null,
|
|
313
|
+
'Account' => [
|
|
314
|
+
'create' => $accountData,
|
|
315
|
+
]
|
|
316
|
+
];
|
|
317
|
+
|
|
318
|
+
$createUser = $prisma->user->create([
|
|
319
|
+
'data' => $userData,
|
|
320
|
+
]);
|
|
321
|
+
|
|
322
|
+
if (!$createUser) {
|
|
323
|
+
exit("Error occurred. Please try again.");
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
$userToAuthenticate = [
|
|
328
|
+
'name' => $responseInfo->login,
|
|
329
|
+
'email' => $primaryEmail,
|
|
330
|
+
'image' => $responseInfo->avatar_url,
|
|
331
|
+
'Account' => (object)$accountData
|
|
332
|
+
];
|
|
333
|
+
$userToAuthenticate = (object)$userToAuthenticate;
|
|
334
|
+
|
|
335
|
+
$this->authenticate($userToAuthenticate, $githubProvider->maxAge);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
private function googleProvider(GoogleProvider $googleProvider, string $authCode)
|
|
341
|
+
{
|
|
342
|
+
$googleToken = [
|
|
343
|
+
'client_id' => $googleProvider->clientId,
|
|
344
|
+
'client_secret' => $googleProvider->clientSecret,
|
|
345
|
+
'code' => $authCode,
|
|
346
|
+
'grant_type' => 'authorization_code',
|
|
347
|
+
'redirect_uri' => $googleProvider->redirectUri
|
|
348
|
+
];
|
|
349
|
+
|
|
350
|
+
$apiUrl = 'https://oauth2.googleapis.com/token';
|
|
351
|
+
$tokenData = (object)$this->exchangeCode($googleToken, $apiUrl);
|
|
352
|
+
|
|
353
|
+
if (!$tokenData) {
|
|
354
|
+
exit("Error occurred. Please try again.");
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (isset($tokenData->error)) {
|
|
358
|
+
exit("Error occurred. Please try again.");
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
if (isset($tokenData->access_token)) {
|
|
362
|
+
$client = new Client();
|
|
363
|
+
$response = $client->get('https://www.googleapis.com/oauth2/v1/userinfo', [
|
|
364
|
+
'headers' => [
|
|
365
|
+
'Authorization' => 'Bearer ' . $tokenData->access_token,
|
|
366
|
+
'Accept' => 'application/json',
|
|
367
|
+
],
|
|
368
|
+
]);
|
|
369
|
+
|
|
370
|
+
if ($response->getStatusCode() == 200) {
|
|
371
|
+
$responseInfo = json_decode($response->getBody()->getContents());
|
|
372
|
+
|
|
373
|
+
$accountData = [
|
|
374
|
+
'provider' => 'google',
|
|
375
|
+
'type' => 'oauth',
|
|
376
|
+
'providerAccountId' => "$responseInfo->id",
|
|
377
|
+
'access_token' => $tokenData->access_token,
|
|
378
|
+
'expires_at' => $tokenData->expires_at ?? null,
|
|
379
|
+
'token_type' => $tokenData->token_type,
|
|
380
|
+
'scope' => $tokenData->scope,
|
|
381
|
+
];
|
|
382
|
+
|
|
383
|
+
$prisma = new Prisma();
|
|
384
|
+
$foundUser = $prisma->user->findUnique([
|
|
385
|
+
'where' => [
|
|
386
|
+
'email' => $responseInfo->email,
|
|
387
|
+
],
|
|
388
|
+
]);
|
|
389
|
+
|
|
390
|
+
if (!$foundUser) {
|
|
391
|
+
$userData = [
|
|
392
|
+
'name' => $responseInfo->name,
|
|
393
|
+
'email' => $responseInfo->email,
|
|
394
|
+
'image' => $responseInfo->picture,
|
|
395
|
+
'emailVerified' => $responseInfo->email ? date("Y-m-d H:i:s") : null,
|
|
396
|
+
'Account' => [
|
|
397
|
+
'create' => $accountData,
|
|
398
|
+
]
|
|
399
|
+
];
|
|
400
|
+
|
|
401
|
+
$createUser = $prisma->user->create([
|
|
402
|
+
'data' => $userData,
|
|
403
|
+
]);
|
|
404
|
+
|
|
405
|
+
if (!$createUser) {
|
|
406
|
+
exit("Error occurred. Please try again.");
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
$userToAuthenticate = [
|
|
411
|
+
'name' => $responseInfo->name,
|
|
412
|
+
'email' => $responseInfo->email,
|
|
413
|
+
'image' => $responseInfo->picture,
|
|
414
|
+
'Account' => (object)$accountData
|
|
415
|
+
];
|
|
416
|
+
$userToAuthenticate = (object)$userToAuthenticate;
|
|
417
|
+
|
|
418
|
+
$this->authenticate($userToAuthenticate, $googleProvider->maxAge);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
class GoogleProvider
|
|
425
|
+
{
|
|
426
|
+
public function __construct(
|
|
427
|
+
public string $clientId,
|
|
428
|
+
public string $clientSecret,
|
|
429
|
+
public string $redirectUri,
|
|
430
|
+
public string $maxAge = '30d'
|
|
431
|
+
) {
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
class GithubProvider
|
|
436
|
+
{
|
|
437
|
+
public function __construct(
|
|
438
|
+
public string $clientId,
|
|
439
|
+
public string $clientSecret,
|
|
440
|
+
public string $maxAge = '30d'
|
|
441
|
+
) {
|
|
442
|
+
}
|
|
185
443
|
}
|