Merge pull request #272 from vietnamesekid/main

feat: integrate @t3-oss/env for environment variable management across the application
This commit is contained in:
Maze
2025-07-15 12:20:55 +02:00
committed by GitHub
16 changed files with 118 additions and 37 deletions
@@ -7,9 +7,10 @@ import { usePlaybackStore } from "@/stores/playback-store";
import { Button } from "@/components/ui/button";
import { useState } from "react";
import type { TimelineElement } from "@/types/timeline";
import { env } from "@/env";
// Only show in development
const SHOW_DEBUG_INFO = process.env.NODE_ENV === "development";
const SHOW_DEBUG_INFO = env.NODE_ENV === "development";
interface ActiveElement {
element: TimelineElement;
+2 -1
View File
@@ -8,6 +8,7 @@ import { useSession } from "@opencut/auth/client";
import { getStars } from "@/lib/fetch-github-stars";
import { useEffect, useState } from "react";
import Image from "next/image";
import { env } from "@/env";
export function Header() {
const { data: session } = useSession();
@@ -40,7 +41,7 @@ export function Header() {
Contributors
</Button>
</Link>
{process.env.NODE_ENV === "development" ? (
{env.NODE_ENV === "development" ? (
<Link href="/projects">
<Button size="sm" className="text-sm ml-4">
Projects
+27
View File
@@ -0,0 +1,27 @@
import { vercel } from "@t3-oss/env-core/presets-zod";
import { createEnv } from "@t3-oss/env-nextjs";
import { z } from "zod";
import { keys as auth } from "@opencut/auth/keys";
import { keys as db } from "@opencut/db/keys";
export const env = createEnv({
extends: [vercel(), auth(), db()],
server: {
ANALYZE: z.string().optional(),
// Added by Vercel
NEXT_RUNTIME: z.enum(["nodejs", "edge"]).optional(),
NODE_ENV: z
.enum(["development", "production", "test"])
.default("development"),
UPSTASH_REDIS_REST_URL: z.string().url(),
UPSTASH_REDIS_REST_TOKEN: z.string(),
},
client: {},
runtimeEnv: {
ANALYZE: process.env.ANALYZE,
NEXT_RUNTIME: process.env.NEXT_RUNTIME,
NODE_ENV: process.env.NODE_ENV,
UPSTASH_REDIS_REST_URL: process.env.UPSTASH_REDIS_REST_URL,
UPSTASH_REDIS_REST_TOKEN: process.env.UPSTASH_REDIS_REST_TOKEN,
},
});
+3 -2
View File
@@ -1,10 +1,11 @@
// lib/rate-limit.ts
import { Ratelimit } from "@upstash/ratelimit";
import { Redis } from "@upstash/redis";
import { env } from "@/env";
const redis = new Redis({
url: process.env.UPSTASH_REDIS_REST_URL!,
token: process.env.UPSTASH_REDIS_REST_TOKEN!,
url: env.UPSTASH_REDIS_REST_URL,
token: env.UPSTASH_REDIS_REST_TOKEN,
});
export const waitlistRateLimit = new Ratelimit({
+2 -1
View File
@@ -1,5 +1,6 @@
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
import { env } from "./env";
export async function middleware(request: NextRequest) {
// Handle fuckcapcut.com domain redirect
@@ -9,7 +10,7 @@ export async function middleware(request: NextRequest) {
const path = request.nextUrl.pathname;
if (path === "/editor" && process.env.NODE_ENV === "production") {
if (path === "/editor" && env.NODE_ENV === "production") {
const homeUrl = new URL("/", request.url);
homeUrl.searchParams.set("redirect", request.url);
return NextResponse.redirect(homeUrl);