supabase-community / vercel-ai-chatbot

A full-featured, Supabaseified Next.js AI chatbot built by Vercel Labs & Supabase
https://github.com/thorwebdev/vercel-ai-chatbot/pull/1
Other
549 stars 83 forks source link

fix/preview_functionality #13

Open c42alyst opened 1 year ago

c42alyst commented 1 year ago

What kind of change does this PR introduce?

Fixes Preview functionality

https://github.com/vercel-labs/ai-chatbot/issues/101 https://github.com/vercel-labs/ai-chatbot/issues/116

What is the current behavior?

  1. Wrong environment variable being requested and read before VERCEL_ENV instead of NEXT_PUBLIC_VERCEL_ENV
  2. API route not using the set token
  3. Token Dialog mount currently causes hydration errors due to differences in server and client renders (radix-ui issue)

What is the new behavior?

  1. Updated .env.example to indicate usage of NEXT_PUBLIC_VERCEL_ENV
  2. Updated the chat component to use NEXT_PUBLIC_VERCEL_ENV instead of VERCEL_ENV
  3. Mount the dialog in useEffect to avoid Nextjs hydration errors
  4. On component Unmount reset the token in localstorage
  5. Updated the chat route to use the preview token passed in the request body

New the preview functionality works by using a user provided Open AI API Key stored to localstorage and reset on exiting the page.

Additional context

Also added encoding library to avoid errors related to fetch “Module not found: Can't resolve encoding”

vercel[bot] commented 1 year ago

@c42alyst is attempting to deploy a commit to the Supabase Team on Vercel.

A member of the Team first needs to authorize it.