-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
292 additions
and
22 deletions.
There are no files selected for viewing
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
Large diffs are not rendered by default.
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
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" | ||
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,74 @@ | ||
"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 aria-label="Loading authentication status..." />; | ||
} | ||
|
||
if (status === "authenticated") { | ||
const signOutClick = () => | ||
signOut({ | ||
callbackUrl: "/", | ||
}); | ||
if (minimal) { | ||
return ( | ||
<Button onClick={signOutClick} color="danger" 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="sign-out" color="danger" onClick={signOutClick}> | ||
Sign Out | ||
</DropdownItem> | ||
</DropdownMenu> | ||
</Dropdown> | ||
); | ||
} | ||
|
||
return ( | ||
<Button | ||
onClick={() => | ||
signIn("google", { | ||
callbackUrl: "/profile", | ||
}) | ||
} | ||
color="danger" | ||
variant="ghost" | ||
> | ||
<IconBrandGoogle /> | ||
Sign In | ||
</Button> | ||
); | ||
} |
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
File renamed without changes.
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,18 @@ | ||
import { NextAuthOptions } from "next-auth"; | ||
import GoogleProvider from "next-auth/providers/google"; | ||
|
||
import { env } from "@/env/server"; | ||
|
||
const options: NextAuthOptions = { | ||
pages: { | ||
signIn: "/", | ||
}, | ||
providers: [ | ||
GoogleProvider({ | ||
clientId: env.GOOGLE_CLIENT_ID, | ||
clientSecret: env.GOOGLE_CLIENT_SECRET, | ||
}), | ||
], | ||
}; | ||
|
||
export default options; |
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,3 @@ | ||
export { default } from "next-auth/middleware"; | ||
|
||
export const config = { matcher: ["/profile"] }; |