Skip to content

Commit

Permalink
login UI
Browse files Browse the repository at this point in the history
  • Loading branch information
ipapandinas committed Dec 29, 2024
1 parent 5f120f4 commit 0721e66
Show file tree
Hide file tree
Showing 15 changed files with 110 additions and 102 deletions.
5 changes: 2 additions & 3 deletions app/api/auth/[...nextauth]/options.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

import GitHubProvider from "next-auth/providers/github";
import NextAuth, { NextAuthOptions } from "next-auth";
import { NextAuthOptions } from "next-auth";

export const authOptions: NextAuthOptions = {
providers: [
Expand All @@ -22,4 +21,4 @@ export const authOptions: NextAuthOptions = {
return session;
},
},
};
};
2 changes: 1 addition & 1 deletion app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import { authOptions } from "./options";

const handler = NextAuth(authOptions);

export { handler as GET, handler as POST };
export { handler as GET, handler as POST };
2 changes: 0 additions & 2 deletions app/client-session-provider.tsx

This file was deleted.

10 changes: 4 additions & 6 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import Navbar from "@/components/nav/navbar";
import TopBar from "@/components/nav/top-bar";
import { container } from "@/components/primitives";
import { SITE_CONFIG } from "@/data/config";
import { AuthProvider } from "./client-session-provider";
// import { auth } from "./api/auth/[...nextauth]/options";
import { Providers } from "./providers";

export const fontSans = Archivo({
subsets: ["latin"],
Expand Down Expand Up @@ -75,13 +74,12 @@ export const viewport: Viewport = {
themeColor: "#020817",
};

export default async function RootLayout({
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
const isProduction = process.env.VERCEL_ENV === "production";
// const session = await auth()
return (
<html
lang="en"
Expand All @@ -94,7 +92,7 @@ export default async function RootLayout({
>
<head />
<body className="min-h-screen bg-background font-sans antialiased">
<AuthProvider >
<Providers>
<div className="bg-[radial-gradient(ellipse_at_center,_var(--tw-gradient-stops))] from-default from-0% to-background to-50% relative flex flex-col">
<header>
<TopBar />
Expand All @@ -107,7 +105,7 @@ export default async function RootLayout({
<Footer />
</footer>
</div>
</AuthProvider>
</Providers>
<Analytics />
</body>
{isProduction && <GoogleAnalytics gaId={SITE_CONFIG.googleAnalyticsId} />}
Expand Down
33 changes: 0 additions & 33 deletions app/profiles/page.tsx

This file was deleted.

5 changes: 3 additions & 2 deletions app/providers.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"use client";

import * as React from "react";
import { NextUIProvider } from "@nextui-org/system";
import { SessionProvider as AuthProvider } from "next-auth/react";
import { useRouter } from "next/navigation";
import { ThemeProvider as NextThemesProvider } from "next-themes";
import { NextUIProvider } from "@nextui-org/system";
import { QueryClientProvider } from "@tanstack/react-query";
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
import { queryClient } from "@/lib/react-query-client";
Expand All @@ -19,7 +20,7 @@ export function Providers({ children }: ProvidersProps) {
<QueryClientProvider client={queryClient}>
<NextUIProvider navigate={router.push}>
<NextThemesProvider attribute="class" defaultTheme="kudos">
{children}
<AuthProvider>{children}</AuthProvider>
</NextThemesProvider>
</NextUIProvider>
<ReactQueryDevtools initialIsOpen={false} />
Expand Down
65 changes: 65 additions & 0 deletions components/auth/auth-menu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"use client";

import { signIn, signOut, useSession } from "next-auth/react";
import { Avatar } from "@nextui-org/avatar";
import { Button } from "@nextui-org/button";
import {
Dropdown,
DropdownTrigger,
DropdownMenu,
DropdownItem,
} from "@nextui-org/dropdown";
import { Skeleton } from "@nextui-org/skeleton";

import { GithubIcon } from "@/assets/icons";

const AuthMenu: React.FC = () => {
const { data: session, status } = useSession();

if (status === "loading") {
return <Skeleton className="h-10 w-10 rounded-full" />;
}

return (
<div>
{session ? (
<Dropdown placement="bottom-end">
<DropdownTrigger>
{/* TODO: Support no image placeholder */}
<Avatar
isBordered
as="button"
className="transition-transform"
src={session.user?.image}
/>
</DropdownTrigger>
<DropdownMenu aria-label="Profile Actions" variant="flat">
{
<DropdownItem key="profile" className="h-14 gap-2" showDivider>
<p className="font-semibold">Signed in as</p>
<p className="font-semibold">{session.user?.name}</p>
</DropdownItem>
}
<DropdownItem key="logout" color="danger" onPress={() => signOut()}>
Log Out
</DropdownItem>
</DropdownMenu>
</Dropdown>
) : (
<Button
size="sm"
aria-label="Login"
color="default"
variant="faded"
className="capitalize font-semibold"
onPress={() => signIn("github")}
startContent={<GithubIcon size={20} />}
>
<p>Login</p>
</Button>
)}
</div>
);
};

export default AuthMenu;
2 changes: 1 addition & 1 deletion components/cta-banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const CtaBanner = ({}: ICtaBannerProps) => {
className="font-semibold border-large hover:underline"
color="danger"
variant="bordered"
onClick={handleClose}
onPress={handleClose}
>
Hide this
</Button>
Expand Down
10 changes: 5 additions & 5 deletions components/nav/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import {
NavbarBrand,
} from "@nextui-org/navbar";
import { Chip } from "@nextui-org/chip";
import AuthMenu from "@/components/auth/auth-menu";
import { MyImage } from "@/components/ui/image";
import { getAllProjects } from "@/lib/api/projects";

import { BugReport, CtaButton, FeedbackForms, ProjectDropDown } from "./items";
import Separator from "./separator";
import SocialLinks from "./social-links";
import { getAllProjects } from "@/lib/api/projects";
import dynamic from "next/dynamic";

const GitHubLoginButton = dynamic(() => import("@/components/sign-in"), { ssr: false });

export default async function Navbar() {
const projects = await getAllProjects().catch((error) => {
Expand Down Expand Up @@ -54,7 +52,9 @@ export default async function Navbar() {
{projects && <ProjectDropDown projects={projects} />}
<CtaButton />
</div>
<div><GitHubLoginButton /></div>
<div>
<AuthMenu />
</div>
</NavbarContent>
</NextUINavbar>
);
Expand Down
30 changes: 0 additions & 30 deletions components/sign-in.tsx

This file was deleted.

5 changes: 2 additions & 3 deletions components/table/row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -347,16 +347,15 @@ interface IApplyButtonProps {
onOpen: () => void;
}
export const ApplyButton = ({ onOpen }: IApplyButtonProps) => {
const handleClick = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
e.stopPropagation();
const handleClick = () => {
onOpen();
};

return (
<Button
className="invisible group-hover:visible"
color="primary"
onClick={handleClick}
onPress={handleClick}
>
Apply
</Button>
Expand Down
3 changes: 1 addition & 2 deletions middlewares/github.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

export { default } from "next-auth/middleware";

// applies next-auth only to matching routes
export const config = { matcher: ["/profiles"] };
export const config = { matcher: ["/profiles"] };
2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const cspHeader = `

const nextConfig = {
images: {
domains: ["avatars.githubusercontent.com"],
remotePatterns: ["avatars.githubusercontent.com"],
formats: ["image/avif", "image/webp"],
remotePatterns: [
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"dependencies": {
"@next/third-parties": "15.1.3",
"@nextui-org/avatar": "^2.2.5",
"@nextui-org/button": "2.2.8",
"@nextui-org/card": "^2.2.8",
"@nextui-org/checkbox": "^2.3.7",
Expand Down Expand Up @@ -53,7 +54,6 @@
"react-dom": "19.0.0",
"react-hook-form": "^7.54.2",
"react-responsive": "^10.0.0",
"react-social-login-buttons": "^4.1.0",
"sharp": "0.33.5",
"tailwind-variants": "^0.3.0",
"tailwindcss": "3.4.17",
Expand Down
36 changes: 24 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0721e66

Please sign in to comment.