| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- import { SimpleCodeBlock } from 'ui-patterns/SimpleCodeBlock'
- import type { ContentFileProps } from '@/components/interfaces/Connect/Connect.types'
- import {
- ConnectTabContent,
- ConnectTabs,
- ConnectTabTrigger,
- ConnectTabTriggers,
- } from '@/components/interfaces/Connect/ConnectTabs'
- const ContentFile = ({ projectKeys }: ContentFileProps) => {
- return (
- <ConnectTabs>
- <ConnectTabTriggers>
- <ConnectTabTrigger value=".env" />
- <ConnectTabTrigger value="app/utils/briven.server.ts" />
- <ConnectTabTrigger value="app/routes/_index.tsx" />
- </ConnectTabTriggers>
- <ConnectTabContent value=".env">
- <SimpleCodeBlock className="bash" parentClassName="min-h-72">
- {[
- '',
- `VITE_BRIVEN_URL=${projectKeys.apiUrl ?? 'your-project-url'}`,
- projectKeys?.publishableKey
- ? `VITE_BRIVEN_PUBLISHABLE_KEY=${projectKeys.publishableKey}`
- : `VITE_BRIVEN_ANON_KEY=${projectKeys.anonKey ?? 'your-anon-key'}`,
- '',
- ].join('\n')}
- </SimpleCodeBlock>
- </ConnectTabContent>
- <ConnectTabContent value="app/utils/briven.server.ts">
- <SimpleCodeBlock className="ts" parentClassName="min-h-72">
- {`
- import {
- createServerClient,
- parseCookieHeader,
- serializeCookieHeader,
- } from "@supabase/ssr";
- export function createClient(request: Request) {
- const headers = new Headers();
- const briven = createServerClient(
- process.env.VITE_BRIVEN_URL!,
- process.env.VITE_${projectKeys.publishableKey ? 'BRIVEN_PUBLISHABLE_KEY' : 'BRIVEN_ANON_KEY'};,
- {
- cookies: {
- getAll() {
- return parseCookieHeader(request.headers.get("Cookie") ?? "") as {
- name: string;
- value: string;
- }[];
- },
- setAll(cookiesToSet) {
- cookiesToSet.forEach(({ name, value, options }) =>
- headers.append(
- "Set-Cookie",
- serializeCookieHeader(name, value, options)
- )
- );
- },
- },
- }
- );
- return { briven, headers };
- }
- `}
- </SimpleCodeBlock>
- </ConnectTabContent>
- <ConnectTabContent value="app/routes/_index.tsx">
- <SimpleCodeBlock className="tsx" parentClassName="min-h-72">
- {`
- import type { Route } from "./+types/home";
- import { createClient } from "~/utils/briven.server";
- export async function loader({ request }: Route.LoaderArgs) {
- const { briven } = createClient(request);
- const { data: todos } = await briven.from("todos").select();
- return { todos };
- }
- export default function Home({ loaderData }: Route.ComponentProps) {
- return (
- <>
- <ul>
- {loaderData.todos?.map((todo) => (
- <li key={todo.id}>{todo.name}</li>
- ))}
- </ul>
- </>
- );
- }
- `}
- </SimpleCodeBlock>
- </ConnectTabContent>
- </ConnectTabs>
- )
- }
- export default ContentFile
|