mirror of
https://github.com/xCyanGrizzly/DragonsStash.git
synced 2026-05-11 06:11:15 +00:00
Compare commits
20 Commits
copilot/fi
...
copilot/de
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
987167de0c | ||
|
|
4f331d5411 | ||
|
|
8088a86feb | ||
|
|
b53934ebf2 | ||
|
|
464c86b32a | ||
|
|
fc00fb6f2e | ||
|
|
0c0c9c7f23 | ||
|
|
82d5fc1812 | ||
|
|
9120f0fb5d | ||
|
|
5d88f9beb3 | ||
|
|
3704708970 | ||
|
|
0c789eabd6 | ||
|
|
9a88914f11 | ||
|
|
6cc8e1185a | ||
|
|
066fb5a046 | ||
|
|
bed99f8167 | ||
|
|
80a8833f2c | ||
|
|
7303d5c6d3 | ||
|
|
c5ca9a7460 | ||
|
|
186aae38b5 |
13
Dockerfile
13
Dockerfile
@@ -40,12 +40,13 @@ COPY --from=builder /app/prisma.config.ts ./prisma.config.ts
|
|||||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||||
|
|
||||||
# Copy node_modules for prisma CLI (needed for migrate deploy at startup)
|
# Copy node_modules for prisma CLI (needed for migrate deploy at startup).
|
||||||
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
|
# Copying the full directory ensures all transitive dependencies are present.
|
||||||
COPY --from=builder /app/node_modules/@prisma ./node_modules/@prisma
|
COPY --from=builder /app/node_modules ./node_modules
|
||||||
COPY --from=builder /app/node_modules/prisma ./node_modules/prisma
|
# Recreate the .bin/prisma symlink so Node resolves __dirname to prisma/build/,
|
||||||
COPY --from=builder /app/node_modules/.bin/prisma ./node_modules/.bin/prisma
|
# where the WASM files live (COPY dereferences symlinks, breaking WASM resolution)
|
||||||
COPY --from=builder /app/node_modules/dotenv ./node_modules/dotenv
|
RUN mkdir -p ./node_modules/.bin && \
|
||||||
|
ln -sf ../prisma/build/index.js ./node_modules/.bin/prisma
|
||||||
|
|
||||||
# Copy entrypoint script
|
# Copy entrypoint script
|
||||||
COPY --chown=nextjs:nodejs docker-entrypoint.sh ./
|
COPY --chown=nextjs:nodejs docker-entrypoint.sh ./
|
||||||
|
|||||||
@@ -125,18 +125,15 @@ docker compose up -d
|
|||||||
|
|
||||||
The app will be available at [http://localhost:3000](http://localhost:3000).
|
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
|
```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)
|
# App + DB + Worker + Bot (also needs BOT_TOKEN in .env)
|
||||||
docker compose --profile full up -d
|
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
|
docker compose --profile bot up -d
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ services:
|
|||||||
retries: 5
|
retries: 5
|
||||||
|
|
||||||
worker:
|
worker:
|
||||||
profiles: ["telegram", "full"]
|
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: worker/Dockerfile
|
dockerfile: worker/Dockerfile
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ services:
|
|||||||
- frontend
|
- frontend
|
||||||
|
|
||||||
worker:
|
worker:
|
||||||
profiles: ["telegram", "full"]
|
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: worker/Dockerfile
|
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?
|
emailVerified DateTime?
|
||||||
image String?
|
image String?
|
||||||
hashedPassword String?
|
hashedPassword String?
|
||||||
role Role @default(USER)
|
role Role @default(ADMIN)
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
|
|
||||||
|
|||||||
@@ -21,12 +21,13 @@ export async function registerUser(input: unknown): Promise<ActionResult<{ id: s
|
|||||||
|
|
||||||
const hashedPassword = await bcrypt.hash(parsed.data.password, 10);
|
const hashedPassword = await bcrypt.hash(parsed.data.password, 10);
|
||||||
|
|
||||||
|
// Self-hosted: all users are admins
|
||||||
const user = await prisma.user.create({
|
const user = await prisma.user.create({
|
||||||
data: {
|
data: {
|
||||||
name: parsed.data.name,
|
name: parsed.data.name,
|
||||||
email: parsed.data.email,
|
email: parsed.data.email,
|
||||||
hashedPassword,
|
hashedPassword,
|
||||||
role: "USER",
|
role: "ADMIN",
|
||||||
settings: {
|
settings: {
|
||||||
create: {
|
create: {
|
||||||
lowStockThreshold: 10,
|
lowStockThreshold: 10,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { usePathname } from "next/navigation";
|
import { usePathname } from "next/navigation";
|
||||||
|
import { useSession } from "next-auth/react";
|
||||||
import {
|
import {
|
||||||
LayoutDashboard,
|
LayoutDashboard,
|
||||||
Cylinder,
|
Cylinder,
|
||||||
@@ -17,27 +18,17 @@ import {
|
|||||||
Flame,
|
Flame,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { APP_NAME } from "@/lib/constants";
|
import { APP_NAME, NAV_ITEMS } from "@/lib/constants";
|
||||||
import { SheetHeader, SheetTitle } from "@/components/ui/sheet";
|
import { SheetHeader, SheetTitle } from "@/components/ui/sheet";
|
||||||
|
|
||||||
const icons = { LayoutDashboard, Cylinder, Droplets, Paintbrush, Gem, FileBox, Send, ClipboardList, Building2, MapPin, Settings };
|
const icons = { LayoutDashboard, Cylinder, Droplets, Paintbrush, Gem, FileBox, Send, ClipboardList, Building2, MapPin, Settings };
|
||||||
|
|
||||||
const navItems = [
|
|
||||||
{ label: "Dashboard", href: "/dashboard", icon: "LayoutDashboard" as const },
|
|
||||||
{ label: "Filaments", href: "/filaments", icon: "Cylinder" as const },
|
|
||||||
{ label: "Resins", href: "/resins", icon: "Droplets" as const },
|
|
||||||
{ label: "Paints", href: "/paints", icon: "Paintbrush" as const },
|
|
||||||
{ label: "Supplies", href: "/supplies", icon: "Gem" as const },
|
|
||||||
{ label: "STL Files", href: "/stls", icon: "FileBox" as const },
|
|
||||||
{ label: "Telegram", href: "/telegram", icon: "Send" as const },
|
|
||||||
{ label: "Usage", href: "/usage", icon: "ClipboardList" as const },
|
|
||||||
{ label: "Vendors", href: "/vendors", icon: "Building2" as const },
|
|
||||||
{ label: "Locations", href: "/locations", icon: "MapPin" as const },
|
|
||||||
{ label: "Settings", href: "/settings", icon: "Settings" as const },
|
|
||||||
];
|
|
||||||
|
|
||||||
export function MobileSidebar() {
|
export function MobileSidebar() {
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
|
const { data: session } = useSession();
|
||||||
|
const isAdmin = session?.user?.role === "ADMIN";
|
||||||
|
|
||||||
|
const visibleItems = NAV_ITEMS.filter((item) => !item.adminOnly || isAdmin);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-full flex-col">
|
<div className="flex h-full flex-col">
|
||||||
@@ -48,7 +39,7 @@ export function MobileSidebar() {
|
|||||||
</SheetTitle>
|
</SheetTitle>
|
||||||
</SheetHeader>
|
</SheetHeader>
|
||||||
<nav className="flex-1 space-y-1 p-2">
|
<nav className="flex-1 space-y-1 p-2">
|
||||||
{navItems.map((item) => {
|
{visibleItems.map((item) => {
|
||||||
const Icon = icons[item.icon];
|
const Icon = icons[item.icon];
|
||||||
const isActive = pathname.startsWith(item.href);
|
const isActive = pathname.startsWith(item.href);
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { usePathname } from "next/navigation";
|
import { usePathname } from "next/navigation";
|
||||||
|
import { useSession } from "next-auth/react";
|
||||||
import {
|
import {
|
||||||
LayoutDashboard,
|
LayoutDashboard,
|
||||||
Cylinder,
|
Cylinder,
|
||||||
@@ -20,7 +21,7 @@ import {
|
|||||||
PanelLeft,
|
PanelLeft,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { APP_NAME } from "@/lib/constants";
|
import { APP_NAME, NAV_ITEMS } from "@/lib/constants";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
||||||
|
|
||||||
@@ -38,23 +39,13 @@ const icons = {
|
|||||||
Settings,
|
Settings,
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
const navItems = [
|
|
||||||
{ label: "Dashboard", href: "/dashboard", icon: "LayoutDashboard" as const },
|
|
||||||
{ label: "Filaments", href: "/filaments", icon: "Cylinder" as const },
|
|
||||||
{ label: "Resins", href: "/resins", icon: "Droplets" as const },
|
|
||||||
{ label: "Paints", href: "/paints", icon: "Paintbrush" as const },
|
|
||||||
{ label: "Supplies", href: "/supplies", icon: "Gem" as const },
|
|
||||||
{ label: "STL Files", href: "/stls", icon: "FileBox" as const },
|
|
||||||
{ label: "Telegram", href: "/telegram", icon: "Send" as const },
|
|
||||||
{ label: "Usage", href: "/usage", icon: "ClipboardList" as const },
|
|
||||||
{ label: "Vendors", href: "/vendors", icon: "Building2" as const },
|
|
||||||
{ label: "Locations", href: "/locations", icon: "MapPin" as const },
|
|
||||||
{ label: "Settings", href: "/settings", icon: "Settings" as const },
|
|
||||||
];
|
|
||||||
|
|
||||||
export function Sidebar() {
|
export function Sidebar() {
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const [collapsed, setCollapsed] = useState(false);
|
const [collapsed, setCollapsed] = useState(false);
|
||||||
|
const { data: session } = useSession();
|
||||||
|
const isAdmin = session?.user?.role === "ADMIN";
|
||||||
|
|
||||||
|
const visibleItems = NAV_ITEMS.filter((item) => !item.adminOnly || isAdmin);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<aside
|
<aside
|
||||||
@@ -73,7 +64,7 @@ export function Sidebar() {
|
|||||||
|
|
||||||
{/* Navigation */}
|
{/* Navigation */}
|
||||||
<nav className="flex-1 space-y-1 p-2">
|
<nav className="flex-1 space-y-1 p-2">
|
||||||
{navItems.map((item) => {
|
{visibleItems.map((item) => {
|
||||||
const Icon = icons[item.icon];
|
const Icon = icons[item.icon];
|
||||||
const isActive = pathname.startsWith(item.href);
|
const isActive = pathname.startsWith(item.href);
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,12 @@ export const { auth, handlers, signIn, signOut } = NextAuth({
|
|||||||
async jwt({ token, user }) {
|
async jwt({ token, user }) {
|
||||||
if (user) {
|
if (user) {
|
||||||
token.id = user.id!;
|
token.id = user.id!;
|
||||||
token.role = user.role ?? "USER";
|
// 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 ?? "ADMIN";
|
||||||
}
|
}
|
||||||
return token;
|
return token;
|
||||||
},
|
},
|
||||||
@@ -33,6 +38,12 @@ export const { auth, handlers, signIn, signOut } = NextAuth({
|
|||||||
events: {
|
events: {
|
||||||
async createUser({ user }) {
|
async createUser({ user }) {
|
||||||
if (user.id) {
|
if (user.id) {
|
||||||
|
// Self-hosted: all users are admins
|
||||||
|
await prisma.user.update({
|
||||||
|
where: { id: user.id },
|
||||||
|
data: { role: "ADMIN" },
|
||||||
|
});
|
||||||
|
|
||||||
await prisma.userSettings.upsert({
|
await prisma.userSettings.upsert({
|
||||||
where: { userId: user.id },
|
where: { userId: user.id },
|
||||||
update: {},
|
update: {},
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
export const APP_NAME = "Dragon's Stash";
|
export const APP_NAME = "Dragon's Stash";
|
||||||
|
|
||||||
export const NAV_ITEMS = [
|
export const NAV_ITEMS = [
|
||||||
{ label: "Dashboard", href: "/dashboard", icon: "LayoutDashboard" },
|
{ label: "Dashboard", href: "/dashboard", icon: "LayoutDashboard", adminOnly: false },
|
||||||
{ label: "Filaments", href: "/filaments", icon: "Cylinder" },
|
{ label: "Filaments", href: "/filaments", icon: "Cylinder", adminOnly: false },
|
||||||
{ label: "Resins", href: "/resins", icon: "Droplets" },
|
{ label: "Resins", href: "/resins", icon: "Droplets", adminOnly: false },
|
||||||
{ label: "Paints", href: "/paints", icon: "Paintbrush" },
|
{ label: "Paints", href: "/paints", icon: "Paintbrush", adminOnly: false },
|
||||||
{ label: "Supplies", href: "/supplies", icon: "Gem" },
|
{ label: "Supplies", href: "/supplies", icon: "Gem", adminOnly: false },
|
||||||
{ label: "STL Files", href: "/stls", icon: "FileBox" },
|
{ label: "STL Files", href: "/stls", icon: "FileBox", adminOnly: false },
|
||||||
{ label: "Telegram", href: "/telegram", icon: "Send" },
|
{ label: "Telegram", href: "/telegram", icon: "Send", adminOnly: true },
|
||||||
{ label: "Usage", href: "/usage", icon: "ClipboardList" },
|
{ label: "Usage", href: "/usage", icon: "ClipboardList", adminOnly: false },
|
||||||
{ label: "Vendors", href: "/vendors", icon: "Building2" },
|
{ label: "Vendors", href: "/vendors", icon: "Building2", adminOnly: false },
|
||||||
{ label: "Locations", href: "/locations", icon: "MapPin" },
|
{ label: "Locations", href: "/locations", icon: "MapPin", adminOnly: false },
|
||||||
{ label: "Settings", href: "/settings", icon: "Settings" },
|
{ label: "Settings", href: "/settings", icon: "Settings", adminOnly: false },
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
export const MATERIALS = [
|
export const MATERIALS = [
|
||||||
|
|||||||
Reference in New Issue
Block a user