From 8acc460bf74dea0b22c1e98767f1301ffc29dddb Mon Sep 17 00:00:00 2001 From: williamschen23 Date: Sat, 16 Nov 2024 16:59:44 -0500 Subject: [PATCH 1/6] add linting --- .eslintrc.json | 24 +++++++++++++++++++++++- package-lock.json | 2 ++ package.json | 15 +++++++++------ src/app/layout.tsx | 20 ++++++++++---------- src/app/page.tsx | 10 +++++----- 5 files changed, 49 insertions(+), 22 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 3722418..6d7cdc1 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,3 +1,25 @@ { - "extends": ["next/core-web-vitals", "next/typescript"] + "parser": "@typescript-eslint/parser", + "parserOptions": { + "project": "./tsconfig.json" + }, + "extends": [ + "next/core-web-vitals", + "next/typescript", + "eslint:recommended", + "plugin:@typescript-eslint/recommended", + "plugin:@typescript-eslint/recommended-requiring-type-checking" + ], + "rules": { + "no-unused-vars": "error", + "no-irregular-whitespace": "error", + "no-undef": "error", + "curly": "error", + "semi": "error", + "no-trailing-spaces": "error", + "indent": ["error", 4] + }, + "globals": { + "React": true + } } diff --git a/package-lock.json b/package-lock.json index c0b4fa5..55f1763 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,8 @@ "@types/node": "^20", "@types/react": "^18", "@types/react-dom": "^18", + "@typescript-eslint/eslint-plugin": "^8.14.0", + "@typescript-eslint/parser": "^8.14.0", "eslint": "^8", "eslint-config-next": "15.0.3", "postcss": "^8", diff --git a/package.json b/package.json index 4633ac9..234a729 100644 --- a/package.json +++ b/package.json @@ -6,21 +6,24 @@ "dev": "next dev", "build": "next build", "start": "next start", - "lint": "next lint" + "lint": "next lint", + "lint:fix": "next lint --fix" }, "dependencies": { + "next": "15.0.3", "react": "19.0.0-rc-66855b96-20241106", - "react-dom": "19.0.0-rc-66855b96-20241106", - "next": "15.0.3" + "react-dom": "19.0.0-rc-66855b96-20241106" }, "devDependencies": { - "typescript": "^5", "@types/node": "^20", "@types/react": "^18", "@types/react-dom": "^18", + "@typescript-eslint/eslint-plugin": "^8.14.0", + "@typescript-eslint/parser": "^8.14.0", + "eslint": "^8", + "eslint-config-next": "15.0.3", "postcss": "^8", "tailwindcss": "^3.4.1", - "eslint": "^8", - "eslint-config-next": "15.0.3" + "typescript": "^5" } } diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 4fafd86..3bc63d4 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,20 +1,20 @@ import type { Metadata } from "next"; export const metadata: Metadata = { - title: "Create Next App", - description: "Generated by create next app", + title: "Create Next App", + description: "Generated by create next app", }; export default function RootLayout({ - children, + children, }: Readonly<{ children: React.ReactNode; }>) { - return ( - - - {children} - - - ); + return ( + + + {children} + + + ); } diff --git a/src/app/page.tsx b/src/app/page.tsx index 2ad4061..929efff 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,12 +1,12 @@ import { Metadata } from "next"; export const metadata: Metadata = { - title: "Create Next App", - description: "Generated by create next app", + title: "Create Next App", + description: "Generated by create next app", }; export default function Home() { - return ( -

Hello World

- ); + return ( +

Hello World

+ ); } From 40d53930713e4cb4efce3f8bd6ceda7f082ef3c0 Mon Sep 17 00:00:00 2001 From: williamschen23 Date: Sun, 17 Nov 2024 13:50:27 -0500 Subject: [PATCH 2/6] add single quotes --- .eslintrc.json | 3 ++- src/app/layout.tsx | 6 +++--- src/app/page.tsx | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 6d7cdc1..65b29d6 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -17,7 +17,8 @@ "curly": "error", "semi": "error", "no-trailing-spaces": "error", - "indent": ["error", 4] + "indent": ["error", 4], + "quotes": ["error", "single"] }, "globals": { "React": true diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 3bc63d4..7880356 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,8 +1,8 @@ -import type { Metadata } from "next"; +import type { Metadata } from 'next'; export const metadata: Metadata = { - title: "Create Next App", - description: "Generated by create next app", + title: 'Create Next App', + description: 'Generated by create next app', }; export default function RootLayout({ diff --git a/src/app/page.tsx b/src/app/page.tsx index 929efff..63086f6 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,8 +1,8 @@ -import { Metadata } from "next"; +import { Metadata } from 'next'; export const metadata: Metadata = { - title: "Create Next App", - description: "Generated by create next app", + title: 'Create Next App', + description: 'Generated by create next app', }; export default function Home() { From 12f6a0e3241d68b6826de3f23a63c59e8acdf89d Mon Sep 17 00:00:00 2001 From: williamschen23 Date: Sun, 17 Nov 2024 13:58:10 -0500 Subject: [PATCH 3/6] add space-before-blocks --- .eslintrc.json | 3 ++- src/app/page.tsx | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.eslintrc.json b/.eslintrc.json index 65b29d6..5e3ed86 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -18,7 +18,8 @@ "semi": "error", "no-trailing-spaces": "error", "indent": ["error", 4], - "quotes": ["error", "single"] + "quotes": ["error", "single"], + "space-before-blocks": "error" }, "globals": { "React": true diff --git a/src/app/page.tsx b/src/app/page.tsx index 63086f6..c0c2d66 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -6,6 +6,9 @@ export const metadata: Metadata = { }; export default function Home() { + if (metadata.title) { + return true; + } return (

Hello World

); From 77e17187f677de27247a31d9f4d6aba2a816cfe8 Mon Sep 17 00:00:00 2001 From: williamschen23 Date: Sun, 17 Nov 2024 14:19:28 -0500 Subject: [PATCH 4/6] remove and update eslint config --- .eslintrc.json | 3 +- src/app/api/auth/[...nextauth]/options.ts | 35 ++++++++++++----------- src/app/api/auth/[...nextauth]/route.ts | 9 +++--- src/app/profile/page.tsx | 12 ++++---- src/middleware.ts | 4 +-- 5 files changed, 32 insertions(+), 31 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 5e3ed86..4e69492 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -7,8 +7,7 @@ "next/core-web-vitals", "next/typescript", "eslint:recommended", - "plugin:@typescript-eslint/recommended", - "plugin:@typescript-eslint/recommended-requiring-type-checking" + "plugin:@typescript-eslint/recommended" ], "rules": { "no-unused-vars": "error", diff --git a/src/app/api/auth/[...nextauth]/options.ts b/src/app/api/auth/[...nextauth]/options.ts index d40dc7d..00f1836 100644 --- a/src/app/api/auth/[...nextauth]/options.ts +++ b/src/app/api/auth/[...nextauth]/options.ts @@ -1,31 +1,32 @@ -import type { NextAuthOptions } from "next-auth"; -import CredentialsProvider from "next-auth/providers/credentials"; +import type { NextAuthOptions } from 'next-auth'; +import CredentialsProvider from 'next-auth/providers/credentials'; export const options: NextAuthOptions = { providers: [ CredentialsProvider({ - name: "Credentials", + name: 'Credentials', credentials: { username: { - label: "Username:", - type: "text", - placeholder: "dev" + label: 'Username:', + type: 'text', + placeholder: 'dev' }, password: { - label: "Password:", - type: "text", - placeholder: "dev" + label: 'Password:', + type: 'text', + placeholder: 'dev' } - }, + }, - async authorize(credentials) { + // change this to await/async once we get a db + authorize(credentials) { const user = { - id: "1", - name: "dev", - password: "dev" - } + id: '1', + name: 'dev', + password: 'dev' + }; - if(credentials?.username === user.name && credentials?.password === user.password){ + if(credentials?.username === user.name && credentials?.password === user.password) { return user; } @@ -33,4 +34,4 @@ export const options: NextAuthOptions = { } }) ], -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/app/api/auth/[...nextauth]/route.ts b/src/app/api/auth/[...nextauth]/route.ts index c5d4fe3..08847a0 100644 --- a/src/app/api/auth/[...nextauth]/route.ts +++ b/src/app/api/auth/[...nextauth]/route.ts @@ -1,6 +1,7 @@ -import NextAuth from "next-auth"; -import { options } from "./options"; +import NextAuth from 'next-auth'; +import { options } from './options'; +import { NextApiHandler } from 'next'; -const handler = NextAuth(options); +const handler: NextApiHandler = NextAuth(options); -export { handler as GET, handler as POST } \ No newline at end of file +export { handler as GET, handler as POST }; \ No newline at end of file diff --git a/src/app/profile/page.tsx b/src/app/profile/page.tsx index 02d2858..2b526a2 100644 --- a/src/app/profile/page.tsx +++ b/src/app/profile/page.tsx @@ -1,15 +1,15 @@ -import { getServerSession } from "next-auth"; -import { options } from "../api/auth/[...nextauth]/options"; -import { redirect } from "next/navigation"; +import { getServerSession } from 'next-auth'; +import { options } from '../api/auth/[...nextauth]/options'; +import { redirect } from 'next/navigation'; export default async function ProfilePage() { const session = await getServerSession(options); - if(!session){ + if(!session) { redirect('/api/auth/signin?callbackUrl=/profile'); } - + return (

Hello {session.user?.name}

- ) + ); } \ No newline at end of file diff --git a/src/middleware.ts b/src/middleware.ts index 0ca12c3..b0b2311 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -1,5 +1,5 @@ -export { default } from "next-auth/middleware" +export { default } from 'next-auth/middleware'; export const config = { matcher: ['/profile'] -} \ No newline at end of file +}; \ No newline at end of file From 37cb82dc60baafaacdd03647b44b3dbf491f42db Mon Sep 17 00:00:00 2001 From: williamschen23 Date: Sun, 17 Nov 2024 14:45:19 -0500 Subject: [PATCH 5/6] readd type checking --- .eslintrc.json | 3 ++- src/app/api/auth/[...nextauth]/route.ts | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 4e69492..5e3ed86 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -7,7 +7,8 @@ "next/core-web-vitals", "next/typescript", "eslint:recommended", - "plugin:@typescript-eslint/recommended" + "plugin:@typescript-eslint/recommended", + "plugin:@typescript-eslint/recommended-requiring-type-checking" ], "rules": { "no-unused-vars": "error", diff --git a/src/app/api/auth/[...nextauth]/route.ts b/src/app/api/auth/[...nextauth]/route.ts index 08847a0..db3aa2e 100644 --- a/src/app/api/auth/[...nextauth]/route.ts +++ b/src/app/api/auth/[...nextauth]/route.ts @@ -1,7 +1,8 @@ import NextAuth from 'next-auth'; -import { options } from './options'; +import { options } from '@/app/api/auth/[...nextauth]/options'; import { NextApiHandler } from 'next'; -const handler: NextApiHandler = NextAuth(options); -export { handler as GET, handler as POST }; \ No newline at end of file +const handler = NextAuth(options) as NextApiHandler; + +export { handler as GET, handler as POST }; From db2ad0fc105e9ad669a5c81a5fb0c3948fc2d2cb Mon Sep 17 00:00:00 2001 From: williamschen23 Date: Mon, 18 Nov 2024 00:16:32 -0500 Subject: [PATCH 6/6] remove testing code --- src/app/page.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/app/page.tsx b/src/app/page.tsx index c0c2d66..63086f6 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -6,9 +6,6 @@ export const metadata: Metadata = { }; export default function Home() { - if (metadata.title) { - return true; - } return (

Hello World

);