Skip to content

Commit

Permalink
feat: authjs following nextjs 13 structure
Browse files Browse the repository at this point in the history
  • Loading branch information
SEBRATHEZEBRA committed Aug 4, 2023
1 parent 7f02c16 commit 2893313
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 46 deletions.
1 change: 0 additions & 1 deletion services/web-app/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
/// <reference types="next/navigation-types/compat/navigation" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
1 change: 1 addition & 0 deletions services/web-app/public/github-mark-white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions services/web-app/src/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { authOptions } from "@/lib/auth";
import NextAuth from "next-auth";

const handler = NextAuth(authOptions);
export { handler as GET, handler as POST };
15 changes: 9 additions & 6 deletions services/web-app/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import { SessionProvider } from "next-auth/react"
import type { AppProps } from 'next/app'
import "../styles/globals.css";
import React, { ReactNode } from 'react';
import { Session } from 'next-auth';
import { NextAuthProvider } from './providers';

export const metadata = {
title: 'Code Review GPT',
}

export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
}: {children: ReactNode }) {
return (
<html lang="en">
<body>
{children}
</body>
<body>
<NextAuthProvider>{children}</NextAuthProvider>
</body>
</html>
)
}
43 changes: 19 additions & 24 deletions services/web-app/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
"use client"
import { useSession, signIn } from 'next-auth/react';
"use client";
import { LoginButton } from '@/components/buttons/login';
import { useSession } from 'next-auth/react';
import Image from "next/image";
import GithubImg from "../../public/github-mark-white.svg";

export default function Home() {
// const { data, status } = useSession();
// const userEmail = data?.user?.email;

// if (status === "loading") {
// return <p>Hang on there...</p>
// }

// if (status === "authenticated") {
// return (
// <>
// <p>Signed in as {userEmail}</p>
// <button onClick={() => signOut()}>Sign out</button>
// <img src="https://cdn.pixabay.com/photo/2017/08/11/19/36/vw-2632486_1280.png" />
// </>
// )
// }
const { data, status } = useSession();

return (
<div className="flex flex-col items-center p-16 relative place-items-center">
<h1 className="pb-[40px] text-4xl font-mono">
<>
<div className="flex flex-col items-center p-16 relative place-items-center">
<h1 className="pb-[10px] text-4xl font-mono">
Code Review GPT
</h1>
<button className="border-solid border-2 border-white p-[10px] text-3xl duration-500 hover:scale-125 hover:animate-bounce" style={{}} onClick={() => { signIn("github") }}>
Login
</button>
</div>
<a href="https://github.com/mattzcarey/code-review-gpt">
<Image src={GithubImg} alt={""} className="p-[10px] w-[60px]" />
</a>
{status === "authenticated" ? (
<h1>You're logged in</h1>
) : (
<LoginButton />
)}
</div>
</>
)
}
11 changes: 11 additions & 0 deletions services/web-app/src/app/providers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"use client";

import { SessionProvider } from "next-auth/react";

type Props = {
children?: React.ReactNode;
};

export const NextAuthProvider = ({ children }: Props) => {
return <SessionProvider>{children}</SessionProvider>;
};
9 changes: 9 additions & 0 deletions services/web-app/src/components/buttons/login.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { signIn } from 'next-auth/react';

export const LoginButton = () => {
return (
<button className="border-solid border-2 border-white p-[5px] text-xl duration-500 hover:scale-125" style={{}} onClick={() => { signIn("github") }}>
Login
</button>
)
};
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import NextAuth from "next-auth"
import { NextAuthOptions } from "next-auth"
import GithubProvider from "next-auth/providers/github"

export default NextAuth({
export const authOptions: NextAuthOptions = ({
providers: [
GithubProvider({
clientId: process.env.GITHUB_ID as string,
clientSecret: process.env.GITHUB_SECRET as string,
}),
],
})
});
12 changes: 0 additions & 12 deletions services/web-app/src/pages/_app.tsx

This file was deleted.

0 comments on commit 2893313

Please sign in to comment.