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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ cp .env.example .env.local
2. Create [Stripe](https://stripe.com) Account
3. Create [Google Console](https://console.cloud.google.com/) Account
4. Create [Resend](https://resend.com/) Account
5. Create [Unkey](https://unkey.com) Account

5. Start the development server from either yarn or turbo:

Expand Down Expand Up @@ -107,6 +108,7 @@ pnpm run deploy
- [Vercel](https://vercel.com/) – Easily preview & deploy changes with git
- [PlanetScale](https://planetscale.com/) – A cutting-edge database platform for seamless, scalable data management
- [Resend](https://resend.com/) – A powerful email framework for streamlined email development
- [Unkey](https://unkey.dev) – API key management for developers

## Contributing

Expand Down
1 change: 1 addition & 0 deletions apps/www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@t3-oss/env-nextjs": "^0.9.2",
"@tanstack/react-table": "^8.10.7",
"@typescript-eslint/parser": "^6.9.0",
"@unkey/api": "^0.20.2",
"@vercel/analytics": "^1.1.1",
"@vercel/og": "^0.5.20",
"axios": "^1.6.7",
Expand Down
33 changes: 32 additions & 1 deletion apps/www/src/actions/generate-api-key.ts
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got some errors for this component:

Screenshot 2024-05-16

It looks like it has something to do with this this
Screenshot 2024-05-16

Could you look into it?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Codehagen, I've resolved the type errors here by changing the error handling in the file

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure why those weren't showing for me previously

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import { revalidatePath } from "next/cache";
import { createProjectAndChannel } from "@/actions/create-project-and-channel"; // Import the function

import { Unkey } from "@unkey/api";

import { prisma } from "@/lib/db";
import { getCurrentUser } from "@/lib/session";

Expand All @@ -13,12 +15,41 @@ export async function generateAndSaveApiKey() {
const user = await getCurrentUser();
const userId = user?.id;

if (!process.env.UNKEY_ROOT_KEY) {
console.error("UNKEY_ROOT_KEY environment variable is not set.");
return {
success: false,
error: "UNKEY_ROOT_KEY environment variable is not set.",
};
}

const unkey = new Unkey({ rootKey: process.env.UNKEY_ROOT_KEY });

if (!userId) {
console.error("No user is currently logged in.");
return { success: false, error: "User not authenticated" };
}

const apiKey = generateApiKey();
const { result } = await unkey.keys.create({
apiId: "api_3Sw97gepmEHFKTepgM5GaFxy8cWG",
prefix: "ding",
ownerId: userId,
ratelimit: {
type: "fast",
limit: 10,
refillRate: 1,
refillInterval: 1000,
},
enabled: true,
});

if (!result) {
console.error("Error creating API key.");
return { success: false, error: "Error creating API key." };
}

const apiKey = result.key;

console.log(`Generated API key for user ID: ${userId}. API Key: ${apiKey}`);

try {
Expand Down
2 changes: 2 additions & 0 deletions apps/www/src/app/(dashboard)/dashboard/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { redirect } from "next/navigation";

import { authOptions } from "@/lib/auth";
import { getCurrentUser } from "@/lib/session";
import { AddApiKeyButton } from "@/components/buttons/AddApiKeyButton";
import { DashboardHeader } from "@/components/dashboard/header";
import { DashboardShell } from "@/components/dashboard/shell";
import { LanguageForm2 } from "@/components/forms/language-form2";
Expand Down Expand Up @@ -30,6 +31,7 @@ export default async function SettingsPage() {
heading="Settings"
text="Manage account and website settings."
/>
<AddApiKeyButton />
<div className="grid gap-10">
<UserNameForm user={{ id: user.id, name: user.name || "" }} />
</div>
Expand Down
Loading