-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
INFRA15 - Add the first Organizer account using the seeding script
- Loading branch information
1 parent
3376156
commit 590efa3
Showing
1 changed file
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
require("dotenv").config({ path: "../.env" }); | ||
|
||
const app = require("firebase-admin").initializeApp({ | ||
credential: require("firebase-admin").credential.cert( | ||
JSON.parse(process.env.FIREBASE_SERVICE_ACCOUNT || "{}"), | ||
), | ||
}); | ||
|
||
const rl = require("readline").createInterface({ | ||
input: process.stdin, | ||
output: process.stdout, | ||
}); | ||
|
||
rl._writeToOutput = function _writeToOutput(stringToWrite) { | ||
if (rl.stdoutMuted) rl.output.write("*"); | ||
else rl.output.write(stringToWrite); | ||
}; | ||
|
||
const setCustomClaim = (claim, uid) => { | ||
return app.auth().setCustomUserClaims(uid, { [claim]: true }); | ||
}; | ||
|
||
const createOrganizerAccount = async () => { | ||
console.log( | ||
"\x1b[33m", | ||
` | ||
██╗ ██╗███████╗██████╗ ██╗ ██╗██╗ ██████╗ ███████╗███████╗███████╗██████╗ ███████╗ | ||
██║ ██║██╔════╝██╔══██╗██║ ██║██║██╔════╝ ██╔════╝██╔════╝██╔════╝██╔══██╗██╔════╝ | ||
███████║█████╗ ██║ ██║██║ █╗ ██║██║██║ ███╗ ███████╗█████╗ █████╗ ██║ ██║███████╗ | ||
██╔══██║██╔══╝ ██║ ██║██║███╗██║██║██║ ██║ ╚════██║██╔══╝ ██╔══╝ ██║ ██║╚════██║ | ||
██║ ██║███████╗██████╔╝╚███╔███╔╝██║╚██████╔╝ ███████║███████╗███████╗██████╔╝███████║ | ||
╚═╝ ╚═╝╚══════╝╚═════╝ ╚══╝╚══╝ ╚═╝ ╚═════╝ ╚══════╝╚══════╝╚══════╝╚═════╝ ╚══════╝ | ||
CREATE ORGANIZER ACCOUNT | ||
`, | ||
"\x1b[0m", | ||
); | ||
const email = await new Promise((resolve) => { | ||
rl.question("Enter email: ", resolve); | ||
}); | ||
const displayName = await new Promise((resolve) => { | ||
rl.question("Enter display name: ", resolve); | ||
}); | ||
const password = await new Promise((resolve) => { | ||
rl.question("Enter password: ", resolve); | ||
rl.stdoutMuted = true; | ||
}); | ||
|
||
try { | ||
const user = await app.auth().createUser({ | ||
email, | ||
password, | ||
displayName, | ||
}); | ||
|
||
await setCustomClaim("organizer", user.uid); | ||
|
||
const verifyEmailLink = await app | ||
.auth() | ||
.generateEmailVerificationLink(email); | ||
|
||
console.log(` | ||
\x1b[32m | ||
🎉 Organizer account configured successfully! 🎉 | ||
\x1b[0m | ||
You can verify your email by clicking on the link below:\x1b[0m | ||
\x1b[36m${verifyEmailLink} | ||
`); | ||
} catch (error) { | ||
console.error( | ||
"\x1b[31m", | ||
` | ||
🚫 Error while configuring account: ${error.message} 🚫 | ||
`, | ||
"\x1b[0m", | ||
); | ||
} finally { | ||
rl.close(); | ||
} | ||
}; | ||
|
||
createOrganizerAccount(); |