diff --git a/apps/alakazam/nuxt.config.ts b/apps/alakazam/nuxt.config.ts index f12646f..92ecc16 100644 --- a/apps/alakazam/nuxt.config.ts +++ b/apps/alakazam/nuxt.config.ts @@ -10,6 +10,7 @@ export default defineNuxtConfig({ modules: [ 'nuxt-typed-router', + 'nuxt-auth-utils', ], alias: { @@ -38,4 +39,13 @@ export default defineNuxtConfig({ build: { transpile: ['fsevents'], }, + + runtimeConfig: { + oauth: { + github: { + clientId: process.env.NUXT_OAUTH_GITHUB_CLIENT_ID, + clientSecret: process.env.NUXT_OAUTH_GITHUB_CLIENT_SECRET, + } + } + } }) diff --git a/apps/alakazam/package.json b/apps/alakazam/package.json index c602bb6..f2060ab 100644 --- a/apps/alakazam/package.json +++ b/apps/alakazam/package.json @@ -18,6 +18,7 @@ "eslint-plugin-vue": "^9.17.0", "glob": "^10.3.4", "nuxt": "^3.7.1", + "nuxt-auth-utils": "^0.0.5", "nuxt-typed-router": "^3.3.1" } } diff --git a/apps/alakazam/src/features/auth/pages/login.vue b/apps/alakazam/src/features/auth/pages/login.vue new file mode 100644 index 0000000..d83885f --- /dev/null +++ b/apps/alakazam/src/features/auth/pages/login.vue @@ -0,0 +1,66 @@ + + + diff --git a/apps/alakazam/src/features/auth/routes.ts b/apps/alakazam/src/features/auth/routes.ts new file mode 100644 index 0000000..1731299 --- /dev/null +++ b/apps/alakazam/src/features/auth/routes.ts @@ -0,0 +1,9 @@ +import { defineNuxtRoutes } from "~/shared/utils/define-nuxt-routes"; + +export default defineNuxtRoutes(__dirname, [ + { + name: 'login-page', + path: '/login', + file: './pages/login.vue', + }, +]) diff --git a/apps/alakazam/src/server/api/auth/github.get.ts b/apps/alakazam/src/server/api/auth/github.get.ts new file mode 100644 index 0000000..9171205 --- /dev/null +++ b/apps/alakazam/src/server/api/auth/github.get.ts @@ -0,0 +1,32 @@ +export default oauth.githubEventHandler({ + config: { + scope: ['repo'], + }, + async onSuccess(event, data) { + await setUserSession(event, { + user: { + provider: 'github', + token: data.tokens.access_token, + id: data.user.id, + login: data.user.login, + name: data.user.name, + avatarUrl: data.user.avatar_url, + }, + loggedInAt: Date.now(), + }) + + setResponseHeaders(event, { + 'content-type': 'text/html', + }) + return ` + + ` as never as void + } +}) \ No newline at end of file diff --git a/apps/alakazam/src/server/tsconfig.json b/apps/alakazam/src/server/tsconfig.json index b9ed69c..3c6e968 100644 --- a/apps/alakazam/src/server/tsconfig.json +++ b/apps/alakazam/src/server/tsconfig.json @@ -1,3 +1,3 @@ { - "extends": "../.nuxt/tsconfig.server.json" + "extends": "../../.nuxt/tsconfig.server.json" } diff --git a/apps/alakazam/src/types/auth.d.ts b/apps/alakazam/src/types/auth.d.ts new file mode 100644 index 0000000..2806586 --- /dev/null +++ b/apps/alakazam/src/types/auth.d.ts @@ -0,0 +1,15 @@ +declare module '#auth-utils' { + interface UserSession { + loggedInAt: number + user: ( + | { + provider: 'github' + token: string + id: number + login: string + name: string + avatarUrl: string + } + ) + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e3e8fc6..80b30e5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -75,6 +75,9 @@ importers: nuxt: specifier: ^3.7.1 version: 3.8.1(@types/node@20.4.7)(eslint@8.46.0)(rollup@3.29.3)(typescript@5.2.2)(vite@4.5.0) + nuxt-auth-utils: + specifier: ^0.0.5 + version: 0.0.5(rollup@3.29.3) nuxt-typed-router: specifier: ^3.3.1 version: 3.3.3(rollup@3.29.3) @@ -961,7 +964,7 @@ packages: astro: ^2.5.0 dependencies: '@astrojs/prism': 2.1.2 - astro: 2.9.6(@types/node@18.18.0) + astro: 2.9.6(@types/node@20.4.7) github-slugger: 1.5.0 import-meta-resolve: 2.2.2 rehype-raw: 6.1.1 @@ -1149,7 +1152,7 @@ packages: resolution: {integrity: sha512-QkBXwGgaoC2GtGZRoma6kv7Szfv06khvhFav67ZExau2RaXzy8MpHSMO2PNoP2XtmQphJQRHFfg77Bq731Yizw==} engines: {node: '>=6.9.0'} dependencies: - '@babel/types': 7.23.0 + '@babel/types': 7.23.3 dev: true /@babel/helper-compilation-targets@7.22.15: @@ -1254,7 +1257,7 @@ packages: resolution: {integrity: sha512-HBwaojN0xFRx4yIvpwGqxiV2tUfl7401jlok564NgB9EHS1y6QT17FmKWm4ztqjeVdXLuC4fSvHc5ePpQjoTbw==} engines: {node: '>=6.9.0'} dependencies: - '@babel/types': 7.23.0 + '@babel/types': 7.23.3 dev: true /@babel/helper-plugin-utils@7.22.5: @@ -1295,7 +1298,7 @@ packages: resolution: {integrity: sha512-tK14r66JZKiC43p8Ki33yLBVJKlQDFoA8GYN67lWCDCqoL6EMMSuM9b+Iff2jHaM/RRFYl7K+iiru7hbRqNx8Q==} engines: {node: '>=6.9.0'} dependencies: - '@babel/types': 7.23.0 + '@babel/types': 7.23.3 dev: true /@babel/helper-split-export-declaration@7.22.6: @@ -1322,7 +1325,7 @@ packages: dependencies: '@babel/helper-function-name': 7.23.0 '@babel/template': 7.22.15 - '@babel/types': 7.23.0 + '@babel/types': 7.23.3 dev: true /@babel/helpers@7.23.1: @@ -2347,7 +2350,7 @@ packages: dependencies: '@babel/core': 7.23.0 '@babel/helper-plugin-utils': 7.22.5 - '@babel/types': 7.23.0 + '@babel/types': 7.23.3 esutils: 2.0.3 dev: true @@ -3449,14 +3452,9 @@ packages: eslint: 8.46.0 eslint-visitor-keys: 3.4.3 - /@eslint-community/regexpp@4.8.1: - resolution: {integrity: sha512-PWiOzLIUAjN/w5K17PoF4n6sKBw0gqLHPhywmYHP4t1VFQQVYeb1yWsJwnMVEMl3tUHME7X/SJPZLmtG7XBDxQ==} - engines: {node: ^12.0.0 || ^14.0.0 || >=16.0.0} - /@eslint-community/regexpp@4.9.1: resolution: {integrity: sha512-Y27x+MBLjXa+0JWDhykM3+JE+il3kHKAEqabfEWq3SDhZjLYb6/BHL/JKFnH3fe207JaXkyDo685Oc2Glt6ifA==} engines: {node: ^12.0.0 || ^14.0.0 || >=16.0.0} - dev: true /@eslint/eslintrc@2.1.2: resolution: {integrity: sha512-+wvgpDsrB1YqAMdEUCcnTlpfVBH7Vqn6A/NT3D8WVXFIaKMlErPIZT3oCIAVCOtarRpMtelZLqJeU3t7WY6X6g==} @@ -4610,7 +4608,7 @@ packages: engines: {node: ^12.20.0 || ^14.18.0 || >=16.0.0} dependencies: cross-spawn: 7.0.3 - fast-glob: 3.3.1 + fast-glob: 3.3.2 is-glob: 4.0.3 open: 9.1.0 picocolors: 1.0.0 @@ -6605,7 +6603,7 @@ packages: /@ts-morph/common@0.20.0: resolution: {integrity: sha512-7uKjByfbPpwuzkstL3L5MQyuXPSKdoNG93Fmi2JoDcTf3pEP731JdRFAduRVkOs8oqxPsXKA+ScrWkdQ8t/I+Q==} dependencies: - fast-glob: 3.3.1 + fast-glob: 3.3.2 minimatch: 7.4.6 mkdirp: 2.1.6 path-browserify: 1.0.1 @@ -6788,7 +6786,7 @@ packages: /@types/http-proxy@1.17.14: resolution: {integrity: sha512-SSrD0c1OQzlFX7pGu1eXxSEjemej64aaNPRhhVYUGqXh0BtldAAx37MG8btcumvpgKyZp1F5Gn3JkktdxiFv6w==} dependencies: - '@types/node': 18.18.0 + '@types/node': 20.4.7 dev: true /@types/ink-spinner@3.0.2: @@ -7262,7 +7260,7 @@ packages: dependencies: '@mapbox/node-pre-gyp': 1.0.11(encoding@0.1.13) '@rollup/pluginutils': 4.2.1 - acorn: 8.10.0 + acorn: 8.11.2 async-sema: 3.1.1 bindings: 1.5.0 estree-walker: 2.0.2 @@ -8591,7 +8589,7 @@ packages: resolution: {integrity: sha512-Q0DjXK4ApbVoIf9GLyCo252tUH44iTnD/hiJ2TQaJeydYWSpKk0sI34+WMel8S9Wt5pbLgG02oJ+gkgX5DV3sQ==} engines: {node: '>=16.14.0'} dependencies: - '@babel/parser': 7.23.0 + '@babel/parser': 7.23.3 '@rollup/pluginutils': 5.0.4(rollup@3.29.3) pathe: 1.1.1 transitivePeerDependencies: @@ -8788,6 +8786,7 @@ packages: - sugarss - supports-color - terser + dev: false /astro@2.9.6(@types/node@20.4.7): resolution: {integrity: sha512-yvbZQ6YOWYLejyQ4nAcgZLDYQ34enQJ5/LWlXKtUzXzpsUHB75vJMj+XmEq5Q2eVlZOlQrp0lU+nhSRGaOsOUQ==} @@ -8866,7 +8865,6 @@ packages: - sugarss - supports-color - terser - dev: true /async-limiter@1.0.1: resolution: {integrity: sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==} @@ -10195,7 +10193,6 @@ packages: /defu@6.1.3: resolution: {integrity: sha512-Vy2wmG3NTkmHNg/kzpuvHhkqeIx3ODWqasgCRbKtbXEN0G+HpEEv9BtJLp7ZG1CZloFaC41Ah3ZFbq7aqCqMeQ==} - dev: true /del@6.1.1: resolution: {integrity: sha512-ua8BhapfP0JUJKC/zV9yHHDW/rDoDxP4Zhn3AkA6/xT6gY7jYXJiaeyBZznYVujhZZET+UgcbZiQ7sN3WqcImg==} @@ -10231,12 +10228,8 @@ packages: resolution: {integrity: sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==} engines: {node: '>=6'} - /destr@2.0.1: - resolution: {integrity: sha512-M1Ob1zPSIvlARiJUkKqvAZ3VAqQY6Jcuth/pBKQ2b1dX/Qx0OnJ8Vux6J2H5PTMQeRzWrrbTu70VxBfv/OPDJA==} - /destr@2.0.2: resolution: {integrity: sha512-65AlobnZMiCET00KaFFjUefxDX0khFA/E4myqZ7a6Sq1yZtR8+FVIvilVX66vF2uobSumxooYZChiRPCKNqhmg==} - dev: true /destroy@1.2.0: resolution: {integrity: sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==} @@ -10436,6 +10429,7 @@ packages: /encoding@0.1.13: resolution: {integrity: sha512-ETBauow1T35Y/WZMkio9jiM0Z5xjHHmJ4XmjZOq1l/dXz3lr2sRn87nJy20RupqSh1F2m3HHPSp8ShIPQJrJ3A==} + requiresBuild: true dependencies: iconv-lite: 0.6.3 @@ -11334,7 +11328,7 @@ packages: hasBin: true dependencies: '@eslint-community/eslint-utils': 4.4.0(eslint@8.46.0) - '@eslint-community/regexpp': 4.8.1 + '@eslint-community/regexpp': 4.9.1 '@eslint/eslintrc': 2.1.2 '@eslint/js': 8.50.0 '@humanwhocodes/config-array': 0.11.11 @@ -11610,7 +11604,6 @@ packages: glob-parent: 5.1.2 merge2: 1.4.1 micromatch: 4.0.5 - dev: true /fast-json-stable-stringify@2.1.0: resolution: {integrity: sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==} @@ -12552,6 +12545,7 @@ packages: /iconv-lite@0.6.3: resolution: {integrity: sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==} engines: {node: '>=0.10.0'} + requiresBuild: true dependencies: safer-buffer: 2.1.2 @@ -13502,7 +13496,7 @@ packages: get-port-please: 3.1.1 h3: 1.8.2 http-shutdown: 1.2.2 - jiti: 1.20.0 + jiti: 1.21.0 mlly: 1.4.2 node-forge: 1.3.1 pathe: 1.1.1 @@ -14657,7 +14651,7 @@ packages: hookable: 5.5.3 httpxy: 0.1.5 is-primitive: 3.0.1 - jiti: 1.20.0 + jiti: 1.21.0 klona: 2.0.6 knitwork: 1.0.0 listhen: 1.5.5 @@ -14957,6 +14951,18 @@ packages: fsevents: 2.3.3 dev: true + /nuxt-auth-utils@0.0.5(rollup@3.29.3): + resolution: {integrity: sha512-ww8AMJvEXN7DI4G8pEeP8zPU7ntYvM6tKnmbkIOQK2VafIpsDTxUnwauRBp+CErRfabU4MZEaRw5wTEYfaGu5Q==} + dependencies: + '@nuxt/kit': 3.8.1(rollup@3.29.3) + defu: 6.1.3 + ofetch: 1.3.3 + ohash: 1.1.3 + transitivePeerDependencies: + - rollup + - supports-color + dev: true + /nuxt-typed-router@3.3.3(rollup@3.29.3): resolution: {integrity: sha512-v+A91u9Gg72NJsDByUsGjZ1JNR49Iat5SQEiLEDli/yArkQDhPp5qRodQI8t5TYmcQQytOeFH+4a+RgPMuDUlg==} dependencies: @@ -16310,8 +16316,8 @@ packages: /rc9@2.1.1: resolution: {integrity: sha512-lNeOl38Ws0eNxpO3+wD1I9rkHGQyj1NU1jlzv4go2CtEnEQEUfqnIvZG7W+bC/aXdJ27n5x/yUjb6RoT9tko+Q==} dependencies: - defu: 6.1.2 - destr: 2.0.1 + defu: 6.1.3 + destr: 2.0.2 flat: 5.0.2 /rc@1.2.8: @@ -17028,6 +17034,7 @@ packages: /safer-buffer@2.1.2: resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==} + requiresBuild: true /sass-formatter@0.7.8: resolution: {integrity: sha512-7fI2a8THglflhhYis7k06eUf92VQuJoXzEs2KRP0r1bluFxKFvLx0Ns7c478oYGM0fPfrr846ZRWVi2MAgHt9Q==} @@ -17803,7 +17810,7 @@ packages: hasBin: true dependencies: '@jridgewell/source-map': 0.3.5 - acorn: 8.10.0 + acorn: 8.11.2 commander: 2.20.3 source-map-support: 0.5.21 dev: true @@ -18681,7 +18688,7 @@ packages: '@babel/core': 7.23.0 '@babel/standalone': 7.23.1 '@babel/types': 7.23.0 - defu: 6.1.2 + defu: 6.1.3 jiti: 1.20.0 mri: 1.2.0 scule: 1.0.0 @@ -18937,7 +18944,7 @@ packages: chokidar: 3.5.3 commander: 8.3.0 eslint: 8.46.0 - fast-glob: 3.3.1 + fast-glob: 3.3.2 fs-extra: 11.1.1 lodash.debounce: 4.0.8 lodash.pick: 4.4.0 @@ -19148,7 +19155,6 @@ packages: rollup: 3.29.4 optionalDependencies: fsevents: 2.3.3 - dev: true /vitefu@0.2.4(vite@4.4.9): resolution: {integrity: sha512-fanAXjSaf9xXtOOeno8wZXIhgia+CZury481LsDaV++lSvcU2R9Ch2bPh3PYFyoHW+w9LqAeYRISVQjUIew14g==} @@ -19169,7 +19175,7 @@ packages: vite: optional: true dependencies: - vite: 4.5.0(@types/node@18.18.0) + vite: 4.5.0(@types/node@20.4.7) /vitest@0.34.5: resolution: {integrity: sha512-CPI68mmnr2DThSB3frSuE5RLm9wo5wU4fbDrDwWQQB1CWgq9jQVoQwnQSzYAjdoBOPoH2UtXpOgHVge/uScfZg==}