-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add next-auth middleware and configure profile route
- Add next-auth middleware to handle authentication - Configure profile route to require authentication - Update package.json to include next-auth dependency - Delete unused client environment file - Update server environment file with required variables - Create auth configuration file with Google provider - Add ExampleThing component and update settings - Update layout component to use Suspense for better loading experience - Create loading component with circular progress indicator - Create profile page component to display user information - Create theme switcher component for toggling between light and dark themes - Update providers component to include session provider - Delete old theme switcher component - Delete old app-navbar component - Create new app-navbar component with authentication button - Create auth-button component for handling authentication actions
- Loading branch information
Showing
14 changed files
with
309 additions
and
32 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import NextAuth from "next-auth"; | ||
|
||
import options from "@/config/auth"; | ||
|
||
const handler = NextAuth(options); | ||
|
||
export { handler as GET, handler as POST }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { CircularProgress } from "@nextui-org/react"; | ||
|
||
export default function Loading() { | ||
return ( | ||
<CircularProgress | ||
className="mx-auto mt-4" | ||
classNames={{ | ||
svg: "w-36 h-36", | ||
}} | ||
aria-label="Loading page" | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Card, CardBody, User } from "@nextui-org/react"; | ||
import { getServerSession } from "next-auth"; | ||
|
||
import options from "@/config/auth"; | ||
|
||
export default async function Profile() { | ||
const session = await getServerSession(options); | ||
|
||
return ( | ||
<Card className="mx-auto mt-4 max-w-md"> | ||
<CardBody> | ||
<User | ||
name={session?.user?.name} | ||
description={session?.user?.email} | ||
avatarProps={{ | ||
showFallback: !session?.user?.image, | ||
src: session?.user?.image || "", | ||
}} | ||
/> | ||
</CardBody> | ||
</Card> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
"use client"; | ||
|
||
import { | ||
Avatar, | ||
Button, | ||
CircularProgress, | ||
Dropdown, | ||
DropdownItem, | ||
DropdownMenu, | ||
DropdownTrigger, | ||
} from "@nextui-org/react"; | ||
import { IconBrandGoogle } from "@tabler/icons-react"; | ||
import { signIn, signOut, useSession } from "next-auth/react"; | ||
|
||
export default function AuthButton({ minimal = true }: { minimal?: boolean }) { | ||
const { data, status } = useSession(); | ||
if (status === "loading") { | ||
return <CircularProgress />; | ||
} | ||
if (status === "authenticated") { | ||
const signOutClick = () => signOut({ callbackUrl: "/" }); | ||
if (minimal) { | ||
return ( | ||
<Button onClick={signOutClick} color="success" variant="ghost"> | ||
<IconBrandGoogle /> | ||
Sign Out | ||
</Button> | ||
); | ||
} | ||
return ( | ||
<Dropdown placement="bottom-end"> | ||
<DropdownTrigger> | ||
<Avatar | ||
isBordered | ||
as="button" | ||
className="transition-transform" | ||
showFallback={!data.user?.image} | ||
src={data.user?.image || ""} | ||
/> | ||
</DropdownTrigger> | ||
<DropdownMenu aria-label="Profile Actions" variant="flat"> | ||
<DropdownItem key="profile" className="h-14 gap-2"> | ||
<p className="font-semibold">Signed in as</p> | ||
<p className="font-semibold">{data.user?.email}</p> | ||
</DropdownItem> | ||
<DropdownItem key="logout" color="danger" onClick={signOutClick}> | ||
Sign Out | ||
</DropdownItem> | ||
</DropdownMenu> | ||
</Dropdown> | ||
); | ||
} | ||
return ( | ||
<Button | ||
onClick={() => signIn("google", { callbackUrl: "/profile" })} | ||
color="danger" | ||
variant="ghost" | ||
> | ||
<IconBrandGoogle /> | ||
Sign In | ||
</Button> | ||
); | ||
} |
Oops, something went wrong.