Skip to content

Commit

Permalink
chores: add public routes in the middleware, add sign in and sign up …
Browse files Browse the repository at this point in the history
…links in popover when user is not logged in
  • Loading branch information
eduamdev committed Feb 27, 2024
1 parent 4f7043c commit a207c0a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
39 changes: 34 additions & 5 deletions app/components/site-header.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import Link from 'next/link';
import { UserButton, SignedIn, SignedOut } from '@clerk/nextjs';
import {
Popover,
PopoverContent,
PopoverTrigger,
} from '@/app/components/ui/popover';
import { Icons } from '@/app/components/icons';

export function SiteHeader() {
Expand All @@ -11,14 +16,38 @@ export function SiteHeader() {
<nav>
<SignedIn>
<div className="flex items-center justify-center">
<UserButton />
<Icons.menu className="mr-1.5 size-6 shrink-0" />
<div className="size-7 shrink-0">
<UserButton />
</div>
</div>
</SignedIn>
<SignedOut>
<div className="flex items-center justify-center text-neutral-800">
<Icons.menu className="mr-1.5 size-6 shrink-0" />
<Icons.user className="size-7 shrink-0" />
</div>
<Popover>
<PopoverTrigger>
<div className="flex items-center justify-center text-neutral-800">
<Icons.menu className="mr-1.5 size-6 shrink-0" />
<Icons.user className="size-7 shrink-0" />
</div>
</PopoverTrigger>
<PopoverContent
align="end"
collisionPadding={{ top: 40, right: 40 }}
sideOffset={8}
className="w-48 px-0 py-2.5 text-neutral-800 shadow-xl"
>
<ul className="flex flex-col gap-0.5 text-sm">
<Link href={'/sign-up'}>
<li className="py-2 pl-4 font-semibold hover:bg-neutral-100">
Sign up
</li>
</Link>
<Link href={'/sign-in'}>
<li className="py-2 pl-4 hover:bg-neutral-100">Sign in</li>
</Link>
</ul>
</PopoverContent>
</Popover>
</SignedOut>
</nav>
</header>
Expand Down
6 changes: 6 additions & 0 deletions app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,9 @@
}
}
}

/* Clerk styles */
.cl-userButtonAvatarBox {
height: 28px;
width: 28px;
}
4 changes: 2 additions & 2 deletions middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { authMiddleware } from '@clerk/nextjs';

export default authMiddleware({
// Routes that can be accessed while signed out
publicRoutes: ['/'],
publicRoutes: ['/', '/cars', '/car/:path', '/reservation'],
// Routes that can always be accessed, and have
// no authentication information
ignoredRoutes: ['/sign-in', '/sign-up'],
ignoredRoutes: ['/sign-up', '/sign-in'],
});

export const config = {
Expand Down

0 comments on commit a207c0a

Please sign in to comment.