Skip to content

Commit

Permalink
Fix Svix
Browse files Browse the repository at this point in the history
  • Loading branch information
N2D4 committed Feb 7, 2025
1 parent 927aea8 commit 79178ee
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 43 deletions.
4 changes: 2 additions & 2 deletions apps/backend/src/app/api/latest/webhooks/svix-token/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const appPortalCrudHandlers = createLazyProxy(() => createCrudHandlers(svixToken
paramsSchema: yupObject({}),
onCreate: async ({ auth }) => {
const svix = getSvixClient();
await svix.application.getOrCreate({ uid: auth.project.id, name: auth.tenancy.id });
const result = await svix.authentication.appPortalAccess(auth.tenancy.id, {});
await svix.application.getOrCreate({ uid: auth.project.id, name: auth.project.id });
const result = await svix.authentication.appPortalAccess(auth.project.id, {});
return { token: result.token };
},
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { SettingCard } from "@/components/settings";
import { urlSchema } from "@stackframe/stack-shared/dist/schema-fields";
import { ActionCell, ActionDialog, Alert, Button, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, Typography } from "@stackframe/stack-ui";
import { useRouter } from "next/navigation";
import { useMemo, useState } from "react";
import { useState } from "react";
import { SvixProvider, useEndpoints, useSvix } from "svix-react";
import * as yup from "yup";
import { PageLayout } from "../page-layout";
Expand Down Expand Up @@ -134,63 +134,55 @@ function Endpoints(props: { updateFn: () => void }) {
let content = null;

if (!endpoints.loaded) {
content = endpoints.rendered;
return endpoints.rendered;
} else {
content = (
<div className="border rounded-md">
<Table>
<TableHeader>
<TableRow>
<TableHead className="w-[600px]">Endpoint URL</TableHead>
<TableHead className="w-[300px]">Description</TableHead>
<TableHead></TableHead>
</TableRow>
</TableHeader>
<TableBody>
{endpoints.data.map(endpoint => (
<TableRow key={endpoint.id}>
<TableCell>{endpoint.url}</TableCell>
<TableCell>{endpoint.description}</TableCell>
<TableCell className="flex justify-end gap-4">
<ActionMenu endpoint={endpoint} updateFn={props.updateFn} />
</TableCell>
return (
<SettingCard
title="Endpoints"
description="Endpoints are the URLs that we will send events to. Please make sure you control these endpoints, as they can receive sensitive data."
actions={<CreateDialog trigger={<Button>Add new endpoint</Button>} updateFn={props.updateFn}/>}
>
<div className="border rounded-md">
<Table>
<TableHeader>
<TableRow>
<TableHead className="w-[600px]">Endpoint URL</TableHead>
<TableHead className="w-[300px]">Description</TableHead>
<TableHead></TableHead>
</TableRow>
))}
</TableBody>
</Table>
</div>
</TableHeader>
<TableBody>
{endpoints.data.map(endpoint => (
<TableRow key={endpoint.id}>
<TableCell>{endpoint.url}</TableCell>
<TableCell>{endpoint.description}</TableCell>
<TableCell className="flex justify-end gap-4">
<ActionMenu endpoint={endpoint} updateFn={props.updateFn} />
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</div>
</SettingCard>
);
}

return (
<SettingCard
title="Endpoints"
description="Endpoints are the URLs that we will send events to. Please make sure you control these endpoints, as they can receive sensitive data."
actions={<CreateDialog trigger={<Button>Add new endpoint</Button>} updateFn={props.updateFn}/>}
>
{content}
</SettingCard>
);
}

export default function PageClient() {
const stackAdminApp = useAdminApp();
const svixToken = stackAdminApp.useSvixToken();
const [updateCounter, setUpdateCounter] = useState(0);

// This is a hack to make sure svix hooks update when content changes
const svixTokenUpdated = useMemo(() => {
return svixToken + '';
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [svixToken, updateCounter]);
console.log(svixToken, stackAdminApp.projectId);

return (
<PageLayout
title="Webhooks"
description="Webhooks are used to sync users and teams events from Stack to your own server."
>
<SvixProvider
token={svixTokenUpdated}
key={updateCounter}
token={svixToken}
appId={stackAdminApp.projectId}
options={{ serverUrl: process.env.NEXT_PUBLIC_STACK_SVIX_SERVER_URL }}
>
Expand Down

0 comments on commit 79178ee

Please sign in to comment.