├── .eslintrc.json ├── src ├── app │ ├── globals.css │ ├── favicon.ico │ ├── api │ │ ├── auth │ │ │ └── [kindeAuth] │ │ │ │ └── route.ts │ │ └── protected │ │ │ └── route.ts │ ├── dashboard │ │ └── page.tsx │ ├── layout.tsx │ ├── page.tsx │ └── components │ │ └── Navbar.tsx └── middleware.ts ├── postcss.config.js ├── .gitignore ├── tailwind.config.js ├── next.config.js ├── public ├── vercel.svg └── next.svg ├── package.json ├── tsconfig.json └── README.md /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "next/core-web-vitals" 3 | } 4 | -------------------------------------------------------------------------------- /src/app/globals.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | -------------------------------------------------------------------------------- /src/app/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gitdagray/kinde-auth-nextjs/HEAD/src/app/favicon.ico -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /src/app/api/auth/[kindeAuth]/route.ts: -------------------------------------------------------------------------------- 1 | import { NextRequest } from "next/server" 2 | import { handleAuth } from "@kinde-oss/kinde-auth-nextjs/server" 3 | 4 | export async function GET(request: NextRequest, { params }: any) { 5 | const endpoint = params.kindeAuth 6 | return handleAuth(request, endpoint) 7 | } -------------------------------------------------------------------------------- /src/app/dashboard/page.tsx: -------------------------------------------------------------------------------- 1 | export default function page() { 2 | return ( 3 |
4 |

Boom!

5 |

Your Auth is all sorted.

6 |

Build the important stuff.

7 |
8 | ) 9 | } -------------------------------------------------------------------------------- /src/app/api/protected/route.ts: -------------------------------------------------------------------------------- 1 | import { NextResponse } from "next/server" 2 | import { getKindeServerSession } from "@kinde-oss/kinde-auth-nextjs/server" 3 | 4 | export async function GET() { 5 | const { getUser, isAuthenticated } = getKindeServerSession() 6 | 7 | if (!isAuthenticated()) { 8 | return new Response("Unauthorized", { status: 401 }) 9 | } 10 | const user = getUser() 11 | const data = { message: "Hello User", id: user.id } 12 | 13 | return NextResponse.json({ data }) 14 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | 15 | # production 16 | /build 17 | 18 | # misc 19 | .DS_Store 20 | *.pem 21 | 22 | # debug 23 | npm-debug.log* 24 | yarn-debug.log* 25 | yarn-error.log* 26 | 27 | # local env files 28 | .env*.local 29 | 30 | # vercel 31 | .vercel 32 | 33 | # typescript 34 | *.tsbuildinfo 35 | next-env.d.ts 36 | -------------------------------------------------------------------------------- /src/middleware.ts: -------------------------------------------------------------------------------- 1 | import { authMiddleware } from "@kinde-oss/kinde-auth-nextjs/server" 2 | 3 | export const config = { 4 | matcher: [ 5 | /* 6 | * Match all request paths except for the ones starting with: 7 | * - api (API routes) 8 | * - _next/static (static files) 9 | * - _next/image (image optimization files) 10 | * - favicon.ico (favicon file) 11 | */ 12 | "/((?!api|_next/static|_next/image|favicon.ico).*)", 13 | ], 14 | } 15 | 16 | export default authMiddleware -------------------------------------------------------------------------------- /tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: [ 4 | './src/pages/**/*.{js,ts,jsx,tsx,mdx}', 5 | './src/components/**/*.{js,ts,jsx,tsx,mdx}', 6 | './src/app/**/*.{js,ts,jsx,tsx,mdx}', 7 | ], 8 | theme: { 9 | extend: { 10 | backgroundImage: { 11 | 'gradient-radial': 'radial-gradient(var(--tw-gradient-stops))', 12 | 'gradient-conic': 13 | 'conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))', 14 | }, 15 | }, 16 | }, 17 | plugins: [], 18 | } 19 | -------------------------------------------------------------------------------- /src/app/layout.tsx: -------------------------------------------------------------------------------- 1 | import './globals.css' 2 | import Navbar from './components/Navbar' 3 | 4 | export const metadata = { 5 | title: 'Kinde Auth', 6 | description: 'Kinde Auth with Next.js App Router', 7 | } 8 | 9 | export default function RootLayout({ 10 | children, 11 | }: { 12 | children: React.ReactNode 13 | }) { 14 | return ( 15 | 16 | 17 | 18 |
19 | {children} 20 |
21 | 22 | 23 | ) 24 | } 25 | -------------------------------------------------------------------------------- /src/app/page.tsx: -------------------------------------------------------------------------------- 1 | import Link from "next/link" 2 | 3 | export default function Home() { 4 | return ( 5 |
6 |

Let's start authenicating with Kinde

7 |

Configure your app

8 | Go to Docs 9 |
10 | ) 11 | } 12 | -------------------------------------------------------------------------------- /next.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('next').NextConfig} */ 2 | const nextConfig = { 3 | images: { 4 | remotePatterns: [ 5 | { 6 | protocol: 'https', 7 | hostname: 'lh3.googleusercontent.com', 8 | port: '', 9 | pathname: '/a/**', 10 | }, 11 | { 12 | protocol: 'https', 13 | hostname: 'avatars.githubusercontent.com', 14 | port: '', 15 | pathname: '/u/**', 16 | }, 17 | ], 18 | }, 19 | } 20 | 21 | module.exports = nextConfig 22 | -------------------------------------------------------------------------------- /public/vercel.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "kinde-auth", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "dev": "next dev", 7 | "build": "next build", 8 | "start": "next start", 9 | "lint": "next lint" 10 | }, 11 | "dependencies": { 12 | "@kinde-oss/kinde-auth-nextjs": "^1.8.9", 13 | "@types/node": "20.4.1", 14 | "@types/react": "18.2.14", 15 | "@types/react-dom": "18.2.7", 16 | "autoprefixer": "10.4.14", 17 | "eslint": "8.44.0", 18 | "eslint-config-next": "13.4.9", 19 | "next": "13.4.9", 20 | "postcss": "8.4.25", 21 | "react": "18.2.0", 22 | "react-dom": "18.2.0", 23 | "tailwindcss": "3.3.2", 24 | "typescript": "5.1.6" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": ["dom", "dom.iterable", "esnext"], 5 | "allowJs": true, 6 | "skipLibCheck": true, 7 | "strict": true, 8 | "forceConsistentCasingInFileNames": true, 9 | "noEmit": true, 10 | "esModuleInterop": true, 11 | "module": "esnext", 12 | "moduleResolution": "node", 13 | "resolveJsonModule": true, 14 | "isolatedModules": true, 15 | "jsx": "preserve", 16 | "incremental": true, 17 | "plugins": [ 18 | { 19 | "name": "next" 20 | } 21 | ], 22 | "paths": { 23 | "@/*": ["./src/*"] 24 | } 25 | }, 26 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], 27 | "exclude": ["node_modules"] 28 | } 29 | -------------------------------------------------------------------------------- /public/next.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # "Kinde Login Authentication & User Registration" 2 | 3 | ## With Next.js App Router 4 | 5 | --- 6 | 7 | ### Author Links 8 | 9 | 👋 Hello, I'm Dave Gray. 10 | 11 | 👉 [My Courses](https://courses.davegray.codes/) 12 | 13 | ✅ [Check out my YouTube Channel with hundreds of tutorials](https://www.youtube.com/DaveGrayTeachesCode). 14 | 15 | 🚩 [Subscribe to my channel](https://bit.ly/3nGHmNn) 16 | 17 | ☕ [Buy Me A Coffee](https://buymeacoffee.com/DaveGray) 18 | 19 | 🚀 Follow Me: 20 | 21 | - [Twitter](https://twitter.com/yesdavidgray) 22 | - [LinkedIn](https://www.linkedin.com/in/davidagray/) 23 | - [Blog](https://yesdavidgray.com) 24 | - [Reddit](https://www.reddit.com/user/DaveOnEleven) 25 | 26 | --- 27 | 28 | ### Description 29 | 30 | 📺 [YouTube Video](https://youtu.be/WtHQGlKGUrU) for this repository. 31 | 32 | --- 33 | 34 | ### 📚 References 35 | - 🔗 [Kinde Auth Official Site](https://bit.ly/dg-kinde) 36 | - 🔗 [Next.js Official Site](https://nextjs.org/) 37 | 38 | --- 39 | 40 | ### 🎓 Academic Honesty 41 | 42 | **DO NOT COPY FOR AN ASSIGNMENT** - Avoid plagiarism and adhere to the spirit of this [Academic Honesty Policy](https://www.freecodecamp.org/news/academic-honesty-policy/). 43 | 44 | --- 45 | 46 | ### ⚙ Free Web Dev Tools 47 | - 🔗 [Google Chrome Web Browser](https://google.com/chrome/) 48 | - 🔗 [Visual Studio Code (aka VS Code)](https://code.visualstudio.com/) 49 | - 🔗 [ES7 React Snippets](https://marketplace.visualstudio.com/items?itemName=dsznajder.es7-react-js-snippets) 50 | -------------------------------------------------------------------------------- /src/app/components/Navbar.tsx: -------------------------------------------------------------------------------- 1 | import Image from "next/image" 2 | import { 3 | getKindeServerSession, 4 | RegisterLink, 5 | LoginLink, 6 | LogoutLink, 7 | } from "@kinde-oss/kinde-auth-nextjs/server" 8 | 9 | export default function Navbar() { 10 | const { isAuthenticated, getUser } = getKindeServerSession() 11 | const user = getUser() 12 | 13 | return ( 14 | 49 | ) 50 | } --------------------------------------------------------------------------------