Skip to content

Commit

Permalink
Try adding suspense and fixing type issues
Browse files Browse the repository at this point in the history
  • Loading branch information
aamirazad committed Oct 26, 2024
1 parent 1de425a commit 62c68d0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/app/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function setUserProperty<K extends keyof UsersTableType>(
propertyName: K,
value: UsersTableType[K],
) {
const { userId } = auth();
const { userId } = await auth();

if (!userId) {
return null;
Expand All @@ -37,7 +37,7 @@ export async function setUserProperty<K extends keyof UsersTableType>(
}

export async function getUserData() {
const { userId } = auth();
const { userId } = await auth();

if (!userId) return null;

Expand Down
2 changes: 1 addition & 1 deletion src/app/api/getUserData/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { db } from "@/server/db";
import { auth } from "@clerk/nextjs/server";

export async function GET() {
const { userId } = auth();
const { userId } = await auth();

if (!userId) return new Response(`Unauthorized`, { status: 401 });

Expand Down
33 changes: 18 additions & 15 deletions src/app/sign-in/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,29 @@ import OpenInternalLink from "@/components/internal-link";
import LoadingSpinner from "@/components/loading-spinner";
import { RedirectToSignIn, SignedIn, SignedOut } from "@clerk/nextjs";
import { useSearchParams } from "next/navigation";
import { Suspense } from "react";

export default function SignIn() {
const searchParams = useSearchParams();
const redirect = searchParams.get("redirect");

return (
<main className="text-xl">
<SignedOut>
<LoadingSpinner>Signing you in...</LoadingSpinner>
<RedirectToSignIn signInForceRedirectUrl={redirect} />
</SignedOut>
<SignedIn>
You are already signed in
<div className="mt-8">
Go{" "}
<OpenInternalLink href="/" className="text-primary">
Home
</OpenInternalLink>
</div>
</SignedIn>
</main>
<Suspense>
<main className="text-xl">
<SignedOut>
<LoadingSpinner>Signing you in...</LoadingSpinner>
<RedirectToSignIn signInForceRedirectUrl={redirect} />
</SignedOut>
<SignedIn>
You are already signed in
<div className="mt-8">
Go{" "}
<OpenInternalLink href="/" className="text-primary">
Home
</OpenInternalLink>
</div>
</SignedIn>
</main>
</Suspense>
);
}

0 comments on commit 62c68d0

Please sign in to comment.