Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/actions/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { Duration, ms } from '@/lib/duration'
import { Sandbox } from '@e2b/code-interpreter'
import { kv } from '@vercel/kv'
import { getKv } from '@/lib/kv'
import { customAlphabet } from 'nanoid'

const nanoid = customAlphabet('1234567890abcdef', 7)
Expand Down Expand Up @@ -37,7 +37,7 @@ export async function publish(

if (process.env.KV_REST_API_URL && process.env.KV_REST_API_TOKEN) {
const id = nanoid()
await kv.set(`fragment:${id}`, url, { px: expiration })
await getKv().set(`fragment:${id}`, url, { px: expiration })

return {
url: process.env.NEXT_PUBLIC_SITE_URL
Expand Down
3 changes: 1 addition & 2 deletions app/providers.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use client'

import { ThemeProvider as NextThemesProvider } from 'next-themes'
import { type ThemeProviderProps } from 'next-themes/dist/types'
import { ThemeProvider as NextThemesProvider, type ThemeProviderProps } from 'next-themes'
import posthog from 'posthog-js'
import { PostHogProvider as PostHogProviderJS } from 'posthog-js/react'

Expand Down
2 changes: 1 addition & 1 deletion components/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ function Auth({
magicLink = false,
onSignUpValidate,
metadata,
}: AuthProps): JSX.Element | null {
}: AuthProps): React.JSX.Element | null {
const [authView, setAuthView] = useState<ViewType>(view)
const {
loading,
Expand Down
15 changes: 15 additions & 0 deletions lib/kv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Redis } from '@upstash/redis'

// Replaces the deprecated @vercel/kv client. Reads the same KV_REST_API_URL /
// KV_REST_API_TOKEN variables, and is only created when both are set.
let client: Redis | undefined

export function getKv(): Redis {
if (!client) {
client = new Redis({
url: process.env.KV_REST_API_URL!,
token: process.env.KV_REST_API_TOKEN!,
})
}
return client
}
4 changes: 2 additions & 2 deletions lib/ratelimit.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Duration } from './duration'
import { Ratelimit } from '@upstash/ratelimit'
import { kv } from '@vercel/kv'
import { getKv } from '@/lib/kv'

export default async function ratelimit(
key: string | null,
Expand All @@ -9,7 +9,7 @@ export default async function ratelimit(
) {
if (process.env.KV_REST_API_URL && process.env.KV_REST_API_TOKEN) {
const ratelimit = new Ratelimit({
redis: kv,
redis: getKv(),
limiter: Ratelimit.slidingWindow(maxRequests, window),
})

Expand Down
4 changes: 2 additions & 2 deletions middleware.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { kv } from '@vercel/kv'
import { getKv } from '@/lib/kv'
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'

export async function middleware(req: NextRequest) {
if (process.env.KV_REST_API_URL && process.env.KV_REST_API_TOKEN) {
const id = req.nextUrl.pathname.split('/').pop()
const url = await kv.get(`fragment:${id}`)
const url = await getKv().get(`fragment:${id}`)

if (url) {
return NextResponse.redirect(url as string)
Expand Down
Loading