From 8272bdb3d962977f475aae69e215bcba29d6cf24 Mon Sep 17 00:00:00 2001 From: Zoey Date: Mon, 13 Nov 2023 16:46:02 +0100 Subject: [PATCH] feat: Revamp NuxtAuth Example to use sidebase and version `0.6.0` (#31) --- .editorconfig | 15 + .env.example | 4 +- .eslintignore | 11 + .eslintrc | 33 + .github/workflows/ci.yaml | 47 +- .gitignore | 1 + .npmrc | 3 + .vscode/extensions.json | 8 + .vscode/settings.json | 30 + Dockerfile | 11 +- app.vue | 12 +- components/AuthenticationStatus.vue | 48 +- components/Navbar.vue | 42 +- components/Protected.vue | 12 - components/Secret.vue | 18 +- components/Welcome.vue | 6 +- nuxt.config.ts | 27 +- package-lock.json | 18564 -------------------------- package.json | 24 +- pages/api-routes.vue | 58 +- pages/index.vue | 10 +- pages/protected/locally.vue | 6 +- pnpm-lock.yaml | 8979 +++++++++++++ server/api/auth/[...].ts | 81 +- server/api/healthz.ts | 8 +- tsconfig.json | 2 +- 26 files changed, 9308 insertions(+), 18752 deletions(-) create mode 100644 .editorconfig create mode 100644 .eslintignore create mode 100644 .eslintrc create mode 100644 .npmrc create mode 100644 .vscode/extensions.json create mode 100644 .vscode/settings.json delete mode 100644 components/Protected.vue delete mode 100644 package-lock.json create mode 100644 pnpm-lock.yaml diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..9493167 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +trim_trailing_whitespace = true +insert_final_newline = true + +[**.{json,js,ts,y{a,}ml}] +indent_style = space +indent_size = 2 + +[*.md] +indent_style = space +indent_size = 4 diff --git a/.env.example b/.env.example index d1ea532..b220599 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,6 @@ GITHUB_CLIENT_ID="YOUR_GIHUB_APPLICATION_ID" GITHUB_CLIENT_SECRET="YOUR_GIHUB_APPLICATION_SECRET" -NUXT_SECRET="YOUR_NUXT_SECRET" -ORIGIN="YOUR_ORIGIN" +AUTH_SECRET="YOUR_NUXT_SECRET" +AUTH_ORIGIN="YOUR_ORIGIN" CERTBOT_DOMAIN="YOUR_DOMAIN" CERTBOT_EMAIL="YOUR_ADMIN_EMAIL" diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..83aefd4 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,11 @@ +# ignore generate imports +auto-imports.d.ts +components.d.ts +nuxt.d.ts + +# nuxt and other artefacts +.nuxt +.output +node_modules +dist +public diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..919a5d7 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,33 @@ +{ + "root": true, + "env": { + "browser": true, + "node": true + }, + "extends": [ + "@nuxtjs/eslint-config-typescript" + ], + "rules": { + "vue/multi-word-component-names": "off" + }, + "overrides": [ + { + "files": [ + "./server/**/*.ts" + ], + "rules": { + "no-console": [ + "error", + { + "allow": [ + "info", + "warn", + "trace", + "error" + ] + } + ] + } + } + ] +} diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5169e64..a704b05 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,30 +1,53 @@ -name: nodejs CI + +name: CI on: push: - branches: [main] + branches: [ main ] pull_request: - branches: [main] + branches: [ main ] jobs: - test: + lint: + runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + + - name: Use Node.js 16.14.2 + uses: actions/setup-node@v3 + with: + node-version: 16.14.2 + + - name: Setup + run: npm i -g @antfu/ni + + - name: Install + run: nci + + - name: Lint + run: nr lint + + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Use Node.js 16.14.2 uses: actions/setup-node@v3 with: node-version: 16.14.2 - # Install locked dependencies and prepare types - - run: npm ci + - name: Setup + run: npm i -g @antfu/ni - # Check building - - run: npm run build + - name: Install + run: nci - # start dev-app and curl from it - - run: "timeout 30 npm run dev & (sleep 10 && curl --fail localhost:3000)" + - name: Build + run: nr build - # start prod-app and curl from it - - run: "timeout 30 npm run start & (sleep 10 && curl --fail localhost:3000)" + # TODO: Add more steps here, like "nr test" as you add the tooling for it diff --git a/.gitignore b/.gitignore index 438cb08..268f90a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ node_modules .output .env dist +*.sqlite diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..50e522c --- /dev/null +++ b/.npmrc @@ -0,0 +1,3 @@ + +shamefully-hoist=true +strict-peer-dependencies=false diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..880d961 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,8 @@ +{ + "recommendations": [ + "editorconfig.editorconfig", + "dbaeumer.vscode-eslint", + "vue.volar", + "bradlc.vscode-tailwindcss" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..1719b8d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,30 @@ +{ + // Use `eslint` for vue, ts and js + "editor.codeActionsOnSave": { + "source.fixAll.eslint": true + }, + "[vue]": { + "editor.defaultFormatter": "dbaeumer.vscode-eslint" + }, + "[js]": { + "editor.defaultFormatter": "dbaeumer.vscode-eslint" + }, + "[ts]": { + "editor.defaultFormatter": "dbaeumer.vscode-eslint" + }, + "[typescript]": { + "editor.defaultFormatter": "dbaeumer.vscode-eslint" + }, + "eslint.validate": [ + "javascript", + "typescript", + "vue" + ], + // Tailwind Support, see https://tailwindcss.nuxt.dev/tailwind/editor-support + "tailwindCSS.experimental.configFile": ".nuxt/tailwind.config.cjs", + "files.associations": { + "*.css": "tailwindcss" + }, + // Auto-complete `.value` attribute when volar is installed + "volar.autoCompleteRefs": true, +} diff --git a/Dockerfile b/Dockerfile index 0a28ee5..8d2bfdc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,26 @@ # see https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact -ARG NODE_VERSION=node:16.14.2 +ARG NODE_VERSION=node:20.6.1 FROM $NODE_VERSION AS dependency-base +# install pnpm +RUN npm i -g pnpm + # create destination directory RUN mkdir -p /app WORKDIR /app # copy the app, note .dockerignore COPY package.json . -COPY package-lock.json . -RUN npm ci +COPY pnpm-lock.yaml . +RUN pnpm i FROM dependency-base AS production-base # build will also take care of building # if necessary COPY . . -RUN npm run build +RUN pnpm build FROM $NODE_VERSION-slim AS production diff --git a/app.vue b/app.vue index 4192e05..cedbb0e 100644 --- a/app.vue +++ b/app.vue @@ -1,3 +1,9 @@ + + - - diff --git a/components/AuthenticationStatus.vue b/components/AuthenticationStatus.vue index 00096e1..a7869e8 100644 --- a/components/AuthenticationStatus.vue +++ b/components/AuthenticationStatus.vue @@ -1,31 +1,31 @@ diff --git a/components/Navbar.vue b/components/Navbar.vue index dff8a49..9881385 100644 --- a/components/Navbar.vue +++ b/components/Navbar.vue @@ -4,36 +4,36 @@ 🔐 nuxt-auth -