-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.mjs
87 lines (76 loc) · 2.45 KB
/
setup.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* This script runs `npx @convex-dev/auth` to help with setting up
* environment variables for Convex Auth.
*
* You can safely delete it and remove it from package.json scripts.
*/
import fs from 'fs';
import { config as loadEnvFile } from 'dotenv';
import { spawnSync } from 'child_process';
if (!fs.existsSync('.env.local')) {
// Something is off, skip the script.
process.exit(0);
}
const config = {};
loadEnvFile({ path: '.env.local', processEnv: config });
const runOnceWorkflow = process.argv.includes('--once');
if (runOnceWorkflow && config.SETUP_SCRIPT_RAN !== undefined) {
// The script has already ran once, skip.
process.exit(0);
}
// The fallback should never be used.
const deploymentName =
config.CONVEX_DEPLOYMENT.split(':').slice(-1)[0] ?? '<your deployment name>';
const variables = JSON.stringify({
help:
'This template includes prebuilt sign-in via GitHub OAuth and ' +
'magic links via Resend. ' +
'This command can help you configure the credentials for these services ' +
'via additional Convex environment variables.',
providers: [
{
name: 'GitHub OAuth',
help:
'Create a GitHub OAuth App, follow the instruction here: ' +
'https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/creating-an-oauth-app\n\n' +
`When you're asked for a callback URL use:\n\n` +
` https://${deploymentName}.convex.site/api/auth/callback/github`,
variables: [
{
name: 'AUTH_GITHUB_ID',
description: 'the Client ID of your GitHub OAuth App',
},
{
name: 'AUTH_GITHUB_SECRET',
description: 'the generated client secret',
},
],
},
{
name: 'Resend',
help: 'Sign up for Resend at https://resend.com/signup. Then create an API Key.',
variables: [
{
name: 'AUTH_RESEND_KEY',
description: 'the API Key',
},
],
},
],
success:
"You're all set. If you need to, you can rerun this command with `node setup.mjs`.",
});
console.error(
'You chose Convex Auth as the auth solution. ' +
'This command will walk you through setting up ' +
'the required Convex environment variables'
);
const result = spawnSync(
'npx',
['@convex-dev/auth', '--variables', variables, '--skip-git-check'],
{ stdio: 'inherit' }
);
if (runOnceWorkflow) {
fs.writeFileSync('.env.local', `\nSETUP_SCRIPT_RAN=1\n`, { flag: 'a' });
}
process.exit(result.status);