added env variables

This commit is contained in:
ZareMate 2025-04-14 12:23:16 +02:00
parent af4d2e9e59
commit 41132eee61
Signed by: zaremate
GPG Key ID: 369A0E45E03A81C3
3 changed files with 13 additions and 5 deletions

View File

@ -22,3 +22,10 @@ AUTH_DISCORD_SECRET=""
# Prisma # Prisma
# https://www.prisma.io/docs/reference/database-reference/connection-urls#env # https://www.prisma.io/docs/reference/database-reference/connection-urls#env
DATABASE_URL="mysql://root:password@localhost:3306/file-hosting" DATABASE_URL="mysql://root:password@localhost:3306/file-hosting"
# Next Auth OAUTH Redirect URL
NEXTAUTH_URL=""
# Page base URL
NEXT_PUBLIC_PAGE_URL=""

View File

@ -7,7 +7,6 @@ import { useEffect, useState } from "react";
import toast from "react-hot-toast"; import toast from "react-hot-toast";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
import { env } from "~/env.js"; import { env } from "~/env.js";
interface File { interface File {
id: string; id: string;
name: string; name: string;
@ -22,6 +21,7 @@ export default function FileGrid({ session }: FileGridProps) {
const [files, setFiles] = useState<File[]>([]); const [files, setFiles] = useState<File[]>([]);
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
const router = useRouter(); const router = useRouter();
const pageUrl = env.NEXT_PUBLIC_PAGE_URL; // Assuming PAGE_URL is defined in your environment variables
const fetchFiles = async () => { const fetchFiles = async () => {
try { try {
@ -98,7 +98,7 @@ export default function FileGrid({ session }: FileGridProps) {
const handleCopyUrl = (url: string) => { const handleCopyUrl = (url: string) => {
navigator.clipboard navigator.clipboard
.writeText(env.PAGE_URL + url) .writeText(pageUrl + url)
.then(() => toast.success("File URL copied to clipboard!")) .then(() => toast.success("File URL copied to clipboard!"))
.catch(() => toast.error("Failed to copy URL.")); .catch(() => toast.error("Failed to copy URL."));
}; };
@ -137,7 +137,7 @@ export default function FileGrid({ session }: FileGridProps) {
className="flex max-w-xs flex-col gap-4 rounded-xl bg-white/10 p-4 hover:bg-white/20" className="flex max-w-xs flex-col gap-4 rounded-xl bg-white/10 p-4 hover:bg-white/20"
> >
<button onClick={() => router.push(env.PAGE_URL + file.url)}> <button onClick={() => router.push(env.NEXT_PUBLIC_PAGE_URL + file.url)}>
<h3 className="text-2xl font-bold">{file.name}</h3> <h3 className="text-2xl font-bold">{file.name}</h3>
</button> </button>
<div className="flex gap-2"> <div className="flex gap-2">

View File

@ -19,7 +19,7 @@ export const env = createEnv({
NODE_ENV: z NODE_ENV: z
.enum(["development", "test", "production"]) .enum(["development", "test", "production"])
.default("development"), .default("development"),
PAGE_URL: z.string().url(),
}, },
/** /**
@ -29,6 +29,7 @@ export const env = createEnv({
*/ */
client: { client: {
// NEXT_PUBLIC_CLIENTVAR: z.string(), // NEXT_PUBLIC_CLIENTVAR: z.string(),
NEXT_PUBLIC_PAGE_URL: z.string().url(),
}, },
/** /**
@ -41,7 +42,7 @@ export const env = createEnv({
AUTH_DISCORD_SECRET: process.env.AUTH_DISCORD_SECRET, AUTH_DISCORD_SECRET: process.env.AUTH_DISCORD_SECRET,
DATABASE_URL: process.env.DATABASE_URL, DATABASE_URL: process.env.DATABASE_URL,
NODE_ENV: process.env.NODE_ENV, NODE_ENV: process.env.NODE_ENV,
PAGE_URL: process.env.PAGE_URL, NEXT_PUBLIC_PAGE_URL: process.env.NEXT_PUBLIC_PAGE_URL,
}, },
/** /**
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially * Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially