Skip to content

Commit

Permalink
feat: added github auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Pulkitxm committed Oct 6, 2024
1 parent d8a5596 commit 4ac8bb9
Show file tree
Hide file tree
Showing 8 changed files with 232 additions and 11 deletions.
2 changes: 2 additions & 0 deletions core/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GITHUB_ID=Ov23liBk6nkspsO1MrXz
GITHUB_SECRET=5f2f63e7958f562ea2741883b7f5a7cde9d0c5f1
18 changes: 18 additions & 0 deletions core/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import NextAuth from "next-auth";
import GithubProvider from "next-auth/providers/github";

const GITHUB_ID = process.env.GITHUB_ID ?? "";
const GITHUB_SECRET = process.env.GITHUB_SECRET ?? "";

export const authOptions = {
providers: [
GithubProvider({
clientId: GITHUB_ID,
clientSecret: GITHUB_SECRET,
}),
],
};

export const GET = NextAuth(authOptions);

export const POST = NextAuth(authOptions);
13 changes: 6 additions & 7 deletions core/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Metadata } from "next";
import "./globals.css";

import Navbar from "@/components/Navbar";
import ThemeProvider from "@/providers/ThemeProvider";
import AppWrapper from "../providers/app-wrapper";

export const metadata: Metadata = {
title: "Create Next App",
Expand All @@ -11,17 +11,16 @@ export const metadata: Metadata = {

export default function RootLayout({
children,
}: Readonly<{
}: {
children: React.ReactNode;
}>) {
}) {
return (
<html lang="en" suppressHydrationWarning>
<body>
<ThemeProvider>

<AppWrapper>
<Navbar />

{children}</ThemeProvider>
{children}
</AppWrapper>
</body>
</html>
);
Expand Down
12 changes: 11 additions & 1 deletion core/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
"use client";

import { signIn, useSession } from "next-auth/react";
import React from "react";

export default function page() {
export default function Page() {
const session = useSession();
console.log(session);

if (!session.data) {
return <button onClick={() => signIn()}>Signin</button>;
}

return <div></div>;
}
5 changes: 4 additions & 1 deletion core/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Link from "next/link";
import { Menu, X } from "lucide-react";
import { Button } from "@/components/ui/button";
import ThemeToggle from "@/components/ui/ThemeToggle";
import { signIn } from "next-auth/react";

export default function Navbar() {
const [isMenuOpen, setIsMenuOpen] = useState(false);
Expand Down Expand Up @@ -68,7 +69,9 @@ export default function Navbar() {
<Button variant="ghost" size="sm">
Log in
</Button>
<Button size="sm">Sign up</Button>
<Button size="sm" onClick={() => signIn()}>
Sign up
</Button>
</div>
<div className="flex items-center sm:hidden">
<ThemeToggle />
Expand Down
176 changes: 174 additions & 2 deletions core/package-lock.json

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

1 change: 1 addition & 0 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"clsx": "^2.1.1",
"lucide-react": "^0.447.0",
"next": "14.2.14",
"next-auth": "^4.24.8",
"next-themes": "^0.3.0",
"react": "^18",
"react-dom": "^18",
Expand Down
Loading

0 comments on commit 4ac8bb9

Please sign in to comment.