Skip to content

UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.

🐛 fix: fix critical auth bugs and landing lint

Dillion Verma19ec3b43b05a
diff --git a/app/(marketing)/page.tsx b/app/(marketing)/page.tsx
index e7ee042c..dd9ca6cd 100644
--- a/app/(marketing)/page.tsx
+++ b/app/(marketing)/page.tsx
@@ -30,7 +30,7 @@ const tweetUrls = [
"https://twitter.com/beneverman/status/1681477151042797568",
].map((t) => t.split("/").slice(-1)[0]);
-export async function getTweets() {
+async function getTweets() {
try {
const tweets = await Promise.all(
tweetUrls.map(async (id) => {
diff --git a/app/api/me/route.ts b/app/api/me/route.ts
new file mode 100644
index 00000000..8724f399
--- /dev/null
+++ b/app/api/me/route.ts
@@ -0,0 +1,43 @@
+import { authOptions } from "@/lib/auth";
+import { db } from "@/lib/db";
+import { getServerSession } from "next-auth";
+import { z } from "zod";
+
+export async function GET() {
+ try {
+ const session = await getServerSession(authOptions);
+
+ if (!session?.user) {
+ return new Response(null, { status: 403 });
+ }
+
+ const user = await db.user.findUnique({
+ where: {
+ id: session.user.id,
+ },
+ include: {
+ customer: {
+ include: {
+ payments: true,
+ },
+ },
+ },
+ });
+
+ if (!user) {
+ return new Response(JSON.stringify({ error: "User not found." }), {
+ status: 404,
+ });
+ }
+
+ return new Response(JSON.stringify({ user }), {
+ status: 200,
+ });
+ } catch (error) {
+ if (error instanceof z.ZodError) {
+ return new Response(JSON.stringify(error.issues), { status: 422 });
+ }
+
+ return new Response(null, { status: 500 });
+ }
+}
diff --git a/components/component-source.tsx b/components/component-source.tsx
index 17a48743..f2741ef7 100644
--- a/components/component-source.tsx
+++ b/components/component-source.tsx
@@ -2,9 +2,10 @@
import { CodeBlockWrapper } from "@/components/code-block-wrapper";
import PreOrder from "@/components/preorder";
-import { cn } from "@/lib/utils";
+import { cn, fetcher } from "@/lib/utils";
import { useSession } from "next-auth/react";
import * as React from "react";
+import useSWR from "swr";
interface ComponentSourceProps extends React.HTMLAttributes<HTMLDivElement> {
src: string;
@@ -16,10 +17,14 @@ export function ComponentSource({
...props
}: ComponentSourceProps) {
const { data: session, status } = useSession();
- const user = session?.user;
+ const { data, isLoading } = useSWR("/api/me", fetcher);
if (status === "loading") return null;
if (status === "unauthenticated") return <PreOrder />;
+ if (isLoading) return null;
+
+ // TODO: Make this cleaner
+ if (data?.user?.customer.payments.length === 0) return <PreOrder />;
return (
<CodeBlockWrapper
diff --git a/lib/utils.ts b/lib/utils.ts
index 3afbf4dd..9abdf359 100644
--- a/lib/utils.ts
+++ b/lib/utils.ts
@@ -12,6 +12,9 @@ export const truncate = (str: string | null, length: number) => {
return `${str.slice(0, length - 3)}...`;
};
+export const fetcher = (...args: Parameters<typeof fetch>) =>
+ fetch(...args).then((res) => res.json());
+
/**
* Capitalizes first letters of words in string.
* @param {string} str String to be modified
diff --git a/package.json b/package.json
index 267c27a0..31129487 100644
--- a/package.json
+++ b/package.json
@@ -76,6 +76,7 @@
"resend": "^0.16.0",
"schema-dts": "^1.1.2",
"stripe": "^12.10.0",
+ "swr": "^2.2.0",
"tailwind-merge": "^1.13.2",
"zod": "^3.21.4"
},
diff --git a/registry/components/magicui/tweet-card.tsx b/registry/components/magicui/tweet-card.tsx
index 3adf9a59..6869a389 100644
--- a/registry/components/magicui/tweet-card.tsx
+++ b/registry/components/magicui/tweet-card.tsx
@@ -164,7 +164,13 @@ export const TweetCard = ({
return <MyTweet tweet={data} components={components} {...props} />;
};
-export const ServerTweetCard = ({ tweet, ...props }) => {
+export const ServerTweetCard = ({
+ tweet,
+ ...props
+}: {
+ tweet: any;
+ [key: string]: any;
+}) => {
return <MyTweet tweet={tweet} {...props} />;
};