first
This commit is contained in:
commit
8538ab969a
434 changed files with 44051 additions and 0 deletions
3
tooling/scripts/biome.json
Normal file
3
tooling/scripts/biome.json
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"extends": ["../../biome.json"]
|
||||
}
|
||||
22
tooling/scripts/package.json
Normal file
22
tooling/scripts/package.json
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"@repo/database": "workspace:*",
|
||||
"@repo/logs": "workspace:*",
|
||||
"@repo/auth": "workspace:*",
|
||||
"@repo/utils": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "1.9.4",
|
||||
"@repo/tsconfig": "workspace:*",
|
||||
"@types/node": "^22.15.30",
|
||||
"nanoid": "^5.1.5",
|
||||
"tsx": "^4.19.4"
|
||||
},
|
||||
"name": "@repo/scripts",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"create:user": "dotenv -c -e ../../.env -- tsx ./src/create-user.ts",
|
||||
"type-check": "tsc --noEmit"
|
||||
},
|
||||
"version": "0.0.0"
|
||||
}
|
||||
63
tooling/scripts/src/create-user.ts
Normal file
63
tooling/scripts/src/create-user.ts
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
import { auth } from "@repo/auth";
|
||||
import { createUser, createUserAccount, getUserByEmail } from "@repo/database";
|
||||
import { logger } from "@repo/logs";
|
||||
import { nanoid } from "nanoid";
|
||||
|
||||
async function main() {
|
||||
logger.info("Let's create a new user for your application!");
|
||||
|
||||
const email = await logger.prompt("Enter an email:", {
|
||||
required: true,
|
||||
placeholder: "admin@example.com",
|
||||
type: "text",
|
||||
});
|
||||
|
||||
const name = await logger.prompt("Enter a name:", {
|
||||
required: true,
|
||||
placeholder: "Adam Admin",
|
||||
type: "text",
|
||||
});
|
||||
|
||||
const isAdmin = await logger.prompt("Should user be an admin?", {
|
||||
required: true,
|
||||
type: "confirm",
|
||||
default: false,
|
||||
});
|
||||
|
||||
const authContext = await auth.$context;
|
||||
const adminPassword = nanoid(16);
|
||||
const hashedPassword = await authContext.password.hash(adminPassword);
|
||||
|
||||
// check if user exists
|
||||
const user = await getUserByEmail(email);
|
||||
|
||||
if (user) {
|
||||
logger.error("User with this email already exists!");
|
||||
return;
|
||||
}
|
||||
|
||||
const adminUser = await createUser({
|
||||
email,
|
||||
name,
|
||||
role: isAdmin ? "admin" : "user",
|
||||
emailVerified: true,
|
||||
onboardingComplete: true,
|
||||
});
|
||||
|
||||
if (!adminUser) {
|
||||
logger.error("Failed to create user!");
|
||||
return;
|
||||
}
|
||||
|
||||
await createUserAccount({
|
||||
userId: adminUser.id,
|
||||
providerId: "credential",
|
||||
accountId: adminUser.id,
|
||||
hashedPassword,
|
||||
});
|
||||
|
||||
logger.success("User created successfully!");
|
||||
logger.info(`Here is the password for the new user: ${adminPassword}`);
|
||||
}
|
||||
|
||||
main();
|
||||
5
tooling/scripts/tsconfig.json
Normal file
5
tooling/scripts/tsconfig.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"extends": "@repo/tsconfig/base.json",
|
||||
"include": ["**/*.ts"],
|
||||
"exclude": ["dist", "build", "node_modules"]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue