Skip to content

Commit

Permalink
fix: route fix after user isSignnedIn (Codehagen#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbennycodes authored Mar 1, 2024
1 parent 1062141 commit 6b8892b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
6 changes: 3 additions & 3 deletions apps/www/app/(marketing)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Link from "next/link";
import { auth } from "@clerk/nextjs";
import Balancer from "react-wrap-balancer";

import { cn } from "@/lib/utils";
Expand All @@ -10,6 +11,7 @@ import Featuressection from "@/components/dashboard/feautressection";
import { Icons } from "@/components/shared/icons";

export default async function IndexPage() {
const { userId } = auth();
return (
<>
<section className="space-y-6 pb-12 pt-16 lg:py-28">
Expand Down Expand Up @@ -54,9 +56,7 @@ export default async function IndexPage() {
>
<GetStartedButton />
<Link
href="https://www.badget.io/"
target="_blank"
rel="noreferrer"
href={userId ? "/dashboard" : "/signin"}
className={cn(
buttonVariants({ variant: "outline", size: "lg" }),
"px-4",
Expand Down
17 changes: 14 additions & 3 deletions apps/www/components/buttons/GetStartedButton.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
"use client";

import { useRouter } from "next/navigation";
import { useAuth } from "@clerk/nextjs";

import { cn } from "@/lib/utils";
import { useSigninModal } from "@/hooks/use-signin-modal";
import { Button, buttonVariants } from "@/components/ui/button";

export function GetStartedButton() {
const signInModal = useSigninModal();
const router = useRouter();
const { isSignedIn } = useAuth();

const handleOnClick = () => {
if (isSignedIn) {
router.push("/dashboard");
} else {
router.push("/signin");
}
};

return (
<Button
className={cn(buttonVariants({ size: "lg" }))}
onClick={signInModal.onOpen}
onClick={handleOnClick}
>
Get started
</Button>
Expand Down
6 changes: 2 additions & 4 deletions apps/www/components/layout/user-account-nav.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import Link from "next/link";
import { useRouter } from "next/navigation";
import { SignedIn, SignedOut, SignInButton, useClerk } from "@clerk/nextjs";
import { useClerk } from "@clerk/nextjs";
import { CreditCard, LayoutDashboard, LogOut, Settings } from "lucide-react";

import { useSigninModal } from "@/hooks/use-signin-modal";
import { Button } from "@/components/ui/button";
import {
DropdownMenu,
Expand All @@ -27,7 +26,6 @@ interface UserAccountNavProps extends React.HTMLAttributes<HTMLDivElement> {
export function UserAccountNav({ user }: UserAccountNavProps) {
const { signOut } = useClerk();
const router = useRouter();
const signInModal = useSigninModal();

return user ? (
<DropdownMenu>
Expand Down Expand Up @@ -96,7 +94,7 @@ export function UserAccountNav({ user }: UserAccountNavProps) {
className="px-3"
variant="default"
size="sm"
onClick={signInModal.onOpen}
onClick={() => router.push("/signin")}
>
Sign In
</Button>
Expand Down

0 comments on commit 6b8892b

Please sign in to comment.