Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Github login #122

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions app/api/auth/[...nextauth]/options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import GitHubProvider from "next-auth/providers/github";
import { NextAuthOptions } from "next-auth";

export const authOptions: NextAuthOptions = {
providers: [
GitHubProvider({
clientId: process.env.GITHUB_CLIENT_ID as string,
clientSecret: process.env.GITHUB_CLIENT_SECRET as string,
}),
],
callbacks: {
async jwt({ token, account }) {
if (account) {
token.accessToken = account.access_token;
}
return token;
},
async session({ session, token }) {
// Type assertion to let TypeScript know token will have accessToken
session.accessToken = (token as { accessToken?: string }).accessToken;
return session;
},
},
};
6 changes: 6 additions & 0 deletions app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import NextAuth from "next-auth";
import { authOptions } from "./options";

const handler = NextAuth(authOptions);

export { handler as GET, handler as POST };
1 change: 0 additions & 1 deletion app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export default function RootLayout({
children: React.ReactNode;
}) {
const isProduction = process.env.VERCEL_ENV === "production";

return (
<html
lang="en"
Expand Down
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
6 changes: 5 additions & 1 deletion components/nav/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +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";

export default async function Navbar() {
const projects = await getAllProjects().catch((error) => {
Expand Down Expand Up @@ -51,6 +52,9 @@ export default async function Navbar() {
{projects && <ProjectDropDown projects={projects} />}
<CtaButton />
</div>
<div>
<AuthMenu />
</div>
</NavbarContent>
</NextUINavbar>
);
Expand Down
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
4 changes: 4 additions & 0 deletions middlewares/github.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { default } from "next-auth/middleware";

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

const nextConfig = {
images: {
remotePatterns: ["avatars.githubusercontent.com"],
formats: ["image/avif", "image/webp"],
remotePatterns: [
{
Expand Down
2 changes: 2 additions & 0 deletions 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 @@ -47,6 +48,7 @@
"isomorphic-dompurify": "^2.19.0",
"marked": "^15.0.4",
"next": "15.1.3",
"next-auth": "^4.24.10",
"next-themes": "^0.4.4",
"react": "19.0.0",
"react-dom": "19.0.0",
Expand Down
Loading
Loading