diff --git a/package.json b/package.json index 1216348..866ee79 100644 --- a/package.json +++ b/package.json @@ -16,8 +16,11 @@ "test:e2e": "playwright test" }, "dependencies": { + "@better-auth/drizzle-adapter": "^1.6.26", + "better-auth": "^1.6.26", "drizzle-orm": "^0.45.2", "next": "^16.3.0", + "nodemailer": "^9.0.5", "pg": "^8.22.0", "react": "^19.2.8", "react-dom": "^19.2.8", @@ -30,6 +33,7 @@ "@testing-library/jest-dom": "^7.0.0", "@testing-library/react": "^16.3.2", "@types/node": "^24.13.3", + "@types/nodemailer": "^8.0.1", "@types/pg": "^8.21.0", "@types/react": "^19.2.18", "@types/react-dom": "^19.2.4", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 25e8b18..2e7374c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,12 +8,21 @@ importers: .: dependencies: + '@better-auth/drizzle-adapter': + specifier: ^1.6.26 + version: 1.6.26(@better-auth/core@1.6.26(@better-auth/utils@0.4.2)(@better-fetch/fetch@1.3.1)(better-call@1.3.7(zod@4.4.3))(jose@6.2.8)(kysely@0.29.4)(nanostores@1.4.2))(@better-auth/utils@0.4.2)(drizzle-orm@0.45.2(@types/pg@8.21.0)(kysely@0.29.4)(pg@8.22.0)) + better-auth: + specifier: ^1.6.26 + version: 1.6.26(drizzle-kit@0.31.10)(drizzle-orm@0.45.2(@types/pg@8.21.0)(kysely@0.29.4)(pg@8.22.0))(next@16.3.0(@babel/core@7.29.7(supports-color@7.2.0))(@types/node@24.13.3)(react-dom@19.2.8(react@19.2.8))(react@19.2.8))(pg@8.22.0)(react-dom@19.2.8(react@19.2.8))(react@19.2.8)(vitest@4.1.10(@types/node@24.13.3)(jsdom@30.0.1(@noble/hashes@2.3.0))(vite@8.2.1(@types/node@24.13.3)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.23.11)(yaml@2.9.0))) drizzle-orm: specifier: ^0.45.2 - version: 0.45.2(@types/pg@8.21.0)(pg@8.22.0) + version: 0.45.2(@types/pg@8.21.0)(kysely@0.29.4)(pg@8.22.0) next: specifier: ^16.3.0 version: 16.3.0(@babel/core@7.29.7(supports-color@7.2.0))(@types/node@24.13.3)(react-dom@19.2.8(react@19.2.8))(react@19.2.8) + nodemailer: + specifier: ^9.0.5 + version: 9.0.5 pg: specifier: ^8.22.0 version: 8.22.0 @@ -45,6 +54,9 @@ importers: '@types/node': specifier: ^24.13.3 version: 24.13.3 + '@types/nodemailer': + specifier: ^8.0.1 + version: 8.0.1 '@types/pg': specifier: ^8.21.0 version: 8.21.0 @@ -68,7 +80,7 @@ importers: version: 16.3.0(@typescript-eslint/parser@8.66.0(eslint@9.39.5(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)(typescript@5.9.3))(eslint@9.39.5(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)(typescript@5.9.3) jsdom: specifier: ^30.0.1 - version: 30.0.1 + version: 30.0.1(@noble/hashes@2.3.0) tailwindcss: specifier: ^4.3.3 version: 4.3.3 @@ -80,7 +92,7 @@ importers: version: 5.9.3 vitest: specifier: ^4.1.10 - version: 4.1.10(@types/node@24.13.3)(jsdom@30.0.1)(vite@8.2.1(@types/node@24.13.3)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.23.11)(yaml@2.9.0)) + version: 4.1.10(@types/node@24.13.3)(jsdom@30.0.1(@noble/hashes@2.3.0))(vite@8.2.1(@types/node@24.13.3)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.23.11)(yaml@2.9.0)) packages: @@ -173,6 +185,88 @@ packages: '@balena/dockerignore@1.0.2': resolution: {integrity: sha512-wMue2Sy4GAVTk6Ic4tJVcnfdau+gx2EnG7S+uAEe+TWJFqE4YoWN4/H8MSLj4eYJKxGg26lZwboEniNiNwZQ6Q==} + '@better-auth/core@1.6.26': + resolution: {integrity: sha512-Ud4FqnjIJDvmeo+3bN+OsuVVAiuvFjNERbW7G8/65ictSxCox62gNgTOsJ4YXmbwXzBzyyekStzrupg2qNGEkA==} + peerDependencies: + '@better-auth/utils': 0.4.2 + '@better-fetch/fetch': 1.3.1 + '@cloudflare/workers-types': '>=4' + '@opentelemetry/api': ^1.9.0 + better-call: 1.3.7 + jose: ^6.1.0 + kysely: ^0.28.5 || ^0.29.0 + nanostores: ^1.0.1 + peerDependenciesMeta: + '@cloudflare/workers-types': + optional: true + '@opentelemetry/api': + optional: true + + '@better-auth/drizzle-adapter@1.6.26': + resolution: {integrity: sha512-SMvAeeUqEsz0BLtWVVp+HdStAVOwcxs4vPkL/AVmFJ0e9dDKItXl881xWeB/Ze4NgBW6NYmUId9qI4LrdQu3hA==} + peerDependencies: + '@better-auth/core': ^1.6.26 + '@better-auth/utils': 0.4.2 + drizzle-orm: ^0.45.2 + peerDependenciesMeta: + drizzle-orm: + optional: true + + '@better-auth/kysely-adapter@1.6.26': + resolution: {integrity: sha512-Y0Kdqn8JQMR8dHMtUnbBNqq7Mk8mDf18DwTves2uhjtRfcOWByVTGxsFMDVUbedMuoM+Ab+v04bwCk94sAo8NA==} + peerDependencies: + '@better-auth/core': ^1.6.26 + '@better-auth/utils': 0.4.2 + kysely: ^0.28.17 || ^0.29.0 + peerDependenciesMeta: + kysely: + optional: true + + '@better-auth/memory-adapter@1.6.26': + resolution: {integrity: sha512-kb5ahphEp9jyMleXU4T8I/xgWPa8gjOLFKKsnaVqR/BU+h7xqTOsjJwTY3evY+PFYHvjNFUlrjZ1Km8A/w1p/w==} + peerDependencies: + '@better-auth/core': ^1.6.26 + '@better-auth/utils': 0.4.2 + + '@better-auth/mongo-adapter@1.6.26': + resolution: {integrity: sha512-jYGhuIQqj48h69ROLPYdc8jgqDaMmRRLLFiRViZFYarNyBuYUV07DywJXvRuw8l9ADx+M1TB+BJZGnLE2nnmwQ==} + peerDependencies: + '@better-auth/core': ^1.6.26 + '@better-auth/utils': 0.4.2 + mongodb: ^6.0.0 || ^7.0.0 + peerDependenciesMeta: + mongodb: + optional: true + + '@better-auth/prisma-adapter@1.6.26': + resolution: {integrity: sha512-ILQoYmnoYyghDP4iN1h/Gkd9Jt7Xs/vxoNAt4AuuJJbqs73u27LlQM4P1YiP7nJ+bM1iVTBI1dDF73myIAtjzQ==} + peerDependencies: + '@better-auth/core': ^1.6.26 + '@better-auth/utils': 0.4.2 + '@prisma/client': ^5.0.0 || ^6.0.0 || ^7.0.0 + prisma: ^5.0.0 || ^6.0.0 || ^7.0.0 + peerDependenciesMeta: + '@prisma/client': + optional: true + prisma: + optional: true + + '@better-auth/telemetry@1.6.26': + resolution: {integrity: sha512-pBs69RORUSJHRF9r5PdeY7pzLRga09YSWew8igFYrBvT2tLt7DktrbD5WjryLZpAZOuKAMZ+Xo0DlJbnvLWGpQ==} + peerDependencies: + '@better-auth/core': ^1.6.26 + '@better-auth/utils': 0.4.2 + '@better-fetch/fetch': 1.3.1 + + '@better-auth/utils@0.4.2': + resolution: {integrity: sha512-AUxrvu+HaaODsUyzDxFgwd/8RZ1yZaYo42LXKSrU2oGgR38pS1ij8nqQKNgtTWoYGpNevNXtCfgTy6loHveW9A==} + + '@better-auth/utils@0.4.3': + resolution: {integrity: sha512-/X4gRYJBwRuLFjjANVpTDJJkAhLD6Sf8SIBypQ+Q2kDW1MnCsyxUujJzdKYsp59i4c41+AaMtpY/WQAQumqtOA==} + + '@better-fetch/fetch@1.3.1': + resolution: {integrity: sha512-ABkD1WhyfPZprKRQI3bhATjeiFuNWC9PXhfGWqL+sg/gKrM977oFrYkdb4msM3hgUGonr7KlOsOFT5TU2rht9g==} + '@bramus/specificity@2.4.2': resolution: {integrity: sha512-ctxtJ/eA+t+6q2++vj5j7FYX3nRu311q1wfYH3xjlLOsczhlhxAg2FWNUXhpGvAw3BWo1xBcvOV6/YLc2r5FJw==} hasBin: true @@ -1020,6 +1114,14 @@ packages: cpu: [x64] os: [win32] + '@noble/ciphers@2.3.0': + resolution: {integrity: sha512-Clu/xdfgVTf9o7ngLOURaxePwR0j8sjclKEtVij10/jGulwFsPWCvvRgG/XjUVf8Nei+jLG6uwyXzUTGY1DQrw==} + engines: {node: '>= 20.19.0'} + + '@noble/hashes@2.3.0': + resolution: {integrity: sha512-oN+QwyX7VSHotibwubG3kpzbwKrfnyR6OOO+3Nk/53ADL7FmgHHz4TgrbaYKvvOw09u6QTx0oiH1cNCIOuN0CQ==} + engines: {node: '>= 20.19.0'} + '@nodelib/fs.scandir@2.1.5': resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==} engines: {node: '>= 8'} @@ -1036,6 +1138,10 @@ packages: resolution: {integrity: sha512-nn5ozdjYQpUCZlWGuxcJY/KpxkWQs4DcbMCmKojjyrYDEAGy4Ce19NN4v5MduafTwJlbKc99UA8YhSVqq9yPZA==} engines: {node: '>=12.4.0'} + '@opentelemetry/semantic-conventions@1.43.0': + resolution: {integrity: sha512-eSYWTm620tTk45EKSedaUL8MFYI8hW164hIXsgIHyxu3VobUB3fFCu5t0hQby6OoWRPsG1KkKUG2M5UadiLiVg==} + engines: {node: '>=14'} + '@oxc-project/types@0.143.0': resolution: {integrity: sha512-u6JZdLBTLotrNC9Vd6vPssINdzcCzleKAH6EJKImQb7GtYvX5keN2dxkoK44stCc4tffE6QQRtZTXVSzsLUlWA==} @@ -1325,6 +1431,9 @@ packages: '@types/node@24.13.3': resolution: {integrity: sha512-Dh8vAsV36ig5wa9OX4pXvMc9D3Veibfw2wix0CUwYODLD8nkj9UsLjASr49nPg+2eKzxhBV+v7L8pXvT4e639Q==} + '@types/nodemailer@8.0.1': + resolution: {integrity: sha512-PxpaInm8V1JQDd4j0ds5HfvWQk8JupS1C0Picb96QJsrrRDjBH+DlK7L4ZdNSqNULhiZRQHc40nLVShaGxXAMw==} + '@types/pg@8.21.0': resolution: {integrity: sha512-AYdtudzabjLZgVgRZmAnU8bAnVUXzuJX2IYHeSIiIHm68olD+LgQYCGWdtcNYnP0uq9c4S4NibVG3Ni7VbKW7Q==} @@ -1748,6 +1857,76 @@ packages: bcrypt-pbkdf@1.0.2: resolution: {integrity: sha512-qeFIXtP4MSoi6NLqO12WfqARWWuCKi2Rn/9hJLEmtB5yTNr9DqFWkJRCf2qShWzPeAMRnOgCrq0sg/KLv5ES9w==} + better-auth@1.6.26: + resolution: {integrity: sha512-nhXWrDDj+EnZsHq1j0z1c6DowOMFZWZHe6LCaXbBfLIgHHZm6dyazBQcbRspM4spUIcUt250Mc1BFOSuP7eniQ==} + peerDependencies: + '@lynx-js/react': '*' + '@prisma/client': ^5.0.0 || ^6.0.0 || ^7.0.0 + '@sveltejs/kit': ^2.0.0 + '@tanstack/react-start': ^1.0.0 + '@tanstack/solid-start': ^1.0.0 + better-sqlite3: ^12.0.0 + drizzle-kit: '>=0.31.4' + drizzle-orm: ^0.45.2 + mongodb: ^6.0.0 || ^7.0.0 + mysql2: ^3.0.0 + next: ^14.0.0 || ^15.0.0 || ^16.0.0 + pg: ^8.0.0 + prisma: ^5.0.0 || ^6.0.0 || ^7.0.0 + react: ^18.0.0 || ^19.0.0 + react-dom: ^18.0.0 || ^19.0.0 + solid-js: ^1.0.0 + svelte: ^4.0.0 || ^5.0.0 + vitest: ^2.0.0 || ^3.0.0 || ^4.0.0 + vue: ^3.0.0 + peerDependenciesMeta: + '@lynx-js/react': + optional: true + '@prisma/client': + optional: true + '@sveltejs/kit': + optional: true + '@tanstack/react-start': + optional: true + '@tanstack/solid-start': + optional: true + better-sqlite3: + optional: true + drizzle-kit: + optional: true + drizzle-orm: + optional: true + mongodb: + optional: true + mysql2: + optional: true + next: + optional: true + pg: + optional: true + prisma: + optional: true + react: + optional: true + react-dom: + optional: true + solid-js: + optional: true + svelte: + optional: true + vitest: + optional: true + vue: + optional: true + + better-call@1.3.7: + resolution: {integrity: sha512-Al51/hjp2SSp6CRTa3F2ptcx4yQVS1xWKoY6jcVXqNYOap6mHFP2jUBn5EwIL4iIed1/Sq4hlQ+Umm6EflZG+w==} + peerDependencies: + zod: ^4.0.0 + peerDependenciesMeta: + zod: + optional: true + bidi-js@1.0.3: resolution: {integrity: sha512-RKshQI1R3YQ+n9YJz2QQ147P66ELpa1FQEg20Dk8oW9t2KgLbpDLLp9aGZ7y8WHSshDknG0bknqGw5/tyCs5tw==} @@ -1928,6 +2107,9 @@ packages: resolution: {integrity: sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg==} engines: {node: '>= 0.4'} + defu@6.1.7: + resolution: {integrity: sha512-7z22QmUWiQ/2d0KkdYmANbRUVABpZ9SNYyH5vx6PZ+nE5bcC0l7uFvEfHlyld/HcGBFTL536ClDt3DEcSlEJAQ==} + dequal@2.0.3: resolution: {integrity: sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==} engines: {node: '>=6'} @@ -2622,6 +2804,9 @@ packages: resolution: {integrity: sha512-AC/7JofJvZGrrneWNaEnJeOLUx+JlGt7tNa0wZiRPT4MY1wmfKjt2+6O2p2uz2+skll8OZZmJMNqeke7kKbNgQ==} hasBin: true + jose@6.2.8: + resolution: {integrity: sha512-Bsdjwm3Qsd/P0jR+BHDe3LytDfY7WBq2HmCCLIwuVRHMuEC9ae7/R474GIUdF1NgCyZjzVo/A9DOiOBtXq8ZoQ==} + js-tokens@4.0.0: resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==} @@ -2668,6 +2853,10 @@ packages: keyv@4.5.4: resolution: {integrity: sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==} + kysely@0.29.4: + resolution: {integrity: sha512-y5mVgQNkMbs1eK9Xyc0pmNdabN2wHhRYY/5r4W5HrUT1rYCEPeVNSj1RUJeSDKT3U0p+mXCvLgkrFuIafYI6BA==} + engines: {node: '>=22.0.0'} + language-subtag-registry@0.3.23: resolution: {integrity: sha512-0K65Lea881pHotoGEa5gDlMxt3pctLi2RplBb7Ezh4rRdLEOtgi7n4EwK9lamnUCkKBqaeKRVebTq6BAxSkpXQ==} @@ -2928,6 +3117,10 @@ packages: engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} hasBin: true + nanostores@1.4.2: + resolution: {integrity: sha512-Wxv8Roefr2nqtiRG0bnaFlpYqpIVtOEeJZHaH+4nGgOK1/7n6OHOuHCb/bhqrNQgZM8fyd0s1PqhdrJc9Ib44g==} + engines: {node: ^20.0.0 || >=22.0.0} + napi-postinstall@0.3.4: resolution: {integrity: sha512-PHI5f1O0EP5xJ9gQmFGMS6IZcrVvTjpXjz7Na41gTE7eE2hK11lg04CECCYEEjdc17EV4DO+fkGEtt7TpTaTiQ==} engines: {node: ^12.20.0 || ^14.18.0 || >=16.0.0} @@ -2965,6 +3158,10 @@ packages: resolution: {integrity: sha512-D9UOmYG3UH1V+ENW56t5QXBwJw1YEY18ruVeus89Rw+SyIgjPkCO84bRzO3uNIYosJbNwiabWVn48o3uJLjxFQ==} engines: {node: '>=18'} + nodemailer@9.0.5: + resolution: {integrity: sha512-wvjiKvjczmsN7U/8006JOdXubgBk2XFAbioDMbT+sM7cPs0QrhJTa6KBRX7P5REGGkDcLUz/EarWidb8G8C1jQ==} + engines: {node: '>=6.0.0'} + normalize-path@3.0.0: resolution: {integrity: sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==} engines: {node: '>=0.10.0'} @@ -3238,6 +3435,9 @@ packages: engines: {node: ^20.19.0 || >=22.12.0} hasBin: true + rou3@0.7.12: + resolution: {integrity: sha512-iFE4hLDuloSWcD7mjdCDhx2bKcIsYbtOTpfH5MHHLSKMOUyjqQXTeZVa289uuwEGEKFoE/BAPbhaU4B774nceg==} + run-parallel@1.2.0: resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==} @@ -3281,6 +3481,9 @@ packages: server-only@0.0.1: resolution: {integrity: sha512-qepMx2JxAa5jjfzxG79yPPq+8BuFToHd1hm7kI+Z4zAq1ftQiP7HcxMhDDItrbtwVeLg/cY2JnKnrcFkmiswNA==} + set-cookie-parser@3.1.2: + resolution: {integrity: sha512-5/r/lTwbJ3zQ+qwdUFZYeRNqda7P5HD8zQKqlSjdGt1/S0cjLAphHusj4Y58ahDtWn/g32xrIS58/ikOvwl0Lw==} + set-function-length@1.2.2: resolution: {integrity: sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==} engines: {node: '>= 0.4'} @@ -3925,6 +4128,63 @@ snapshots: '@balena/dockerignore@1.0.2': {} + '@better-auth/core@1.6.26(@better-auth/utils@0.4.2)(@better-fetch/fetch@1.3.1)(better-call@1.3.7(zod@4.4.3))(jose@6.2.8)(kysely@0.29.4)(nanostores@1.4.2)': + dependencies: + '@better-auth/utils': 0.4.2 + '@better-fetch/fetch': 1.3.1 + '@opentelemetry/semantic-conventions': 1.43.0 + '@standard-schema/spec': 1.1.0 + better-call: 1.3.7(zod@4.4.3) + jose: 6.2.8 + kysely: 0.29.4 + nanostores: 1.4.2 + zod: 4.4.3 + + '@better-auth/drizzle-adapter@1.6.26(@better-auth/core@1.6.26(@better-auth/utils@0.4.2)(@better-fetch/fetch@1.3.1)(better-call@1.3.7(zod@4.4.3))(jose@6.2.8)(kysely@0.29.4)(nanostores@1.4.2))(@better-auth/utils@0.4.2)(drizzle-orm@0.45.2(@types/pg@8.21.0)(kysely@0.29.4)(pg@8.22.0))': + dependencies: + '@better-auth/core': 1.6.26(@better-auth/utils@0.4.2)(@better-fetch/fetch@1.3.1)(better-call@1.3.7(zod@4.4.3))(jose@6.2.8)(kysely@0.29.4)(nanostores@1.4.2) + '@better-auth/utils': 0.4.2 + optionalDependencies: + drizzle-orm: 0.45.2(@types/pg@8.21.0)(kysely@0.29.4)(pg@8.22.0) + + '@better-auth/kysely-adapter@1.6.26(@better-auth/core@1.6.26(@better-auth/utils@0.4.2)(@better-fetch/fetch@1.3.1)(better-call@1.3.7(zod@4.4.3))(jose@6.2.8)(kysely@0.29.4)(nanostores@1.4.2))(@better-auth/utils@0.4.2)(kysely@0.29.4)': + dependencies: + '@better-auth/core': 1.6.26(@better-auth/utils@0.4.2)(@better-fetch/fetch@1.3.1)(better-call@1.3.7(zod@4.4.3))(jose@6.2.8)(kysely@0.29.4)(nanostores@1.4.2) + '@better-auth/utils': 0.4.2 + optionalDependencies: + kysely: 0.29.4 + + '@better-auth/memory-adapter@1.6.26(@better-auth/core@1.6.26(@better-auth/utils@0.4.2)(@better-fetch/fetch@1.3.1)(better-call@1.3.7(zod@4.4.3))(jose@6.2.8)(kysely@0.29.4)(nanostores@1.4.2))(@better-auth/utils@0.4.2)': + dependencies: + '@better-auth/core': 1.6.26(@better-auth/utils@0.4.2)(@better-fetch/fetch@1.3.1)(better-call@1.3.7(zod@4.4.3))(jose@6.2.8)(kysely@0.29.4)(nanostores@1.4.2) + '@better-auth/utils': 0.4.2 + + '@better-auth/mongo-adapter@1.6.26(@better-auth/core@1.6.26(@better-auth/utils@0.4.2)(@better-fetch/fetch@1.3.1)(better-call@1.3.7(zod@4.4.3))(jose@6.2.8)(kysely@0.29.4)(nanostores@1.4.2))(@better-auth/utils@0.4.2)': + dependencies: + '@better-auth/core': 1.6.26(@better-auth/utils@0.4.2)(@better-fetch/fetch@1.3.1)(better-call@1.3.7(zod@4.4.3))(jose@6.2.8)(kysely@0.29.4)(nanostores@1.4.2) + '@better-auth/utils': 0.4.2 + + '@better-auth/prisma-adapter@1.6.26(@better-auth/core@1.6.26(@better-auth/utils@0.4.2)(@better-fetch/fetch@1.3.1)(better-call@1.3.7(zod@4.4.3))(jose@6.2.8)(kysely@0.29.4)(nanostores@1.4.2))(@better-auth/utils@0.4.2)': + dependencies: + '@better-auth/core': 1.6.26(@better-auth/utils@0.4.2)(@better-fetch/fetch@1.3.1)(better-call@1.3.7(zod@4.4.3))(jose@6.2.8)(kysely@0.29.4)(nanostores@1.4.2) + '@better-auth/utils': 0.4.2 + + '@better-auth/telemetry@1.6.26(@better-auth/core@1.6.26(@better-auth/utils@0.4.2)(@better-fetch/fetch@1.3.1)(better-call@1.3.7(zod@4.4.3))(jose@6.2.8)(kysely@0.29.4)(nanostores@1.4.2))(@better-auth/utils@0.4.2)(@better-fetch/fetch@1.3.1)': + dependencies: + '@better-auth/core': 1.6.26(@better-auth/utils@0.4.2)(@better-fetch/fetch@1.3.1)(better-call@1.3.7(zod@4.4.3))(jose@6.2.8)(kysely@0.29.4)(nanostores@1.4.2) + '@better-auth/utils': 0.4.2 + '@better-fetch/fetch': 1.3.1 + + '@better-auth/utils@0.4.2': + dependencies: + '@noble/hashes': 2.3.0 + + '@better-auth/utils@0.4.3': + dependencies: + '@noble/hashes': 2.3.0 + + '@better-fetch/fetch@1.3.1': {} + '@bramus/specificity@2.4.2': dependencies: css-tree: 3.2.1 @@ -4259,7 +4519,9 @@ snapshots: '@eslint/core': 0.17.0 levn: 0.4.1 - '@exodus/bytes@1.15.1': {} + '@exodus/bytes@1.15.1(@noble/hashes@2.3.0)': + optionalDependencies: + '@noble/hashes': 2.3.0 '@grpc/grpc-js@1.14.4': dependencies: @@ -4479,6 +4741,10 @@ snapshots: '@next/swc-win32-x64-msvc@16.3.0': optional: true + '@noble/ciphers@2.3.0': {} + + '@noble/hashes@2.3.0': {} + '@nodelib/fs.scandir@2.1.5': dependencies: '@nodelib/fs.stat': 2.0.5 @@ -4493,6 +4759,8 @@ snapshots: '@nolyfill/is-core-module@1.0.39': {} + '@opentelemetry/semantic-conventions@1.43.0': {} + '@oxc-project/types@0.143.0': {} '@pkgjs/parseargs@0.11.0': @@ -4718,6 +4986,10 @@ snapshots: dependencies: undici-types: 7.18.2 + '@types/nodemailer@8.0.1': + dependencies: + '@types/node': 24.13.3 + '@types/pg@8.21.0': dependencies: '@types/node': 24.13.3 @@ -5145,6 +5417,46 @@ snapshots: dependencies: tweetnacl: 0.14.5 + better-auth@1.6.26(drizzle-kit@0.31.10)(drizzle-orm@0.45.2(@types/pg@8.21.0)(kysely@0.29.4)(pg@8.22.0))(next@16.3.0(@babel/core@7.29.7(supports-color@7.2.0))(@types/node@24.13.3)(react-dom@19.2.8(react@19.2.8))(react@19.2.8))(pg@8.22.0)(react-dom@19.2.8(react@19.2.8))(react@19.2.8)(vitest@4.1.10(@types/node@24.13.3)(jsdom@30.0.1(@noble/hashes@2.3.0))(vite@8.2.1(@types/node@24.13.3)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.23.11)(yaml@2.9.0))): + dependencies: + '@better-auth/core': 1.6.26(@better-auth/utils@0.4.2)(@better-fetch/fetch@1.3.1)(better-call@1.3.7(zod@4.4.3))(jose@6.2.8)(kysely@0.29.4)(nanostores@1.4.2) + '@better-auth/drizzle-adapter': 1.6.26(@better-auth/core@1.6.26(@better-auth/utils@0.4.2)(@better-fetch/fetch@1.3.1)(better-call@1.3.7(zod@4.4.3))(jose@6.2.8)(kysely@0.29.4)(nanostores@1.4.2))(@better-auth/utils@0.4.2)(drizzle-orm@0.45.2(@types/pg@8.21.0)(kysely@0.29.4)(pg@8.22.0)) + '@better-auth/kysely-adapter': 1.6.26(@better-auth/core@1.6.26(@better-auth/utils@0.4.2)(@better-fetch/fetch@1.3.1)(better-call@1.3.7(zod@4.4.3))(jose@6.2.8)(kysely@0.29.4)(nanostores@1.4.2))(@better-auth/utils@0.4.2)(kysely@0.29.4) + '@better-auth/memory-adapter': 1.6.26(@better-auth/core@1.6.26(@better-auth/utils@0.4.2)(@better-fetch/fetch@1.3.1)(better-call@1.3.7(zod@4.4.3))(jose@6.2.8)(kysely@0.29.4)(nanostores@1.4.2))(@better-auth/utils@0.4.2) + '@better-auth/mongo-adapter': 1.6.26(@better-auth/core@1.6.26(@better-auth/utils@0.4.2)(@better-fetch/fetch@1.3.1)(better-call@1.3.7(zod@4.4.3))(jose@6.2.8)(kysely@0.29.4)(nanostores@1.4.2))(@better-auth/utils@0.4.2) + '@better-auth/prisma-adapter': 1.6.26(@better-auth/core@1.6.26(@better-auth/utils@0.4.2)(@better-fetch/fetch@1.3.1)(better-call@1.3.7(zod@4.4.3))(jose@6.2.8)(kysely@0.29.4)(nanostores@1.4.2))(@better-auth/utils@0.4.2) + '@better-auth/telemetry': 1.6.26(@better-auth/core@1.6.26(@better-auth/utils@0.4.2)(@better-fetch/fetch@1.3.1)(better-call@1.3.7(zod@4.4.3))(jose@6.2.8)(kysely@0.29.4)(nanostores@1.4.2))(@better-auth/utils@0.4.2)(@better-fetch/fetch@1.3.1) + '@better-auth/utils': 0.4.2 + '@better-fetch/fetch': 1.3.1 + '@noble/ciphers': 2.3.0 + '@noble/hashes': 2.3.0 + better-call: 1.3.7(zod@4.4.3) + defu: 6.1.7 + jose: 6.2.8 + kysely: 0.29.4 + nanostores: 1.4.2 + zod: 4.4.3 + optionalDependencies: + drizzle-kit: 0.31.10 + drizzle-orm: 0.45.2(@types/pg@8.21.0)(kysely@0.29.4)(pg@8.22.0) + next: 16.3.0(@babel/core@7.29.7(supports-color@7.2.0))(@types/node@24.13.3)(react-dom@19.2.8(react@19.2.8))(react@19.2.8) + pg: 8.22.0 + react: 19.2.8 + react-dom: 19.2.8(react@19.2.8) + vitest: 4.1.10(@types/node@24.13.3)(jsdom@30.0.1(@noble/hashes@2.3.0))(vite@8.2.1(@types/node@24.13.3)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.23.11)(yaml@2.9.0)) + transitivePeerDependencies: + - '@cloudflare/workers-types' + - '@opentelemetry/api' + + better-call@1.3.7(zod@4.4.3): + dependencies: + '@better-auth/utils': 0.4.3 + '@better-fetch/fetch': 1.3.1 + rou3: 0.7.12 + set-cookie-parser: 3.1.2 + optionalDependencies: + zod: 4.4.3 + bidi-js@1.0.3: dependencies: require-from-string: 2.0.2 @@ -5287,10 +5599,10 @@ snapshots: damerau-levenshtein@1.0.8: {} - data-urls@7.0.0: + data-urls@7.0.0(@noble/hashes@2.3.0): dependencies: whatwg-mimetype: 5.0.0 - whatwg-url: 16.0.1 + whatwg-url: 16.0.1(@noble/hashes@2.3.0) transitivePeerDependencies: - '@noble/hashes' @@ -5340,6 +5652,8 @@ snapshots: has-property-descriptors: 1.0.2 object-keys: 1.1.1 + defu@6.1.7: {} + dequal@2.0.3: {} detect-libc@2.1.2: {} @@ -5383,9 +5697,10 @@ snapshots: esbuild: 0.25.12 tsx: 4.23.11 - drizzle-orm@0.45.2(@types/pg@8.21.0)(pg@8.22.0): + drizzle-orm@0.45.2(@types/pg@8.21.0)(kysely@0.29.4)(pg@8.22.0): optionalDependencies: '@types/pg': 8.21.0 + kysely: 0.29.4 pg: 8.22.0 dunder-proto@1.0.1: @@ -6002,9 +6317,9 @@ snapshots: dependencies: hermes-estree: 0.25.1 - html-encoding-sniffer@6.0.0: + html-encoding-sniffer@6.0.0(@noble/hashes@2.3.0): dependencies: - '@exodus/bytes': 1.15.1 + '@exodus/bytes': 1.15.1(@noble/hashes@2.3.0) transitivePeerDependencies: - '@noble/hashes' @@ -6176,23 +6491,25 @@ snapshots: jiti@2.7.0: {} + jose@6.2.8: {} + js-tokens@4.0.0: {} js-yaml@4.3.1: dependencies: argparse: 2.0.1 - jsdom@30.0.1: + jsdom@30.0.1(@noble/hashes@2.3.0): dependencies: '@asamuzakjp/css-color': 6.0.5 '@asamuzakjp/dom-selector': 8.3.2 '@bramus/specificity': 2.4.2 '@csstools/css-syntax-patches-for-csstree': 1.1.7(css-tree@3.2.1) - '@exodus/bytes': 1.15.1 + '@exodus/bytes': 1.15.1(@noble/hashes@2.3.0) css-tree: 3.2.1 - data-urls: 7.0.0 + data-urls: 7.0.0(@noble/hashes@2.3.0) decimal.js: 10.6.0 - html-encoding-sniffer: 6.0.0 + html-encoding-sniffer: 6.0.0(@noble/hashes@2.3.0) is-potential-custom-element-name: 1.0.1 lru-cache: 11.5.2 parse5: 8.0.1 @@ -6203,7 +6520,7 @@ snapshots: w3c-xmlserializer: 5.0.0 webidl-conversions: 8.0.1 whatwg-mimetype: 5.0.0 - whatwg-url: 17.1.0 + whatwg-url: 17.1.0(@noble/hashes@2.3.0) xml-name-validator: 5.0.0 transitivePeerDependencies: - '@noble/hashes' @@ -6233,6 +6550,8 @@ snapshots: dependencies: json-buffer: 3.0.1 + kysely@0.29.4: {} + language-subtag-registry@0.3.23: {} language-tags@1.0.9: @@ -6420,6 +6739,8 @@ snapshots: nanoid@3.3.18: {} + nanostores@1.4.2: {} + napi-postinstall@0.3.4: {} natural-compare@1.4.0: {} @@ -6458,6 +6779,8 @@ snapshots: node-releases@2.0.53: {} + nodemailer@9.0.5: {} + normalize-path@3.0.0: {} object-assign@4.1.1: {} @@ -6779,6 +7102,8 @@ snapshots: '@rolldown/binding-win32-arm64-msvc': 1.2.3 '@rolldown/binding-win32-x64-msvc': 1.2.3 + rou3@0.7.12: {} + run-parallel@1.2.0: dependencies: queue-microtask: 1.2.3 @@ -6820,6 +7145,8 @@ snapshots: server-only@0.0.1: {} + set-cookie-parser@3.1.2: {} + set-function-length@1.2.2: dependencies: define-data-property: 1.1.4 @@ -7311,7 +7638,7 @@ snapshots: tsx: 4.23.11 yaml: 2.9.0 - vitest@4.1.10(@types/node@24.13.3)(jsdom@30.0.1)(vite@8.2.1(@types/node@24.13.3)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.23.11)(yaml@2.9.0)): + vitest@4.1.10(@types/node@24.13.3)(jsdom@30.0.1(@noble/hashes@2.3.0))(vite@8.2.1(@types/node@24.13.3)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.23.11)(yaml@2.9.0)): dependencies: '@vitest/expect': 4.1.10 '@vitest/mocker': 4.1.10(vite@8.2.1(@types/node@24.13.3)(esbuild@0.28.1)(jiti@2.7.0)(tsx@4.23.11)(yaml@2.9.0)) @@ -7335,7 +7662,7 @@ snapshots: why-is-node-running: 2.3.0 optionalDependencies: '@types/node': 24.13.3 - jsdom: 30.0.1 + jsdom: 30.0.1(@noble/hashes@2.3.0) transitivePeerDependencies: - msw @@ -7347,17 +7674,17 @@ snapshots: whatwg-mimetype@5.0.0: {} - whatwg-url@16.0.1: + whatwg-url@16.0.1(@noble/hashes@2.3.0): dependencies: - '@exodus/bytes': 1.15.1 + '@exodus/bytes': 1.15.1(@noble/hashes@2.3.0) tr46: 6.0.0 webidl-conversions: 8.0.1 transitivePeerDependencies: - '@noble/hashes' - whatwg-url@17.1.0: + whatwg-url@17.1.0(@noble/hashes@2.3.0): dependencies: - '@exodus/bytes': 1.15.1 + '@exodus/bytes': 1.15.1(@noble/hashes@2.3.0) tr46: 6.0.0 webidl-conversions: 8.0.1 transitivePeerDependencies: diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 6c750ff..7d44de6 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,2 +1,6 @@ allowBuilds: + cpu-features: false + esbuild: true + protobufjs: false + ssh2: false unrs-resolver: true diff --git a/src/app/(public)/anmelden/page.tsx b/src/app/(public)/anmelden/page.tsx new file mode 100644 index 0000000..21269b4 --- /dev/null +++ b/src/app/(public)/anmelden/page.tsx @@ -0,0 +1,38 @@ +import Link from "next/link"; + +import { env } from "@/config/env"; +import { LoginForm } from "@/modules/auth/public-forms"; + +export default function LoginPage() { + return ( +
+
+ + Leon Tonhäuser + + Redaktionsportal +
+
+

Zugang

+

Anmelden

+

Melden Sie sich mit der E-Mail-Adresse Ihrer Redaktion an.

+ + +
+ +
+ ); +} + +function LegalFooter({ imprint, privacy, terms }: { imprint: string; privacy: string; terms: string }) { + return ( + + ); +} diff --git a/src/app/(public)/passwort-vergessen/page.tsx b/src/app/(public)/passwort-vergessen/page.tsx new file mode 100644 index 0000000..74da6ac --- /dev/null +++ b/src/app/(public)/passwort-vergessen/page.tsx @@ -0,0 +1,25 @@ +import Link from "next/link"; + +import { PasswordResetRequestForm } from "@/modules/auth/public-forms"; + +export default function ForgotPasswordPage() { + return ( +
+
+ + Leon Tonhäuser + + Redaktionsportal +
+
+

Zugang

+

Passwort vergessen?

+

Fordern Sie einen Link zum Zurücksetzen Ihres Passworts an.

+ + +
+
+ ); +} diff --git a/src/app/(public)/passwort-zuruecksetzen/page.tsx b/src/app/(public)/passwort-zuruecksetzen/page.tsx new file mode 100644 index 0000000..70413b8 --- /dev/null +++ b/src/app/(public)/passwort-zuruecksetzen/page.tsx @@ -0,0 +1,31 @@ +import Link from "next/link"; + +import { PasswordResetForm } from "@/modules/auth/public-forms"; + +export default async function ResetPasswordPage({ + searchParams, +}: { + searchParams: Promise<{ token?: string }>; +}) { + const { token } = await searchParams; + + return ( +
+
+ + Leon Tonhäuser + + Redaktionsportal +
+
+

Zugang

+

Neues Passwort setzen

+

Wählen Sie ein neues Passwort für den Zugang Ihrer Redaktion.

+ + +
+
+ ); +} diff --git a/src/app/(public)/registrieren/bestaetigt/page.tsx b/src/app/(public)/registrieren/bestaetigt/page.tsx new file mode 100644 index 0000000..082f879 --- /dev/null +++ b/src/app/(public)/registrieren/bestaetigt/page.tsx @@ -0,0 +1,25 @@ +import Link from "next/link"; + +export default function RegistrationConfirmedPage() { + return ( +
+
+ + Leon Tonhäuser + + Redaktionsportal +
+
+

Registrierung

+

Vielen Dank.

+

+ Bitte folgen Sie den weiteren Hinweisen, die wir Ihnen gegebenenfalls zusenden. Danach + prüfen wir Ihre Registrierung. +

+ + Zur Anmeldung + +
+
+ ); +} diff --git a/src/app/(public)/registrieren/page.tsx b/src/app/(public)/registrieren/page.tsx new file mode 100644 index 0000000..bff3a1f --- /dev/null +++ b/src/app/(public)/registrieren/page.tsx @@ -0,0 +1,75 @@ +import Link from "next/link"; +import { redirect } from "next/navigation"; + +import { env } from "@/config/env"; +import { registerEditorial } from "@/modules/auth/auth"; +import { RegistrationValidationError } from "@/modules/auth/registration"; +import { + RegistrationForm, + type RegistrationFormState, +} from "@/modules/auth/public-forms"; + +export default function RegistrationPage() { + return ( +
+
+ + Leon Tonhäuser + + Redaktionsportal +
+
+

B2B-Zugang

+

Redaktion registrieren

+

+ Das Redaktionsportal steht ausschließlich Unternehmen und Redaktionen zur Verfügung. +

+ +
+
+ ); +} + +async function registerAction( + _state: RegistrationFormState, + formData: FormData, +): Promise { + "use server"; + + try { + await registerEditorial({ + companyName: text(formData, "companyName"), + contactName: text(formData, "contactName"), + email: text(formData, "email"), + password: text(formData, "password"), + billingAddress: { + addressLine1: text(formData, "addressLine1"), + addressLine2: text(formData, "addressLine2") || undefined, + postalCode: text(formData, "postalCode"), + city: text(formData, "city"), + countryCode: text(formData, "countryCode"), + }, + actsForBusiness: formData.has("actsForBusiness"), + termsVersion: formData.has("termsAccepted") ? text(formData, "termsVersion") : "", + privacyAcknowledged: formData.has("privacyAcknowledged"), + }); + } catch (error) { + if (error instanceof RegistrationValidationError) { + return { errors: { [error.field]: error.message } }; + } + } + + redirect("/registrieren/bestaetigt"); +} + +function text(formData: FormData, name: string): string { + const value = formData.get(name); + return typeof value === "string" ? value : ""; +} diff --git a/src/app/api/auth/[...all]/route.ts b/src/app/api/auth/[...all]/route.ts new file mode 100644 index 0000000..3e0413c --- /dev/null +++ b/src/app/api/auth/[...all]/route.ts @@ -0,0 +1,5 @@ +import { toNextJsHandler } from "better-auth/next-js"; + +import { auth } from "@/modules/auth/auth"; + +export const { GET, POST } = toNextJsHandler(auth); diff --git a/src/app/globals.css b/src/app/globals.css index 2c0ebc3..9c971cb 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -138,3 +138,141 @@ a { transition: none; } } + +.public-account-page { + display: grid; + min-height: 100vh; + grid-template-rows: auto 1fr auto; + padding: clamp(1.25rem, 3vw, 2.75rem); +} + +.account-panel { + width: min(100%, 37rem); + align-self: center; + padding-block: clamp(4rem, 10vh, 7rem); +} + +.account-panel-wide { + width: min(100%, 48rem); +} + +.account-panel h1 { + max-width: 12ch; + margin: 0; + font-size: clamp(2.6rem, 6vw, 5.5rem); + font-weight: 600; + letter-spacing: -0.06em; + line-height: 0.92; +} + +.account-panel .lede { + margin-top: 1.75rem; +} + +.account-form { + display: grid; + gap: 1.25rem; + margin-top: 2.5rem; +} + +.account-form label, +.acknowledgements legend { + display: grid; + gap: 0.5rem; + font-size: 0.8125rem; + font-weight: 650; + letter-spacing: 0.01em; +} + +.account-form input:not([type="checkbox"]) { + width: 100%; + min-height: 3.1rem; + border: 1px solid var(--ink); + border-radius: 0; + background: var(--paper); + color: var(--ink); + font: inherit; + font-weight: 400; + padding: 0.75rem; +} + +.form-grid { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 1rem; +} + +.acknowledgements { + display: grid; + gap: 0.75rem; + margin: 0; + padding: 1.25rem 0; + border: 0; + border-top: 1px solid var(--line); + border-bottom: 1px solid var(--line); +} + +.acknowledgements legend { + padding: 0; + margin-bottom: 0.25rem; +} + +.checkbox-label { + grid-template-columns: 1rem minmax(0, 1fr); + align-items: start; + font-weight: 400 !important; + line-height: 1.45; +} + +.checkbox-label input { + width: 1rem; + height: 1rem; + margin: 0.12rem 0 0; + accent-color: var(--ink); +} + +.checkbox-label a, +.account-links a, +.public-footer a, +.legal-link { + text-underline-offset: 0.17em; +} + +.field-error { + margin: -0.25rem 0 0; + color: #9d0e0e; + font-size: 0.875rem; + line-height: 1.4; +} + +.form-note { + max-width: 44rem; + margin: 0; + color: var(--muted); + font-size: 0.875rem; + line-height: 1.55; +} + +.account-links, +.public-footer { + display: flex; + flex-wrap: wrap; + gap: 0.75rem 1.25rem; + margin-top: 1rem; + font-size: 0.875rem; +} + +.public-footer { + padding-top: 1rem; + border-top: 1px solid var(--line); + color: var(--muted); + font-size: 0.75rem; + letter-spacing: 0.06em; + text-transform: uppercase; +} + +@media (max-width: 40rem) { + .form-grid { + grid-template-columns: 1fr; + } +} diff --git a/src/modules/auth/admin-bootstrap.ts b/src/modules/auth/admin-bootstrap.ts new file mode 100644 index 0000000..9ecfb9e --- /dev/null +++ b/src/modules/auth/admin-bootstrap.ts @@ -0,0 +1,80 @@ +import "server-only"; + +import { eq, sql } from "drizzle-orm"; +import type { NodePgDatabase } from "drizzle-orm/node-postgres"; + +import { users } from "@/db/schema"; +import type * as schema from "@/db/schema"; + +export type AdminBootstrapInput = { + email: string; + name: string; + password: string; +}; + +export type AdminBootstrapAuth = { + signUpEmail(input: { email: string; name: string; password: string }): Promise<{ user: { id: string } }>; + sendVerificationEmail(input: { email: string }): Promise; +}; + +export type AdminBootstrapRepository = { + countAdmins(): Promise; + findUserByEmail(email: string): Promise<{ id: string } | undefined>; + promoteUserToAdmin(userId: string): Promise; +}; + +export function createAdminBootstrapService({ + auth, + repo, +}: { + auth: AdminBootstrapAuth; + repo: AdminBootstrapRepository; +}) { + return { + async bootstrap(input: AdminBootstrapInput): Promise<{ status: "created" | "already_configured" }> { + if ((await repo.countAdmins()) > 0) { + return { status: "already_configured" }; + } + + const email = input.email.trim().toLowerCase(); + const existingUser = await repo.findUserByEmail(email); + const user = + existingUser ?? + (await auth.signUpEmail({ + email, + name: input.name.trim(), + password: input.password, + })).user; + + await repo.promoteUserToAdmin(user.id); + await auth.sendVerificationEmail({ email }); + return { status: "created" }; + }, + }; +} + +export function createAdminBootstrapRepository(database: NodePgDatabase): AdminBootstrapRepository { + return { + async countAdmins() { + const [result] = await database + .select({ count: sql`count(*)::int` }) + .from(users) + .where(eq(users.role, "ADMIN")); + return result.count; + }, + async findUserByEmail(email) { + const [user] = await database + .select({ id: users.id }) + .from(users) + .where(eq(users.email, email)) + .limit(1); + return user; + }, + async promoteUserToAdmin(userId) { + await database + .update(users) + .set({ role: "ADMIN", updatedAt: new Date() }) + .where(eq(users.id, userId)); + }, + }; +} diff --git a/src/modules/auth/auth.test.ts b/src/modules/auth/auth.test.ts new file mode 100644 index 0000000..4ce2e44 --- /dev/null +++ b/src/modules/auth/auth.test.ts @@ -0,0 +1,19 @@ +import { expect, test } from "vitest"; + +import { auth } from "./auth"; + +test("rejects direct Better Auth sign-up requests that bypass B2B registration", async () => { + const response = await auth.handler( + new Request("http://localhost:3000/api/auth/sign-up/email", { + method: "POST", + headers: { "content-type": "application/json" }, + body: JSON.stringify({ + email: "bypass@example.com", + name: "Bypass", + password: "sicheres-passwort-123", + }), + }), + ); + + expect(response.status).toBe(403); +}); diff --git a/src/modules/auth/auth.ts b/src/modules/auth/auth.ts new file mode 100644 index 0000000..1c95a76 --- /dev/null +++ b/src/modules/auth/auth.ts @@ -0,0 +1,90 @@ +import "server-only"; + +import { drizzleAdapter } from "@better-auth/drizzle-adapter"; +import { betterAuth } from "better-auth"; +import { APIError, createAuthMiddleware } from "better-auth/api"; + +import { env } from "@/config/env"; +import { db } from "@/db/client"; +import { accounts, sessions, users, verifications } from "@/db/schema"; +import { mailer } from "@/modules/mail/mailer"; + +import { + createEditorialRegistrationRepository, + createRegistrationService, + type RegistrationInput, +} from "./registration"; + +const registrationRepository = createEditorialRegistrationRepository(db); + +export const auth = betterAuth({ + baseURL: env.BETTER_AUTH_URL, + secret: env.BETTER_AUTH_SECRET, + database: drizzleAdapter(db, { + provider: "pg", + schema: { + user: users, + account: accounts, + session: sessions, + verification: verifications, + }, + }), + hooks: { + before: createAuthMiddleware(async (context) => { + if (context.path === "/sign-up/email") { + throw new APIError("FORBIDDEN", { + message: "Bitte verwenden Sie die Registrierung des Redaktionsportals.", + }); + } + }), + }, + emailAndPassword: { + enabled: true, + requireEmailVerification: true, + autoSignIn: false, + resetPasswordTokenExpiresIn: 60 * 60, + revokeSessionsOnPasswordReset: true, + async sendResetPassword({ user, url }) { + await mailer.sendPasswordReset({ to: user.email, resetUrl: url }); + }, + }, + emailVerification: { + sendOnSignUp: false, + autoSignInAfterVerification: false, + expiresIn: 60 * 60, + async sendVerificationEmail({ user, url }) { + await mailer.sendVerification({ to: user.email, verificationUrl: url }); + }, + async afterEmailVerification(user) { + await registrationService.onEmailVerified(user.id); + }, + }, + databaseHooks: { + session: { + create: { + async before(session) { + return registrationRepository.canCreateSession(session.userId); + }, + }, + }, + }, +}); + +export const registrationService = createRegistrationService({ + auth: { + async signUpEmail({ email, name, password }) { + return auth.api.signUpEmail({ body: { email, name, password } }); + }, + async sendVerificationEmail({ email }) { + await auth.api.sendVerificationEmail({ + body: { email, callbackURL: "/registrieren/bestaetigt" }, + }); + }, + }, + repo: registrationRepository, + audit: registrationRepository, +}); + +export function registerEditorial(input: RegistrationInput): Promise<{ status: "pending_email" }> { + return registrationService.register(input); +} diff --git a/src/modules/auth/client.ts b/src/modules/auth/client.ts new file mode 100644 index 0000000..2f75fd4 --- /dev/null +++ b/src/modules/auth/client.ts @@ -0,0 +1,5 @@ +"use client"; + +import { createAuthClient } from "better-auth/react"; + +export const authClient = createAuthClient(); diff --git a/src/modules/auth/public-forms.test.tsx b/src/modules/auth/public-forms.test.tsx new file mode 100644 index 0000000..5d5aefe --- /dev/null +++ b/src/modules/auth/public-forms.test.tsx @@ -0,0 +1,41 @@ +// @vitest-environment jsdom + +import { render, screen } from "@testing-library/react"; +import { expect, test, vi } from "vitest"; + +import { RegistrationForm } from "./public-forms"; + +test("registration presents separate B2B, terms, and privacy acknowledgements", () => { + render( + , + ); + + expect( + screen.getByRole("checkbox", { + name: /im namen einer redaktion oder eines unternehmens/i, + }), + ).toHaveProperty("required", true); + expect(screen.getByRole("checkbox", { name: /nutzungs- und lizenzbedingungen/i })).toHaveProperty( + "required", + true, + ); + expect(screen.getByRole("checkbox", { name: /datenschutzerklärung/i })).toHaveProperty( + "required", + true, + ); + expect(screen.getByRole("link", { name: /nutzungs- und lizenzbedingungen/i })).toHaveProperty( + "href", + "https://example.com/nutzungsbedingungen", + ); + expect(screen.getByRole("link", { name: /datenschutzerklärung/i })).toHaveProperty( + "href", + "https://example.com/datenschutz", + ); +}); diff --git a/src/modules/auth/public-forms.tsx b/src/modules/auth/public-forms.tsx new file mode 100644 index 0000000..6f39b60 --- /dev/null +++ b/src/modules/auth/public-forms.tsx @@ -0,0 +1,256 @@ +"use client"; + +import { type FormEvent, useActionState, useState } from "react"; + +import { authClient } from "./client"; + +export type RegistrationFormState = { + errors?: Partial< + Record<"actsForBusiness" | "termsVersion" | "privacyAcknowledged", string> + >; +}; + +export type RegistrationFormAction = ( + state: RegistrationFormState, + formData: FormData, +) => Promise; + +export type LegalUrls = { + imprint: string; + privacy: string; + terms: string; +}; + +const initialRegistrationState: RegistrationFormState = {}; + +export function RegistrationForm({ + action, + legalUrls, +}: { + action: RegistrationFormAction; + legalUrls: LegalUrls; +}) { + const [state, formAction, pending] = useActionState(action, initialRegistrationState); + + return ( +
+ +
+ + + + + + + + + +
+ +
+ Verbindliche Angaben + + + + + + +
+ + +

+ Wir informieren Sie auf der nächsten Seite über den weiteren Ablauf. +

+ + Impressum + +
+ ); +} + +export function LoginForm() { + const [error, setError] = useState(); + const [pending, setPending] = useState(false); + + async function submit(event: FormEvent) { + event.preventDefault(); + setPending(true); + setError(undefined); + + const formData = new FormData(event.currentTarget); + const result = await authClient.signIn.email({ + email: readText(formData, "email").trim().toLowerCase(), + password: readText(formData, "password"), + callbackURL: "/", + }); + + if (result.error) { + setError("Die Anmeldung war nicht erfolgreich. Bitte prüfen Sie Ihre Angaben."); + setPending(false); + return; + } + + window.location.assign(result.data?.url ?? "/"); + } + + return ( +
+ + + + + + ); +} + +export function PasswordResetRequestForm() { + const [submitted, setSubmitted] = useState(false); + const [pending, setPending] = useState(false); + + async function submit(event: FormEvent) { + event.preventDefault(); + setPending(true); + const formData = new FormData(event.currentTarget); + + try { + await authClient.requestPasswordReset({ + email: readText(formData, "email").trim().toLowerCase(), + redirectTo: `${window.location.origin}/passwort-zuruecksetzen`, + }); + } finally { + setSubmitted(true); + setPending(false); + } + } + + if (submitted) { + return ( +

+ Falls ein Zugang zu dieser Adresse gehört, erhalten Sie in Kürze weitere Hinweise. +

+ ); + } + + return ( +
+ + +
+ ); +} + +export function PasswordResetForm({ token }: { token?: string }) { + const [message, setMessage] = useState(); + const [pending, setPending] = useState(false); + + async function submit(event: FormEvent) { + event.preventDefault(); + setPending(true); + const formData = new FormData(event.currentTarget); + + try { + await authClient.resetPassword({ newPassword: readText(formData, "password"), token }); + } finally { + setMessage("Wenn der Link gültig war, wurde Ihr Passwort aktualisiert."); + setPending(false); + } + } + + if (message) { + return ( +

+ {message} +

+ ); + } + + return ( +
+ + +
+ ); +} + +function FieldError({ message }: { message?: string }) { + return message ? ( +

+ {message} +

+ ) : null; +} + +function readText(formData: FormData, name: string): string { + const value = formData.get(name); + return typeof value === "string" ? value : ""; +} diff --git a/src/modules/auth/registration.test.ts b/src/modules/auth/registration.test.ts new file mode 100644 index 0000000..1e9b398 --- /dev/null +++ b/src/modules/auth/registration.test.ts @@ -0,0 +1,169 @@ +import { describe, expect, test, vi } from "vitest"; + +import { + RegistrationValidationError, + createRegistrationService, + type RegistrationInput, +} from "./registration"; +import { createAdminBootstrapService } from "./admin-bootstrap"; + +const validRegistration: RegistrationInput = { + companyName: "Neue Redaktion GmbH", + contactName: "Mara Muster", + email: "Mara.Muster@Example.com", + password: "sicheres-passwort-123", + billingAddress: { + addressLine1: "Presseweg 1", + addressLine2: "Haus B", + postalCode: "10115", + city: "Berlin", + countryCode: "DE", + }, + actsForBusiness: true, + termsVersion: "2026-08", + privacyAcknowledged: true, +}; + +function createService() { + const auth = { + signUpEmail: vi.fn().mockResolvedValue({ user: { id: "user-1" } }), + sendVerificationEmail: vi.fn().mockResolvedValue(undefined), + }; + const repo = { + createEditorial: vi.fn().mockResolvedValue(undefined), + markPendingApproval: vi.fn().mockResolvedValue(true), + }; + const audit = { + recordVerificationInconsistency: vi.fn().mockResolvedValue(undefined), + }; + const now = new Date("2026-08-09T10:00:00.000Z"); + + return { + auth, + repo, + audit, + service: createRegistrationService({ auth, repo, audit, now: () => now }), + }; +} + +describe("editorial registration", () => { + test("creates a pending editorial and sends verification mail", async () => { + const { auth, repo, service } = createService(); + + await expect(service.register(validRegistration)).resolves.toEqual({ status: "pending_email" }); + + expect(auth.signUpEmail).toHaveBeenCalledWith({ + email: "mara.muster@example.com", + name: "Mara Muster", + password: "sicheres-passwort-123", + }); + expect(repo.createEditorial).toHaveBeenCalledWith({ + userId: "user-1", + name: "Neue Redaktion GmbH", + contactName: "Mara Muster", + loginEmail: "mara.muster@example.com", + status: "pending_email", + acceptedTermsVersion: "2026-08", + acceptedTermsAt: new Date("2026-08-09T10:00:00.000Z"), + privacyAcknowledgedAt: new Date("2026-08-09T10:00:00.000Z"), + billingAddress: { + companyName: "Neue Redaktion GmbH", + contactName: "Mara Muster", + addressLine1: "Presseweg 1", + addressLine2: "Haus B", + postalCode: "10115", + city: "Berlin", + countryCode: "DE", + }, + }); + expect(auth.sendVerificationEmail).toHaveBeenCalledWith({ + email: "mara.muster@example.com", + }); + }); + + test("rejects a registration that is not made for a business", async () => { + const { auth, repo, service } = createService(); + + await expect( + service.register({ ...validRegistration, actsForBusiness: false }), + ).rejects.toEqual( + new RegistrationValidationError( + "actsForBusiness", + "Bitte bestätigen Sie, dass Sie im Namen eines Unternehmens oder einer Redaktion handeln.", + ), + ); + + expect(auth.signUpEmail).not.toHaveBeenCalled(); + expect(repo.createEditorial).not.toHaveBeenCalled(); + }); + + test("rejects missing terms and privacy acknowledgements with stable German field errors", async () => { + const { service } = createService(); + + await expect( + service.register({ ...validRegistration, termsVersion: "" }), + ).rejects.toEqual( + new RegistrationValidationError( + "termsVersion", + "Bitte akzeptieren Sie die Nutzungs- und Lizenzbedingungen.", + ), + ); + await expect( + service.register({ ...validRegistration, privacyAcknowledged: false }), + ).rejects.toEqual( + new RegistrationValidationError( + "privacyAcknowledged", + "Bitte bestätigen Sie die Kenntnisnahme der Datenschutzerklärung.", + ), + ); + }); + + test("moves a verified account from pending email to pending approval", async () => { + const { audit, repo, service } = createService(); + + await service.onEmailVerified("user-1"); + + expect(repo.markPendingApproval).toHaveBeenCalledWith("user-1"); + expect(audit.recordVerificationInconsistency).not.toHaveBeenCalled(); + }); + + test("audits a verified user without an editorial account without raw request data", async () => { + const { audit, repo, service } = createService(); + repo.markPendingApproval.mockResolvedValue(false); + + await service.onEmailVerified("user-without-editorial"); + + expect(audit.recordVerificationInconsistency).toHaveBeenCalledWith({ + userId: "user-without-editorial", + }); + }); +}); + +test("bootstraps the first admin only once", async () => { + const auth = { + signUpEmail: vi.fn().mockResolvedValue({ user: { id: "admin-1" } }), + sendVerificationEmail: vi.fn().mockResolvedValue(undefined), + }; + const repo = { + countAdmins: vi.fn().mockResolvedValue(0), + findUserByEmail: vi.fn().mockResolvedValue(undefined), + promoteUserToAdmin: vi.fn().mockResolvedValue(undefined), + }; + const service = createAdminBootstrapService({ auth, repo }); + + await expect( + service.bootstrap({ + email: "ADMIN@EXAMPLE.COM", + name: "Portal Admin", + password: "sicheres-passwort-123", + }), + ).resolves.toEqual({ status: "created" }); + + expect(auth.signUpEmail).toHaveBeenCalledWith({ + email: "admin@example.com", + name: "Portal Admin", + password: "sicheres-passwort-123", + }); + expect(repo.promoteUserToAdmin).toHaveBeenCalledWith("admin-1"); + expect(auth.sendVerificationEmail).toHaveBeenCalledWith({ email: "admin@example.com" }); +}); diff --git a/src/modules/auth/registration.ts b/src/modules/auth/registration.ts new file mode 100644 index 0000000..f1eb232 --- /dev/null +++ b/src/modules/auth/registration.ts @@ -0,0 +1,276 @@ +import "server-only"; + +import { and, eq } from "drizzle-orm"; +import type { NodePgDatabase } from "drizzle-orm/node-postgres"; + +import { auditEvents, billingAddressVersions, editorialAccounts, users } from "@/db/schema"; +import type * as schema from "@/db/schema"; + +export type BillingAddressInput = { + addressLine1: string; + addressLine2?: string; + postalCode: string; + city: string; + countryCode: string; +}; + +export type RegistrationInput = { + companyName: string; + contactName: string; + email: string; + password: string; + billingAddress: BillingAddressInput; + actsForBusiness: boolean; + termsVersion: string; + privacyAcknowledged: boolean; +}; + +export type PendingEditorial = { + userId: string; + name: string; + contactName: string; + loginEmail: string; + status: "pending_email"; + acceptedTermsVersion: string; + acceptedTermsAt: Date; + privacyAcknowledgedAt: Date; + billingAddress: BillingAddressInput & { companyName: string; contactName: string }; +}; + +export type RegistrationAuth = { + signUpEmail(input: { email: string; name: string; password: string }): Promise<{ user: { id: string } }>; + sendVerificationEmail(input: { email: string }): Promise; +}; + +export type EditorialRegistrationRepository = { + createEditorial(input: PendingEditorial): Promise; + markPendingApproval(userId: string): Promise; +}; + +export type RegistrationAudit = { + recordVerificationInconsistency(input: { userId: string }): Promise; +}; + +export class RegistrationValidationError extends Error { + readonly name = "RegistrationValidationError"; + + constructor( + readonly field: "actsForBusiness" | "termsVersion" | "privacyAcknowledged", + message: string, + ) { + super(message); + } +} + +export function createRegistrationService({ + auth, + repo, + audit, + now = () => new Date(), +}: { + auth: RegistrationAuth; + repo: EditorialRegistrationRepository; + audit: RegistrationAudit; + now?: () => Date; +}) { + return { + async register(input: RegistrationInput): Promise<{ status: "pending_email" }> { + const registration = validateRegistration(input); + const result = await auth.signUpEmail({ + email: registration.loginEmail, + name: registration.contactName, + password: registration.password, + }); + const acceptedAt = now(); + + await repo.createEditorial({ + userId: result.user.id, + name: registration.companyName, + contactName: registration.contactName, + loginEmail: registration.loginEmail, + status: "pending_email", + acceptedTermsVersion: registration.termsVersion, + acceptedTermsAt: acceptedAt, + privacyAcknowledgedAt: acceptedAt, + billingAddress: { + companyName: registration.companyName, + contactName: registration.contactName, + ...registration.billingAddress, + }, + }); + + await auth.sendVerificationEmail({ email: registration.loginEmail }); + return { status: "pending_email" }; + }, + + async onEmailVerified(userId: string): Promise { + const transitioned = await repo.markPendingApproval(userId); + if (!transitioned) { + await audit.recordVerificationInconsistency({ userId }); + } + }, + }; +} + +export function createEditorialRegistrationRepository(database: NodePgDatabase): { + createEditorial(input: PendingEditorial): Promise; + markPendingApproval(userId: string): Promise; + recordVerificationInconsistency(input: { userId: string }): Promise; + canCreateSession(userId: string): Promise; +} { + return { + async createEditorial(input) { + await database.transaction(async (transaction) => { + const [user] = await transaction + .select({ id: users.id }) + .from(users) + .where(eq(users.id, input.userId)) + .limit(1); + + if (!user) { + return; + } + + const [existingEditorial] = await transaction + .select({ id: editorialAccounts.id }) + .from(editorialAccounts) + .where(eq(editorialAccounts.userId, input.userId)) + .limit(1); + + if (existingEditorial) { + return; + } + + const [editorial] = await transaction + .insert(editorialAccounts) + .values({ + userId: input.userId, + name: input.name, + contactName: input.contactName, + loginEmail: input.loginEmail, + status: input.status, + acceptedTermsVersion: input.acceptedTermsVersion, + acceptedTermsAt: input.acceptedTermsAt, + privacyAcknowledgedAt: input.privacyAcknowledgedAt, + }) + .returning({ id: editorialAccounts.id }); + + const [billingAddress] = await transaction + .insert(billingAddressVersions) + .values({ + editorialAccountId: editorial.id, + companyName: input.billingAddress.companyName, + contactName: input.billingAddress.contactName, + addressLine1: input.billingAddress.addressLine1, + addressLine2: input.billingAddress.addressLine2, + postalCode: input.billingAddress.postalCode, + city: input.billingAddress.city, + countryCode: input.billingAddress.countryCode, + validFrom: input.acceptedTermsAt, + createdByUserId: input.userId, + }) + .returning({ id: billingAddressVersions.id }); + + await transaction + .update(editorialAccounts) + .set({ currentBillingAddressVersionId: billingAddress.id, updatedAt: input.acceptedTermsAt }) + .where(eq(editorialAccounts.id, editorial.id)); + }); + }, + + async markPendingApproval(userId) { + const verifiedAt = new Date(); + const [transitioned] = await database + .update(editorialAccounts) + .set({ + status: "pending_approval", + emailVerifiedAt: verifiedAt, + updatedAt: verifiedAt, + }) + .where( + and( + eq(editorialAccounts.userId, userId), + eq(editorialAccounts.status, "pending_email"), + ), + ) + .returning({ id: editorialAccounts.id }); + + if (transitioned) { + return true; + } + + const [existingEditorial] = await database + .select({ id: editorialAccounts.id }) + .from(editorialAccounts) + .where(eq(editorialAccounts.userId, userId)) + .limit(1); + + return Boolean(existingEditorial); + }, + + async recordVerificationInconsistency({ userId }) { + await database.insert(auditEvents).values({ + eventType: "email_verification_without_editorial_account", + actorUserId: userId, + actorType: "system", + entityType: "user", + entityId: userId, + newValues: { reason: "no_editorial_account" }, + }); + }, + + async canCreateSession(userId) { + const [principal] = await database + .select({ role: users.role, status: editorialAccounts.status }) + .from(users) + .leftJoin(editorialAccounts, eq(editorialAccounts.userId, users.id)) + .where(eq(users.id, userId)) + .limit(1); + + return principal?.role === "ADMIN" || principal?.status === "active"; + }, + }; +} + +function validateRegistration(input: RegistrationInput): { + companyName: string; + contactName: string; + loginEmail: string; + password: string; + termsVersion: string; + billingAddress: BillingAddressInput; +} { + if (!input.actsForBusiness) { + throw new RegistrationValidationError( + "actsForBusiness", + "Bitte bestätigen Sie, dass Sie im Namen eines Unternehmens oder einer Redaktion handeln.", + ); + } + if (!input.termsVersion.trim()) { + throw new RegistrationValidationError( + "termsVersion", + "Bitte akzeptieren Sie die Nutzungs- und Lizenzbedingungen.", + ); + } + if (!input.privacyAcknowledged) { + throw new RegistrationValidationError( + "privacyAcknowledged", + "Bitte bestätigen Sie die Kenntnisnahme der Datenschutzerklärung.", + ); + } + + return { + companyName: input.companyName.trim(), + contactName: input.contactName.trim(), + loginEmail: input.email.trim().toLowerCase(), + password: input.password, + termsVersion: input.termsVersion.trim(), + billingAddress: { + addressLine1: input.billingAddress.addressLine1.trim(), + addressLine2: input.billingAddress.addressLine2?.trim() || undefined, + postalCode: input.billingAddress.postalCode.trim(), + city: input.billingAddress.city.trim(), + countryCode: input.billingAddress.countryCode.trim().toUpperCase(), + }, + }; +} diff --git a/src/modules/mail/mailer.test.ts b/src/modules/mail/mailer.test.ts new file mode 100644 index 0000000..9253f25 --- /dev/null +++ b/src/modules/mail/mailer.test.ts @@ -0,0 +1,36 @@ +import { expect, test, vi } from "vitest"; + +import { createMailer } from "./mailer"; + +test("sends a verification link through the configured SMTP boundary", async () => { + const transport = { sendMail: vi.fn().mockResolvedValue({ messageId: "message-1" }) }; + const mailer = createMailer({ from: "portal@example.com", transport }); + + await mailer.sendVerification({ + to: "editorial@example.com", + verificationUrl: "https://portal.example.com/api/auth/verify-email?token=secret-token", + }); + + expect(transport.sendMail).toHaveBeenCalledWith({ + from: "portal@example.com", + to: "editorial@example.com", + subject: "Bitte bestätigen Sie Ihre E-Mail-Adresse", + text: expect.stringContaining( + "https://portal.example.com/api/auth/verify-email?token=secret-token", + ), + }); +}); + +test("sends an approval notice without leaking SMTP credentials", async () => { + const transport = { sendMail: vi.fn().mockResolvedValue({ messageId: "message-2" }) }; + const mailer = createMailer({ from: "portal@example.com", transport }); + + await mailer.sendApprovalNotice({ to: "editorial@example.com", editorialName: "Neue Redaktion" }); + + expect(transport.sendMail).toHaveBeenCalledWith({ + from: "portal@example.com", + to: "editorial@example.com", + subject: "Ihr Zugang zum Redaktionsportal ist freigegeben", + text: expect.stringContaining("Neue Redaktion"), + }); +}); diff --git a/src/modules/mail/mailer.ts b/src/modules/mail/mailer.ts new file mode 100644 index 0000000..0c79d78 --- /dev/null +++ b/src/modules/mail/mailer.ts @@ -0,0 +1,64 @@ +import "server-only"; + +import nodemailer from "nodemailer"; + +import { env } from "@/config/env"; + +export type MailMessage = { + from: string; + to: string; + subject: string; + text: string; +}; + +export type MailTransport = { + sendMail(message: MailMessage): Promise; +}; + +export type Mailer = { + sendVerification(input: { to: string; verificationUrl: string }): Promise; + sendPasswordReset(input: { to: string; resetUrl: string }): Promise; + sendApprovalNotice(input: { to: string; editorialName: string }): Promise; +}; + +export function createMailer({ from, transport }: { from: string; transport: MailTransport }): Mailer { + async function send(message: Omit): Promise { + await transport.sendMail({ from, ...message }); + } + + return { + async sendVerification({ to, verificationUrl }) { + await send({ + to, + subject: "Bitte bestätigen Sie Ihre E-Mail-Adresse", + text: `Bitte bestätigen Sie Ihre E-Mail-Adresse für das Redaktionsportal:\n\n${verificationUrl}`, + }); + }, + async sendPasswordReset({ to, resetUrl }) { + await send({ + to, + subject: "Passwort für das Redaktionsportal zurücksetzen", + text: `Setzen Sie Ihr Passwort für das Redaktionsportal zurück:\n\n${resetUrl}`, + }); + }, + async sendApprovalNotice({ to, editorialName }) { + await send({ + to, + subject: "Ihr Zugang zum Redaktionsportal ist freigegeben", + text: `Der Zugang für ${editorialName} wurde freigegeben. Sie können sich jetzt im Redaktionsportal anmelden.`, + }); + }, + }; +} + +const smtpTransport = nodemailer.createTransport({ + host: env.SMTP_HOST, + port: env.SMTP_PORT, + secure: env.SMTP_PORT === 465, + auth: { + user: env.SMTP_USER, + pass: env.SMTP_PASSWORD, + }, +}); + +export const mailer = createMailer({ from: env.SMTP_FROM, transport: smtpTransport });