From 4ac8bb9f0688f4d05894c1737a07b9bf890856cc Mon Sep 17 00:00:00 2001 From: Pulkit Date: Sun, 6 Oct 2024 17:15:10 +0530 Subject: [PATCH] feat: added github auth --- core/.env | 2 + core/app/api/auth/[...nextauth]/route.ts | 18 +++ core/app/layout.tsx | 13 +- core/app/page.tsx | 12 +- core/components/Navbar.tsx | 5 +- core/package-lock.json | 176 ++++++++++++++++++++++- core/package.json | 1 + core/providers/app-wrapper.tsx | 16 +++ 8 files changed, 232 insertions(+), 11 deletions(-) create mode 100644 core/.env create mode 100644 core/app/api/auth/[...nextauth]/route.ts create mode 100644 core/providers/app-wrapper.tsx diff --git a/core/.env b/core/.env new file mode 100644 index 0000000..ecdfecf --- /dev/null +++ b/core/.env @@ -0,0 +1,2 @@ +GITHUB_ID=Ov23liBk6nkspsO1MrXz +GITHUB_SECRET=5f2f63e7958f562ea2741883b7f5a7cde9d0c5f1 \ No newline at end of file diff --git a/core/app/api/auth/[...nextauth]/route.ts b/core/app/api/auth/[...nextauth]/route.ts new file mode 100644 index 0000000..dd4dded --- /dev/null +++ b/core/app/api/auth/[...nextauth]/route.ts @@ -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); \ No newline at end of file diff --git a/core/app/layout.tsx b/core/app/layout.tsx index 3fe905d..e69d186 100644 --- a/core/app/layout.tsx +++ b/core/app/layout.tsx @@ -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", @@ -11,17 +11,16 @@ export const metadata: Metadata = { export default function RootLayout({ children, -}: Readonly<{ +}: { children: React.ReactNode; -}>) { +}) { return ( - - + - - {children} + {children} + ); diff --git a/core/app/page.tsx b/core/app/page.tsx index d30c80d..ac180ed 100644 --- a/core/app/page.tsx +++ b/core/app/page.tsx @@ -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 ; + } + return
; } diff --git a/core/components/Navbar.tsx b/core/components/Navbar.tsx index fcef3a7..9c7933d 100644 --- a/core/components/Navbar.tsx +++ b/core/components/Navbar.tsx @@ -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); @@ -68,7 +69,9 @@ export default function Navbar() { - +
diff --git a/core/package-lock.json b/core/package-lock.json index 5ba0e72..8066a87 100644 --- a/core/package-lock.json +++ b/core/package-lock.json @@ -1,11 +1,11 @@ { - "name": "deploytit:core", + "name": "deployit-core", "version": "0.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "deploytit:core", + "name": "deployit-core", "version": "0.1.0", "dependencies": { "@heroicons/react": "^2.1.5", @@ -16,6 +16,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", @@ -165,6 +166,18 @@ "node": ">=4" } }, + "node_modules/@babel/runtime": { + "version": "7.25.7", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.25.7.tgz", + "integrity": "sha512-FjoyLe754PMiYsFaN5C94ttGiOmBNYTf6pLr4xXHAT5uctHb092PBszndLDR5XA/jghQvn4n7JMHl7dmTgbm9w==", + "license": "MIT", + "dependencies": { + "regenerator-runtime": "^0.14.0" + }, + "engines": { + "node": ">=6.9.0" + } + }, "node_modules/@commitlint/cli": { "version": "19.5.0", "resolved": "https://registry.npmjs.org/@commitlint/cli/-/cli-19.5.0.tgz", @@ -1026,6 +1039,15 @@ "node": ">=12.4.0" } }, + "node_modules/@panva/hkdf": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@panva/hkdf/-/hkdf-1.2.1.tgz", + "integrity": "sha512-6oclG6Y3PiDFcoyk8srjLfVKyMfVCKJ27JwNPViuXziFpmdz+MZnZN/aKY0JGXgYuO/VghU0jcOAZgWXZ1Dmrw==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/panva" + } + }, "node_modules/@pkgjs/parseargs": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", @@ -2583,6 +2605,15 @@ "node": ">=16" } }, + "node_modules/cookie": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.5.0.tgz", + "integrity": "sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, "node_modules/cosmiconfig": { "version": "9.0.0", "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-9.0.0.tgz", @@ -4705,6 +4736,15 @@ "jiti": "bin/jiti.js" } }, + "node_modules/jose": { + "version": "4.15.9", + "resolved": "https://registry.npmjs.org/jose/-/jose-4.15.9.tgz", + "integrity": "sha512-1vUQX+IdDMVPj4k8kOxgUqlcK518yluMuGZwqlr44FS1ppZB/5GWh4rZG89erpOBOJjU/OBsnCVFfapsRz6nEA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/panva" + } + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -5133,6 +5173,38 @@ } } }, + "node_modules/next-auth": { + "version": "4.24.8", + "resolved": "https://registry.npmjs.org/next-auth/-/next-auth-4.24.8.tgz", + "integrity": "sha512-SLt3+8UCtklsotnz2p+nB4aN3IHNmpsQFAZ24VLxGotWGzSxkBh192zxNhm/J5wgkcrDWVp0bwqvW0HksK/Lcw==", + "license": "ISC", + "dependencies": { + "@babel/runtime": "^7.20.13", + "@panva/hkdf": "^1.0.2", + "cookie": "^0.5.0", + "jose": "^4.15.5", + "oauth": "^0.9.15", + "openid-client": "^5.4.0", + "preact": "^10.6.3", + "preact-render-to-string": "^5.1.19", + "uuid": "^8.3.2" + }, + "peerDependencies": { + "@auth/core": "0.34.2", + "next": "^12.2.5 || ^13 || ^14", + "nodemailer": "^6.6.5", + "react": "^17.0.2 || ^18", + "react-dom": "^17.0.2 || ^18" + }, + "peerDependenciesMeta": { + "@auth/core": { + "optional": true + }, + "nodemailer": { + "optional": true + } + } + }, "node_modules/next-themes": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/next-themes/-/next-themes-0.3.0.tgz", @@ -5180,6 +5252,12 @@ "node": ">=0.10.0" } }, + "node_modules/oauth": { + "version": "0.9.15", + "resolved": "https://registry.npmjs.org/oauth/-/oauth-0.9.15.tgz", + "integrity": "sha512-a5ERWK1kh38ExDEfoO6qUHJb32rd7aYmPHuyCu3Fta/cnICvYmgd2uhuKXvPD+PXB+gCEYYEaQdIRAjCOwAKNA==", + "license": "MIT" + }, "node_modules/object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -5324,6 +5402,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/oidc-token-hash": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/oidc-token-hash/-/oidc-token-hash-5.0.3.tgz", + "integrity": "sha512-IF4PcGgzAr6XXSff26Sk/+P4KZFJVuHAJZj3wgO3vX2bMdNVp/QXTP3P7CEm9V1IdG8lDLY3HhiqpsE/nOwpPw==", + "license": "MIT", + "engines": { + "node": "^10.13.0 || >=12.0.0" + } + }, "node_modules/once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -5334,6 +5421,42 @@ "wrappy": "1" } }, + "node_modules/openid-client": { + "version": "5.7.0", + "resolved": "https://registry.npmjs.org/openid-client/-/openid-client-5.7.0.tgz", + "integrity": "sha512-4GCCGZt1i2kTHpwvaC/sCpTpQqDnBzDzuJcJMbH+y1Q5qI8U8RBvoSh28svarXszZHR5BAMXbJPX1PGPRE3VOA==", + "license": "MIT", + "dependencies": { + "jose": "^4.15.9", + "lru-cache": "^6.0.0", + "object-hash": "^2.2.0", + "oidc-token-hash": "^5.0.3" + }, + "funding": { + "url": "https://github.com/sponsors/panva" + } + }, + "node_modules/openid-client/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "license": "ISC", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/openid-client/node_modules/object-hash": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/object-hash/-/object-hash-2.2.0.tgz", + "integrity": "sha512-gScRMn0bS5fH+IuwyIFgnh9zBdo4DV+6GhygmWM9HyNJSgS0hScp1f5vjtm7oIIOiT9trXrShAkLFSc2IqKNgw==", + "license": "MIT", + "engines": { + "node": ">= 6" + } + }, "node_modules/optionator": { "version": "0.9.4", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz", @@ -5668,6 +5791,28 @@ "integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==", "license": "MIT" }, + "node_modules/preact": { + "version": "10.24.2", + "resolved": "https://registry.npmjs.org/preact/-/preact-10.24.2.tgz", + "integrity": "sha512-1cSoF0aCC8uaARATfrlz4VCBqE8LwZwRfLgkxJOQwAlQt6ayTmi0D9OF7nXid1POI5SZidFuG9CnlXbDfLqY/Q==", + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/preact" + } + }, + "node_modules/preact-render-to-string": { + "version": "5.2.6", + "resolved": "https://registry.npmjs.org/preact-render-to-string/-/preact-render-to-string-5.2.6.tgz", + "integrity": "sha512-JyhErpYOvBV1hEPwIxc/fHWXPfnEGdRKxc8gFdAZ7XV4tlzyzG847XAyEZqoDnynP88akM4eaHcSOzNcLWFguw==", + "license": "MIT", + "dependencies": { + "pretty-format": "^3.8.0" + }, + "peerDependencies": { + "preact": ">=10" + } + }, "node_modules/prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", @@ -5678,6 +5823,12 @@ "node": ">= 0.8.0" } }, + "node_modules/pretty-format": { + "version": "3.8.0", + "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-3.8.0.tgz", + "integrity": "sha512-WuxUnVtlWL1OfZFQFuqvnvs6MiAGk9UNsBostyBOB0Is9wb5uRESevA6rnl/rkksXaGX3GzZhPup5d6Vp1nFew==", + "license": "MIT" + }, "node_modules/prop-types": { "version": "15.8.1", "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.8.1.tgz", @@ -5865,6 +6016,12 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/regenerator-runtime": { + "version": "0.14.1", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz", + "integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==", + "license": "MIT" + }, "node_modules/regexp.prototype.flags": { "version": "1.5.3", "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.3.tgz", @@ -6865,6 +7022,15 @@ "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", "license": "MIT" }, + "node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "license": "MIT", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -7084,6 +7250,12 @@ "node": ">=10" } }, + "node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "license": "ISC" + }, "node_modules/yaml": { "version": "2.5.1", "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.5.1.tgz", diff --git a/core/package.json b/core/package.json index b66cab5..bca59b4 100644 --- a/core/package.json +++ b/core/package.json @@ -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", diff --git a/core/providers/app-wrapper.tsx b/core/providers/app-wrapper.tsx new file mode 100644 index 0000000..099e4b7 --- /dev/null +++ b/core/providers/app-wrapper.tsx @@ -0,0 +1,16 @@ +"use client"; + +import { SessionProvider } from "next-auth/react"; +import ThemeProvider from "@/providers/ThemeProvider"; + +export default function AppWrapper({ + children, +}: { + children: React.ReactNode; +}) { + return ( + + {children} + + ); +}