-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateAuth.sh
More file actions
executable file
·115 lines (90 loc) · 2.61 KB
/
createAuth.sh
File metadata and controls
executable file
·115 lines (90 loc) · 2.61 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
rm -- "$0"
echo "installing jq"
brew install jq
echo "Please enter your GitHub token:"
read -s GITHUB_TOKEN
echo
if [ -z "$GITHUB_TOKEN" ]; then
echo "Error: GitHub token cannot be empty"
exit 1
fi
cat > .yarnrc.yml << EOF
nodeLinker: node-modules
enableGlobalCache: true
enableTelemetry: false
npmRegistryServer: "https://registry.npmjs.org"
npmRegistries:
"https://npm.pkg.github.com":
npmAuthToken: $GITHUB_TOKEN
npmScopes:
fluss:
npmRegistryServer: "https://npm.pkg.github.com"
npmPublishRegistry: "https://npm.pkg.github.com"
EOF
yarn init
rm .editorconfig .gitattributes
echo "✓ .yarnrc.yml has been created successfully!"
yarn add sst @fluss/auth
mkdir infra && cd infra
cat > authModule.ts << EOF
import { Auth } from '@fluss/auth/server'
const authoriser = new Auth()
export const { auth, userTable, authoriserFunction } = authoriser.createAuthoriser()
EOF
cd ../
echo "Initialising SST, follow the prompts"
yarn sst init
if [ -f "sst.config.ts" ]; then
if grep -q "await import('./infra/authModule')" sst.config.ts; then
echo "✓ sst.config.ts already contains the authModule import"
else
awk '
{
if ($0 ~ /async run\(\) *{ *}/) {
sub(/async run\(\) *{ *}/, "async run() {\n await import(\"./infra/authModule\")\n }")
}
print
}' sst.config.ts > sst.config.ts.tmp \
&& mv sst.config.ts.tmp sst.config.ts
echo "✓ sst.config.ts has been updated with authModule import!"
fi
else
echo "⚠ Warning: sst.config.ts not found, skipping SST config setup"
fi
echo "Please add credentials and regions to your sst config before running an example is like:"
cat << 'EOF'
export default $config({
app(input) {
return {
name: 'mysite',
removal: input?.stage === 'live' ? 'remove' : 'remove',
protect: [''].includes(input?.stage),
home: 'aws',
providers: input?.stage === "live" ? {
aws: {
profile: "my_site",
region: "af-south-1",
}
} : {}
};
},
});
EOF
echo "Final step is to setup your config.json - please ensure that the specified info matches what is in your frontend"
echo "Please enter your clientId (this should match in your backend):"
read -s CLIENT_ID
echo
if [ -z "$CLIENT_ID" ]; then
echo "Error: clientId cannot be empty"
exit 1
fi
cat > config.json << EOF
{
"auth": {
"clientId": "$CLIENT_ID",
"authoriser": true
}
}
EOF
echo "once you have setup your profile and region for your sst config, deploy by running yarn sst deploy --stage=<YOUR_STAGE> or yarn sst dev --stage=<YOUR_STAGE>"