mirror of
https://github.com/xCyanGrizzly/DragonsStash.git
synced 2026-05-11 06:11:15 +00:00
Compare commits
6 Commits
copilot/fi
...
copilot/de
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
987167de0c | ||
|
|
4f331d5411 | ||
|
|
8088a86feb | ||
|
|
b53934ebf2 | ||
|
|
464c86b32a | ||
|
|
fc00fb6f2e |
@@ -125,18 +125,15 @@ docker compose up -d
|
||||
|
||||
The app will be available at [http://localhost:3000](http://localhost:3000).
|
||||
|
||||
### Adding Telegram Services
|
||||
### Adding the Telegram Bot
|
||||
|
||||
The worker and bot run as optional profiles so `docker compose up` works with just the app + database:
|
||||
The worker starts by default with `docker compose up`. The bot runs as an optional profile:
|
||||
|
||||
```bash
|
||||
# App + DB + Telegram worker (needs TELEGRAM_API_ID + TELEGRAM_API_HASH in .env)
|
||||
docker compose --profile telegram up -d
|
||||
|
||||
# App + DB + Worker + Bot (also needs BOT_TOKEN in .env)
|
||||
docker compose --profile full up -d
|
||||
|
||||
# Or just the bot (alongside app + db)
|
||||
# Or just the bot (alongside app + db + worker)
|
||||
docker compose --profile bot up -d
|
||||
```
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ services:
|
||||
retries: 5
|
||||
|
||||
worker:
|
||||
profiles: ["telegram", "full"]
|
||||
build:
|
||||
context: .
|
||||
dockerfile: worker/Dockerfile
|
||||
|
||||
@@ -31,7 +31,6 @@ services:
|
||||
- frontend
|
||||
|
||||
worker:
|
||||
profiles: ["telegram", "full"]
|
||||
build:
|
||||
context: .
|
||||
dockerfile: worker/Dockerfile
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
-- Promote all existing users to ADMIN (self-hosted: every user is an admin)
|
||||
UPDATE "User" SET "role" = 'ADMIN' WHERE "role" = 'USER';
|
||||
|
||||
-- Change the default role for new users to ADMIN
|
||||
ALTER TABLE "User" ALTER COLUMN "role" SET DEFAULT 'ADMIN';
|
||||
@@ -22,7 +22,7 @@ model User {
|
||||
emailVerified DateTime?
|
||||
image String?
|
||||
hashedPassword String?
|
||||
role Role @default(USER)
|
||||
role Role @default(ADMIN)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
|
||||
@@ -21,27 +21,22 @@ export async function registerUser(input: unknown): Promise<ActionResult<{ id: s
|
||||
|
||||
const hashedPassword = await bcrypt.hash(parsed.data.password, 10);
|
||||
|
||||
// First user to register becomes ADMIN (self-hosted owner)
|
||||
const user = await prisma.$transaction(async (tx) => {
|
||||
const userCount = await tx.user.count();
|
||||
const role = userCount === 0 ? "ADMIN" : "USER";
|
||||
|
||||
return tx.user.create({
|
||||
data: {
|
||||
name: parsed.data.name,
|
||||
email: parsed.data.email,
|
||||
hashedPassword,
|
||||
role,
|
||||
settings: {
|
||||
create: {
|
||||
lowStockThreshold: 10,
|
||||
currency: "USD",
|
||||
theme: "dark",
|
||||
units: "metric",
|
||||
},
|
||||
// Self-hosted: all users are admins
|
||||
const user = await prisma.user.create({
|
||||
data: {
|
||||
name: parsed.data.name,
|
||||
email: parsed.data.email,
|
||||
hashedPassword,
|
||||
role: "ADMIN",
|
||||
settings: {
|
||||
create: {
|
||||
lowStockThreshold: 10,
|
||||
currency: "USD",
|
||||
theme: "dark",
|
||||
units: "metric",
|
||||
},
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
return { success: true, data: { id: user.id } };
|
||||
|
||||
@@ -18,12 +18,12 @@ export const { auth, handlers, signIn, signOut } = NextAuth({
|
||||
async jwt({ token, user }) {
|
||||
if (user) {
|
||||
token.id = user.id!;
|
||||
// Fetch the role from the database to pick up first-user ADMIN promotion
|
||||
// Fetch the role from the database to ensure token reflects current role
|
||||
const dbUser = await prisma.user.findUnique({
|
||||
where: { id: user.id! },
|
||||
select: { role: true },
|
||||
});
|
||||
token.role = dbUser?.role ?? user.role ?? "USER";
|
||||
token.role = dbUser?.role ?? user.role ?? "ADMIN";
|
||||
}
|
||||
return token;
|
||||
},
|
||||
@@ -38,17 +38,11 @@ export const { auth, handlers, signIn, signOut } = NextAuth({
|
||||
events: {
|
||||
async createUser({ user }) {
|
||||
if (user.id) {
|
||||
// First user to register becomes ADMIN (self-hosted owner)
|
||||
const adminExists = await prisma.user.findFirst({
|
||||
where: { role: "ADMIN" },
|
||||
select: { id: true },
|
||||
// Self-hosted: all users are admins
|
||||
await prisma.user.update({
|
||||
where: { id: user.id },
|
||||
data: { role: "ADMIN" },
|
||||
});
|
||||
if (!adminExists) {
|
||||
await prisma.user.update({
|
||||
where: { id: user.id },
|
||||
data: { role: "ADMIN" },
|
||||
});
|
||||
}
|
||||
|
||||
await prisma.userSettings.upsert({
|
||||
where: { userId: user.id },
|
||||
|
||||
Reference in New Issue
Block a user