Skip to content

Commit

Permalink
Scaffold Knock integration
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenbleasel committed Nov 18, 2024
1 parent 33b28ad commit 639c504
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ jobs:
echo "ARCJET_KEY=ajkey_test" >> apps/app/.env.local
echo "SVIX_TOKEN=testsk_test" >> apps/app/.env.local
echo "LIVEBLOCKS_SECRET=sk_test" >> apps/app/.env.local
echo "KNOCK_API_KEY=test" >> apps/app/.env.local
echo "KNOCK_FEED_CHANNEL_ID=test" >> apps/app/.env.local
echo "NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_JA==" >> apps/app/.env.local
echo "NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in" >> apps/app/.env.local
Expand Down
4 changes: 3 additions & 1 deletion apps/app/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ FLAGS_SECRET=""
ARCJET_KEY=""
SVIX_TOKEN=""
LIVEBLOCKS_SECRET=""
KNOCK_API_KEY=""
KNOCK_FEED_CHANNEL_ID=""

# Client
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=""
Expand All @@ -26,4 +28,4 @@ NEXT_PUBLIC_POSTHOG_HOST=""
NEXT_PUBLIC_APP_URL="http://localhost:3000"
NEXT_PUBLIC_WEB_URL="http://localhost:3001"
NEXT_PUBLIC_DOCS_URL="http://localhost:3004"
NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL="http://localhost:3000"
NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL="http://localhost:3000"
27 changes: 15 additions & 12 deletions apps/app/app/(authenticated)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { auth, currentUser } from '@clerk/nextjs/server';
import { SidebarProvider } from '@repo/design-system/components/ui/sidebar';
import { NotificationsProvider } from '@repo/design-system/providers/notifications';
import { showBetaFeature } from '@repo/feature-flags';
import arcjet, { detectBot, request } from '@repo/security';
import type { ReactNode } from 'react';
Expand Down Expand Up @@ -38,21 +39,23 @@ const AppLayout = async ({ children }: AppLayoutProperties) => {
const betaFeature = await showBetaFeature();

if (!user) {
redirectToSignIn();
return redirectToSignIn();
}

return (
<SidebarProvider>
<GlobalSidebar>
{betaFeature && (
<div className="m-4 rounded-full bg-success p-1.5 text-center text-sm text-success-foreground">
Beta feature now available
</div>
)}
{children}
</GlobalSidebar>
<PostHogIdentifier />
</SidebarProvider>
<NotificationsProvider userId={user.id}>
<SidebarProvider>
<GlobalSidebar>
{betaFeature && (
<div className="m-4 rounded-full bg-success p-1.5 text-center text-sm text-success-foreground">
Beta feature now available
</div>
)}
{children}
</GlobalSidebar>
<PostHogIdentifier />
</SidebarProvider>
</NotificationsProvider>
);
};

Expand Down
9 changes: 9 additions & 0 deletions packages/design-system/lib/knock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Knock } from '@knocklabs/node';

const knockApiKey = process.env.KNOCK_API_KEY;

if (!knockApiKey) {
throw new Error('KNOCK_API_KEY is not set');
}

export const knock = new Knock(knockApiKey);
2 changes: 2 additions & 0 deletions packages/design-system/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"private": true,
"dependencies": {
"@hookform/resolvers": "^3.9.1",
"@knocklabs/node": "^0.6.13",
"@knocklabs/react": "^0.2.29",
"@radix-ui/react-accordion": "^1.2.1",
"@radix-ui/react-alert-dialog": "^1.1.2",
"@radix-ui/react-aspect-ratio": "^1.1.0",
Expand Down
24 changes: 24 additions & 0 deletions packages/design-system/providers/notifications.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { KnockFeedProvider, KnockProvider } from '@knocklabs/react';
import type { ReactNode } from 'react';

const knockApiKey = process.env.KNOCK_API_KEY;
const knockFeedChannelId = process.env.KNOCK_FEED_CHANNEL_ID;

if (!knockApiKey) {
throw new Error('KNOCK_API_KEY is not set');
}

if (!knockFeedChannelId) {
throw new Error('KNOCK_FEED_CHANNEL_ID is not set');
}

export const NotificationsProvider = ({
children,
userId,
}: { children: ReactNode; userId: string }) => (
<KnockProvider apiKey={knockApiKey} userId={userId}>
<KnockFeedProvider feedId={knockFeedChannelId}>
{children}
</KnockFeedProvider>
</KnockProvider>
);

0 comments on commit 639c504

Please sign in to comment.