create-nexwire 4.3.0 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (326) hide show
  1. package/README.md +10 -5
  2. package/express/src/framework/facade.ts +1 -0
  3. package/express/src/framework/http/logger.ts +13 -4
  4. package/express/src/framework/maker-cli/runtime/core.mjs +1 -2
  5. package/express/src/framework/notification/channels/mail.ts +8 -6
  6. package/express/src/middlewares/auth-middleware.ts +1 -2
  7. package/express/src/middlewares/role-middleware.ts +3 -13
  8. package/express/src/modules/auth/routes/index.ts +1 -2
  9. package/express/src/providers/notification.ts +2 -2
  10. package/express/src/resources/src/components/Switch.vue +60 -65
  11. package/express/src/resources/src/pages/auth/forgetPassword.vue +23 -30
  12. package/express/src/resources/src/pages/auth/login.vue +25 -28
  13. package/express/src/resources/src/pages/auth/register.vue +35 -39
  14. package/express/src/resources/src/pages/auth/resetPassword.vue +29 -37
  15. package/express/src/resources/src/pages/auth/verifyEmail.vue +15 -19
  16. package/express/src/resources/src/plugins/gum.ts +519 -203
  17. package/express/src/resources/src/stores/auth.ts +9 -6
  18. package/express/src/storage/database/nexwire.sqlite +0 -0
  19. package/fastify/.dockerignore +14 -0
  20. package/fastify/.env +44 -0
  21. package/fastify/.env.example +42 -0
  22. package/fastify/.vscode/extensions.json +6 -0
  23. package/fastify/.vscode/settings.json +37 -0
  24. package/fastify/LICENSE +21 -0
  25. package/fastify/README.md +232 -0
  26. package/fastify/biome.json +99 -0
  27. package/fastify/drizzle.config.ts +25 -0
  28. package/fastify/gitignore-stub +31 -0
  29. package/fastify/package.json +130 -0
  30. package/fastify/public/.gitkeep +0 -0
  31. package/fastify/src/config/app.ts +41 -0
  32. package/fastify/src/config/auth.ts +12 -0
  33. package/fastify/src/config/cache.ts +16 -0
  34. package/fastify/src/config/cookie.ts +15 -0
  35. package/fastify/src/config/cors.ts +12 -0
  36. package/fastify/src/config/database.ts +48 -0
  37. package/fastify/src/config/index.ts +83 -0
  38. package/fastify/src/config/jwt.ts +19 -0
  39. package/fastify/src/config/logging.ts +13 -0
  40. package/fastify/src/config/mail.ts +24 -0
  41. package/fastify/src/config/openapi.ts +36 -0
  42. package/fastify/src/config/queue.ts +30 -0
  43. package/fastify/src/config/rateLimit.ts +17 -0
  44. package/fastify/src/config/realtime.ts +15 -0
  45. package/fastify/src/config/redis.ts +18 -0
  46. package/fastify/src/config/security.ts +44 -0
  47. package/fastify/src/config/session.ts +17 -0
  48. package/fastify/src/config/storage.ts +22 -0
  49. package/fastify/src/config/validate.ts +50 -0
  50. package/fastify/src/database/migrations/sqlite/0000_init.sql +48 -0
  51. package/fastify/src/database/migrations/sqlite/meta/0000_snapshot.json +324 -0
  52. package/fastify/src/database/migrations/sqlite/meta/_journal.json +13 -0
  53. package/fastify/src/database/schema.ts +2 -0
  54. package/fastify/src/env.ts +76 -0
  55. package/fastify/src/framework/cache/cache.ts +114 -0
  56. package/fastify/src/framework/circuit-breaker/cb.ts +88 -0
  57. package/fastify/src/framework/database/app-schema.ts +37 -0
  58. package/fastify/src/framework/database/connection.ts +223 -0
  59. package/fastify/src/framework/database/migrate-hooks.ts +87 -0
  60. package/fastify/src/framework/database/paginate.ts +226 -0
  61. package/fastify/src/framework/database/schema.ts +20 -0
  62. package/fastify/src/framework/database/seed.ts +152 -0
  63. package/fastify/src/framework/events/dispatcher.ts +61 -0
  64. package/fastify/src/framework/facade.ts +96 -0
  65. package/fastify/src/framework/http/app.ts +176 -0
  66. package/fastify/src/framework/http/cors.ts +13 -0
  67. package/fastify/src/framework/http/fastify.d.ts +13 -0
  68. package/fastify/src/framework/http/logger.ts +110 -0
  69. package/fastify/src/framework/http/metrics.ts +22 -0
  70. package/fastify/src/framework/http/openapi.ts +48 -0
  71. package/fastify/src/framework/http/ratelimiter.ts +47 -0
  72. package/fastify/src/framework/http/security.ts +25 -0
  73. package/fastify/src/framework/http/static.ts +83 -0
  74. package/fastify/src/framework/http/validation.ts +49 -0
  75. package/fastify/src/framework/kernel.ts +43 -0
  76. package/fastify/src/framework/maker-cli/db/core.mjs +291 -0
  77. package/fastify/src/framework/maker-cli/db/index.mjs +204 -0
  78. package/fastify/src/framework/maker-cli/deploy/core.mjs +1046 -0
  79. package/fastify/src/framework/maker-cli/deploy/index.mjs +91 -0
  80. package/fastify/src/framework/maker-cli/index.mjs +65 -0
  81. package/fastify/src/framework/maker-cli/middleware/core.mjs +41 -0
  82. package/fastify/src/framework/maker-cli/middleware/index.mjs +17 -0
  83. package/fastify/src/framework/maker-cli/module/core.mjs +1066 -0
  84. package/fastify/src/framework/maker-cli/module/index.mjs +211 -0
  85. package/fastify/src/framework/maker-cli/provider/core.mjs +49 -0
  86. package/fastify/src/framework/maker-cli/provider/index.mjs +12 -0
  87. package/fastify/src/framework/maker-cli/runtime/build-ui.mjs +16 -0
  88. package/fastify/src/framework/maker-cli/runtime/core.mjs +560 -0
  89. package/fastify/src/framework/maker-cli/runtime/index.mjs +120 -0
  90. package/fastify/src/framework/maker-cli/runtime/redis-commander-patch.cjs +20 -0
  91. package/fastify/src/framework/maker-cli/stubs/controller/openapi.ts.stub +74 -0
  92. package/fastify/src/framework/maker-cli/stubs/controller/plain.ts.stub +77 -0
  93. package/fastify/src/framework/maker-cli/stubs/controller/standalone.ts.stub +51 -0
  94. package/fastify/src/framework/maker-cli/stubs/deploy/Dockerfile.bun.stub +52 -0
  95. package/fastify/src/framework/maker-cli/stubs/deploy/Dockerfile.pnpm.stub +55 -0
  96. package/fastify/src/framework/maker-cli/stubs/deploy/Dockerfile.stub +51 -0
  97. package/fastify/src/framework/maker-cli/stubs/deploy/Dockerfile.yarn.stub +55 -0
  98. package/fastify/src/framework/maker-cli/stubs/deploy/README.stub +59 -0
  99. package/fastify/src/framework/maker-cli/stubs/deploy/compose/mysql.server.stub +45 -0
  100. package/fastify/src/framework/maker-cli/stubs/deploy/compose/postgres.server.stub +45 -0
  101. package/fastify/src/framework/maker-cli/stubs/deploy/compose/sqlite.stub +45 -0
  102. package/fastify/src/framework/maker-cli/stubs/deploy/env/mysql.server.stub +68 -0
  103. package/fastify/src/framework/maker-cli/stubs/deploy/env/postgres.server.stub +68 -0
  104. package/fastify/src/framework/maker-cli/stubs/deploy/env/sqlite.stub +67 -0
  105. package/fastify/src/framework/maker-cli/stubs/deploy/scripts/auto-migrate.sh.stub +41 -0
  106. package/fastify/src/framework/maker-cli/stubs/deploy/server/README.stub +78 -0
  107. package/fastify/src/framework/maker-cli/stubs/deploy/server/compose/noredis.stub +120 -0
  108. package/fastify/src/framework/maker-cli/stubs/deploy/server/compose/redis.dev.stub +133 -0
  109. package/fastify/src/framework/maker-cli/stubs/deploy/server/compose/redis.stub +131 -0
  110. package/fastify/src/framework/maker-cli/stubs/deploy/server/env/local.example.stub +11 -0
  111. package/fastify/src/framework/maker-cli/stubs/deploy/server/env/noredis.stub +25 -0
  112. package/fastify/src/framework/maker-cli/stubs/deploy/server/env/redis.stub +25 -0
  113. package/fastify/src/framework/maker-cli/stubs/deploy/server/nginx-vhost/README.stub +16 -0
  114. package/fastify/src/framework/maker-cli/stubs/deploy/server/nginx-vhost/app.example.com.stub +13 -0
  115. package/fastify/src/framework/maker-cli/stubs/deploy/server/pgadmin/servers.stub +14 -0
  116. package/fastify/src/framework/maker-cli/stubs/deploy/server/redis/redis.conf.stub +7 -0
  117. package/fastify/src/framework/maker-cli/stubs/deploy/supervisor/noredis.stub +54 -0
  118. package/fastify/src/framework/maker-cli/stubs/deploy/supervisor/redis.stub +70 -0
  119. package/fastify/src/framework/maker-cli/stubs/deploy/workflow/local.json.stub +25 -0
  120. package/fastify/src/framework/maker-cli/stubs/deploy/workflow/remote.json.stub +24 -0
  121. package/fastify/src/framework/maker-cli/stubs/facade/name.ts.stub +12 -0
  122. package/fastify/src/framework/maker-cli/stubs/helper/name.ts.stub +14 -0
  123. package/fastify/src/framework/maker-cli/stubs/job/name.ts.stub +25 -0
  124. package/fastify/src/framework/maker-cli/stubs/middleware/name.local.ts.stub +15 -0
  125. package/fastify/src/framework/maker-cli/stubs/middleware/name.ts.stub +15 -0
  126. package/fastify/src/framework/maker-cli/stubs/model/name.mysql.ts.stub +10 -0
  127. package/fastify/src/framework/maker-cli/stubs/model/name.postgresql.ts.stub +10 -0
  128. package/fastify/src/framework/maker-cli/stubs/model/name.sqlite.ts.stub +10 -0
  129. package/fastify/src/framework/maker-cli/stubs/notification/controller.ts.stub +79 -0
  130. package/fastify/src/framework/maker-cli/stubs/notification/job.ts.stub +11 -0
  131. package/fastify/src/framework/maker-cli/stubs/notification/model.ts.stub +29 -0
  132. package/fastify/src/framework/maker-cli/stubs/notification/provider.ts.stub +174 -0
  133. package/fastify/src/framework/maker-cli/stubs/notification/route.api.ts.stub +71 -0
  134. package/fastify/src/framework/maker-cli/stubs/notification/route.plain.ts.stub +15 -0
  135. package/fastify/src/framework/maker-cli/stubs/notification/schema.plain.ts.stub +26 -0
  136. package/fastify/src/framework/maker-cli/stubs/notification/schema.ts.stub +26 -0
  137. package/fastify/src/framework/maker-cli/stubs/provider/module-barrel.ts.stub +19 -0
  138. package/fastify/src/framework/maker-cli/stubs/provider/module.ts.stub +21 -0
  139. package/fastify/src/framework/maker-cli/stubs/provider/name.ts.stub +21 -0
  140. package/fastify/src/framework/maker-cli/stubs/route/api.ts.stub +101 -0
  141. package/fastify/src/framework/maker-cli/stubs/route/plain.ts.stub +23 -0
  142. package/fastify/src/framework/maker-cli/stubs/route/standalone.api.ts.stub +120 -0
  143. package/fastify/src/framework/maker-cli/stubs/route/standalone.plain.ts.stub +50 -0
  144. package/fastify/src/framework/maker-cli/stubs/schedule/name.ts.stub +36 -0
  145. package/fastify/src/framework/maker-cli/stubs/schema/name.plain.ts.stub +14 -0
  146. package/fastify/src/framework/maker-cli/stubs/schema/name.ts.stub +33 -0
  147. package/fastify/src/framework/maker-cli/stubs/seeder/name.ts.stub +18 -0
  148. package/fastify/src/framework/maker-cli/stubs/seeder/standalone.ts.stub +22 -0
  149. package/fastify/src/framework/maker-cli/stubs/service/name.plain.ts.stub +67 -0
  150. package/fastify/src/framework/maker-cli/stubs/service/name.ts.stub +65 -0
  151. package/fastify/src/framework/maker-cli/stubs/test/unit.ts.stub +22 -0
  152. package/fastify/src/framework/maker-cli/stubs/type/name.ts.stub +22 -0
  153. package/fastify/src/framework/maker-cli/utils/env-config.mjs +44 -0
  154. package/fastify/src/framework/maker-cli/utils/env-db.mjs +61 -0
  155. package/fastify/src/framework/maker-cli/utils/file-ops.mjs +30 -0
  156. package/fastify/src/framework/maker-cli/utils/flags.mjs +14 -0
  157. package/fastify/src/framework/maker-cli/utils/help.mjs +379 -0
  158. package/fastify/src/framework/maker-cli/utils/naming.mjs +119 -0
  159. package/fastify/src/framework/maker-cli/utils/process.mjs +52 -0
  160. package/fastify/src/framework/maker-cli/utils/project-commands.mjs +201 -0
  161. package/fastify/src/framework/modules/discover.ts +57 -0
  162. package/fastify/src/framework/modules/routes.ts +31 -0
  163. package/fastify/src/framework/notification/channels/broadcast.ts +15 -0
  164. package/fastify/src/framework/notification/channels/mail.ts +42 -0
  165. package/fastify/src/framework/notification/contracts.ts +29 -0
  166. package/fastify/src/framework/notification/index.ts +59 -0
  167. package/fastify/src/framework/notification/registry.ts +15 -0
  168. package/fastify/src/framework/providers/adapter.ts +149 -0
  169. package/fastify/src/framework/providers/contracts.ts +126 -0
  170. package/fastify/src/framework/providers/loader.ts +105 -0
  171. package/fastify/src/framework/providers/registry.ts +88 -0
  172. package/fastify/src/framework/queue/clear.ts +22 -0
  173. package/fastify/src/framework/queue/queue.ts +401 -0
  174. package/fastify/src/framework/queue/ui.ts +194 -0
  175. package/fastify/src/framework/queue/worker.ts +61 -0
  176. package/fastify/src/framework/realtime/broadcast.ts +70 -0
  177. package/fastify/src/framework/realtime/index.ts +2 -0
  178. package/fastify/src/framework/realtime/socket-cookie.ts +72 -0
  179. package/fastify/src/framework/realtime/socket.ts +149 -0
  180. package/fastify/src/framework/realtime/types.ts +6 -0
  181. package/fastify/src/framework/realtime/ui.ts +16 -0
  182. package/fastify/src/framework/redis/client.ts +148 -0
  183. package/fastify/src/framework/runtime/runtime.ts +23 -0
  184. package/fastify/src/framework/runtime/server-adapter.ts +33 -0
  185. package/fastify/src/framework/scheduler/lock.ts +128 -0
  186. package/fastify/src/framework/scheduler/run.ts +48 -0
  187. package/fastify/src/framework/scheduler/scheduler.ts +155 -0
  188. package/fastify/src/framework/server.ts +162 -0
  189. package/fastify/src/framework/session/session.ts +160 -0
  190. package/fastify/src/framework/storage/storage.ts +744 -0
  191. package/fastify/src/framework/support/cookie.ts +71 -0
  192. package/fastify/src/framework/support/jwt.ts +33 -0
  193. package/fastify/src/framework/support/lifecycle.ts +35 -0
  194. package/fastify/src/framework/support/logger.ts +148 -0
  195. package/fastify/src/framework/support/mail.ts +56 -0
  196. package/fastify/src/framework/support/password.ts +23 -0
  197. package/fastify/src/framework/support/status-codes.ts +75 -0
  198. package/fastify/src/framework/support/upload.ts +181 -0
  199. package/fastify/src/framework/support/url.ts +41 -0
  200. package/fastify/src/middlewares/auth-middleware.ts +134 -0
  201. package/fastify/src/middlewares/role-middleware.ts +19 -0
  202. package/fastify/src/modules/auth/__tests__/forgetpass.test.ts +200 -0
  203. package/fastify/src/modules/auth/__tests__/login.test.ts +171 -0
  204. package/fastify/src/modules/auth/__tests__/logout.test.ts +60 -0
  205. package/fastify/src/modules/auth/__tests__/logoutalldevices.test.ts +49 -0
  206. package/fastify/src/modules/auth/__tests__/me.test.ts +91 -0
  207. package/fastify/src/modules/auth/__tests__/refreshtoken.test.ts +305 -0
  208. package/fastify/src/modules/auth/__tests__/register.test.ts +291 -0
  209. package/fastify/src/modules/auth/__tests__/resetpass.test.ts +206 -0
  210. package/fastify/src/modules/auth/__tests__/verifyemail.test.ts +183 -0
  211. package/fastify/src/modules/auth/controllers/auth.ts +252 -0
  212. package/fastify/src/modules/auth/controllers/role.ts +35 -0
  213. package/fastify/src/modules/auth/database/models/role.ts +14 -0
  214. package/fastify/src/modules/auth/database/models/user.ts +46 -0
  215. package/fastify/src/modules/auth/database/seeders/role.ts +18 -0
  216. package/fastify/src/modules/auth/database/seeders/user.ts +35 -0
  217. package/fastify/src/modules/auth/facade.ts +12 -0
  218. package/fastify/src/modules/auth/helpers/auth.ts +115 -0
  219. package/fastify/src/modules/auth/jobs/forgetpass.ts +20 -0
  220. package/fastify/src/modules/auth/jobs/registeruser.ts +23 -0
  221. package/fastify/src/modules/auth/jobs/verifyemail.ts +18 -0
  222. package/fastify/src/modules/auth/routes/index.ts +185 -0
  223. package/fastify/src/modules/auth/routes/role.ts +56 -0
  224. package/fastify/src/modules/auth/schemas/auth.ts +116 -0
  225. package/fastify/src/modules/auth/services/forgetpassword.ts +66 -0
  226. package/fastify/src/modules/auth/services/login.ts +63 -0
  227. package/fastify/src/modules/auth/services/logout.ts +25 -0
  228. package/fastify/src/modules/auth/services/logoutalldevices.ts +19 -0
  229. package/fastify/src/modules/auth/services/me.ts +31 -0
  230. package/fastify/src/modules/auth/services/refreshtoken.ts +110 -0
  231. package/fastify/src/modules/auth/services/register.ts +141 -0
  232. package/fastify/src/modules/auth/services/resetpassword.ts +69 -0
  233. package/fastify/src/modules/auth/services/verifyemail.ts +77 -0
  234. package/fastify/src/modules/auth/types/auth.ts +31 -0
  235. package/fastify/src/providers/README.md +107 -0
  236. package/fastify/src/providers/notification.ts +4 -0
  237. package/fastify/src/resources/index.html +17 -0
  238. package/fastify/src/resources/src/App.vue +5 -0
  239. package/fastify/src/resources/src/assets/css/styles.css +14761 -0
  240. package/fastify/src/resources/src/assets/css/styles.css.map +1 -0
  241. package/fastify/src/resources/src/assets/fonts/public-sans/public-sans-latin-ext.woff2 +0 -0
  242. package/fastify/src/resources/src/assets/fonts/public-sans/public-sans-latin.woff2 +0 -0
  243. package/fastify/src/resources/src/assets/images/favicon/favicon.ico +0 -0
  244. package/fastify/src/resources/src/assets/images/logo.png +0 -0
  245. package/fastify/src/resources/src/assets/scss/custom.css +217 -0
  246. package/fastify/src/resources/src/assets/scss/custom.css.map +1 -0
  247. package/fastify/src/resources/src/assets/scss/custom.scss +1346 -0
  248. package/fastify/src/resources/src/components/Button.vue +32 -0
  249. package/fastify/src/resources/src/components/Checkbox.vue +32 -0
  250. package/fastify/src/resources/src/components/Datepicker.vue +106 -0
  251. package/fastify/src/resources/src/components/FeatureButton.vue +53 -0
  252. package/fastify/src/resources/src/components/FloatButton.vue +33 -0
  253. package/fastify/src/resources/src/components/Href.vue +32 -0
  254. package/fastify/src/resources/src/components/Input.vue +243 -0
  255. package/fastify/src/resources/src/components/InputGroup.vue +147 -0
  256. package/fastify/src/resources/src/components/InputPasswordToggle.vue +229 -0
  257. package/fastify/src/resources/src/components/Modal.vue +71 -0
  258. package/fastify/src/resources/src/components/Pagebar.vue +26 -0
  259. package/fastify/src/resources/src/components/Refresh.vue +19 -0
  260. package/fastify/src/resources/src/components/Select.vue +384 -0
  261. package/fastify/src/resources/src/components/Spinner.vue +42 -0
  262. package/fastify/src/resources/src/components/Switch.vue +60 -0
  263. package/fastify/src/resources/src/components/TextArea.vue +117 -0
  264. package/fastify/src/resources/src/components/Toast.vue +56 -0
  265. package/fastify/src/resources/src/components/datatable/DataTableSkeleton.vue +98 -0
  266. package/fastify/src/resources/src/components/datatable/Pagination.vue +147 -0
  267. package/fastify/src/resources/src/components/datatable/SelectOpption.vue +64 -0
  268. package/fastify/src/resources/src/components/datatable/index.vue +199 -0
  269. package/fastify/src/resources/src/composables/useAuth.ts +52 -0
  270. package/fastify/src/resources/src/helpers/assets.ts +51 -0
  271. package/fastify/src/resources/src/helpers/nformatter.ts +10 -0
  272. package/fastify/src/resources/src/helpers/utils.ts +75 -0
  273. package/fastify/src/resources/src/layouts/AuthLayout.vue +20 -0
  274. package/fastify/src/resources/src/layouts/Layout/Footer.vue +23 -0
  275. package/fastify/src/resources/src/layouts/Layout/Header.vue +124 -0
  276. package/fastify/src/resources/src/layouts/Layout/Sidebar.vue +137 -0
  277. package/fastify/src/resources/src/layouts/Layout/index.vue +87 -0
  278. package/fastify/src/resources/src/main.ts +28 -0
  279. package/fastify/src/resources/src/pages/auth/forgetPassword.vue +76 -0
  280. package/fastify/src/resources/src/pages/auth/login.vue +96 -0
  281. package/fastify/src/resources/src/pages/auth/register.vue +129 -0
  282. package/fastify/src/resources/src/pages/auth/resetPassword.vue +110 -0
  283. package/fastify/src/resources/src/pages/auth/verifyEmail.vue +64 -0
  284. package/fastify/src/resources/src/pages/dashboard/index.vue +66 -0
  285. package/fastify/src/resources/src/plugins/axios.ts +31 -0
  286. package/fastify/src/resources/src/plugins/browserDetect.ts +55 -0
  287. package/fastify/src/resources/src/plugins/dialog.ts +216 -0
  288. package/fastify/src/resources/src/plugins/gum.ts +683 -0
  289. package/fastify/src/resources/src/plugins/pulse.ts +157 -0
  290. package/fastify/src/resources/src/plugins/routeProgress.ts +87 -0
  291. package/fastify/src/resources/src/router/index.ts +85 -0
  292. package/fastify/src/resources/src/stores/admin-ui.ts +148 -0
  293. package/fastify/src/resources/src/stores/auth.ts +187 -0
  294. package/fastify/src/resources/tsconfig.json +19 -0
  295. package/fastify/src/resources/vite.config.ts +64 -0
  296. package/fastify/src/storage/app/private/.gitkeep +0 -0
  297. package/fastify/src/storage/app/public/.gitkeep +0 -0
  298. package/fastify/src/storage/app/tmp/generated/.gitkeep +0 -0
  299. package/fastify/src/storage/database/nexwire.sqlite +0 -0
  300. package/fastify/src/storage/logs/.gitkeep +0 -0
  301. package/fastify/src/storage/logs/app.log +0 -0
  302. package/fastify/src/storage/logs/fatal.log +0 -0
  303. package/fastify/src/storage/tmp/.gitkeep +0 -0
  304. package/fastify/src/storage/trash/modules/.gitkeep +0 -0
  305. package/fastify/src/types/global.d.ts +32 -0
  306. package/fastify/tsconfig.json +19 -0
  307. package/fastify/vitest.config.ts +38 -0
  308. package/hono/src/framework/facade.ts +1 -0
  309. package/hono/src/framework/http/logger.ts +86 -81
  310. package/hono/src/framework/maker-cli/runtime/core.mjs +1 -2
  311. package/hono/src/framework/notification/channels/mail.ts +8 -6
  312. package/hono/src/middlewares/auth-middleware.ts +1 -2
  313. package/hono/src/middlewares/role-middleware.ts +3 -13
  314. package/hono/src/modules/auth/routes/index.ts +1 -2
  315. package/hono/src/providers/notification.ts +2 -2
  316. package/hono/src/resources/src/components/Switch.vue +60 -65
  317. package/hono/src/resources/src/pages/auth/forgetPassword.vue +23 -29
  318. package/hono/src/resources/src/pages/auth/login.vue +26 -29
  319. package/hono/src/resources/src/pages/auth/register.vue +36 -40
  320. package/hono/src/resources/src/pages/auth/resetPassword.vue +29 -37
  321. package/hono/src/resources/src/pages/auth/verifyEmail.vue +15 -19
  322. package/hono/src/resources/src/plugins/gum.ts +519 -203
  323. package/hono/src/resources/src/stores/auth.ts +9 -6
  324. package/hono/src/storage/database/nexwire.sqlite +0 -0
  325. package/package.json +3 -2
  326. package/src/index.js +11 -8
@@ -0,0 +1,46 @@
1
+ import { relations } from "drizzle-orm";
2
+ import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
3
+ import { roles } from "@/modules/auth/database/models/role.js";
4
+
5
+ export const users = sqliteTable("users", {
6
+ id: integer("id").primaryKey({ autoIncrement: true }),
7
+ name: text("name").notNull(),
8
+ email: text("email").notNull().unique(),
9
+ password: text("password").notNull(),
10
+ roleId: integer("role_id").references(() => roles.id, { onUpdate: "cascade", onDelete: "set null" }),
11
+ emailVerifiedAt: integer("email_verified_at", { mode: "timestamp" }),
12
+ createdAt: integer("created_at", { mode: "timestamp" }).defaultNow().notNull(),
13
+ updatedAt: integer("updated_at", { mode: "timestamp" }).defaultNow().notNull()
14
+ });
15
+
16
+ export const emailVerificationTokens = sqliteTable("email_verification_tokens", {
17
+ id: integer("id").primaryKey({ autoIncrement: true }),
18
+ email: text("email").notNull(),
19
+ token: text("token").notNull(),
20
+ expiresAt: integer("expires_at", { mode: "timestamp" }).notNull(),
21
+ createdAt: integer("created_at", { mode: "timestamp" }).defaultNow().notNull()
22
+ });
23
+
24
+ export const passwordResetTokens = sqliteTable("password_reset_tokens", {
25
+ id: integer("id").primaryKey({ autoIncrement: true }),
26
+ email: text("email").notNull(),
27
+ token: text("token").notNull(),
28
+ expiresAt: integer("expires_at", { mode: "timestamp" }).notNull(),
29
+ createdAt: integer("created_at", { mode: "timestamp" }).defaultNow().notNull()
30
+ });
31
+
32
+ export const refreshTokens = sqliteTable("refresh_tokens", {
33
+ id: integer("id").primaryKey({ autoIncrement: true }),
34
+ userId: integer("user_id").references(() => users.id, { onUpdate: "cascade", onDelete: "set null" }),
35
+ jti: text("jti").notNull().unique(),
36
+ revoked: integer("revoked", { mode: "boolean" }).default(false),
37
+ expiresAt: integer("expires_at", { mode: "timestamp" }).notNull(),
38
+ createdAt: integer("created_at", { mode: "timestamp" }).defaultNow().notNull()
39
+ });
40
+
41
+ export const usersRelations = relations(users, ({ one }) => ({
42
+ role: one(roles, {
43
+ fields: [users.roleId],
44
+ references: [roles.id]
45
+ })
46
+ }));
@@ -0,0 +1,18 @@
1
+ import { eq } from "drizzle-orm";
2
+ import { db } from "@/framework/facade.js";
3
+ import { roles } from "@/modules/auth/database/models/role.js";
4
+
5
+ export const table = roles;
6
+
7
+ export default async function RoleSeeder() {
8
+ const rows = [{ name: "admin" }, { name: "user" }];
9
+
10
+ for (const row of rows) {
11
+ const existing = await db.query.roles.findFirst({ where: eq(roles.name, row.name) });
12
+ if (!existing) {
13
+ await db.insert(roles).values({ name: row.name });
14
+ }
15
+ }
16
+
17
+ console.log("Role seeder completed");
18
+ }
@@ -0,0 +1,35 @@
1
+ import { eq } from "drizzle-orm";
2
+ import { db, password } from "@/framework/facade.js";
3
+ import { roles } from "@/modules/auth/database/models/role.js";
4
+ import { users } from "@/modules/auth/database/models/user.js";
5
+
6
+ export const table = users;
7
+
8
+ export default async function UserSeeder() {
9
+ const adminRole = await db.query.roles.findFirst({ where: eq(roles.name, "admin") });
10
+ const userRole = await db.query.roles.findFirst({ where: eq(roles.name, "user") });
11
+
12
+ const rows = [
13
+ {
14
+ name: "Admin",
15
+ email: "admin@example.com",
16
+ password: await password.hashPassword("Password@123"),
17
+ roleId: adminRole?.id ?? null
18
+ },
19
+ {
20
+ name: "User One",
21
+ email: "user1@example.com",
22
+ password: await password.hashPassword("Password@123"),
23
+ roleId: userRole?.id ?? null
24
+ }
25
+ ];
26
+
27
+ for (const row of rows) {
28
+ const existing = await db.query.users.findFirst({ where: eq(users.email, row.email) });
29
+ if (!existing) {
30
+ await db.insert(users).values(row);
31
+ }
32
+ }
33
+
34
+ console.log("User seeder completed");
35
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Public API for the auth module.
3
+ *
4
+ * Other modules import from this file, never from controllers/ or services/ directly.
5
+ * Re-export the pieces they are allowed to depend on:
6
+ *
7
+ * export { list, findOne } from "./services/auth.js";
8
+ *
9
+ * Rule: a facade must never import another module's facade.
10
+ */
11
+
12
+ export { getCurrentUser, hasRole } from "@/modules/auth/helpers/auth.js";
@@ -0,0 +1,115 @@
1
+ import { createHash, randomBytes } from "node:crypto";
2
+ import { eq } from "drizzle-orm";
3
+ import type { FastifyReply, FastifyRequest } from "fastify";
4
+ import { jwtConfig } from "@/config/index.js";
5
+ import { cookie, db, jwt } from "@/framework/facade.js";
6
+ import { refreshTokens, users } from "@/modules/auth/database/models/user.js";
7
+
8
+ export function hasRole(auth: any, rolesToMatch: string[]) {
9
+ const role = String(auth?.role || "").toLowerCase();
10
+ return rolesToMatch.includes(role);
11
+ }
12
+
13
+ export async function getCurrentUser(auth: any) {
14
+ if (!auth?.id) return null;
15
+ return db.query.users.findFirst({
16
+ where: eq(users.id, Number(auth.id)),
17
+ with: { role: true },
18
+ columns: {
19
+ password: false,
20
+ rememberToken: false
21
+ }
22
+ });
23
+ }
24
+
25
+ export function sanitizeUser(user: any) {
26
+ return {
27
+ id: user.id,
28
+ name: user.name,
29
+ email: user.email,
30
+ emailVerifiedAt: user.emailVerifiedAt ? String(user.emailVerifiedAt) : null,
31
+ roleId: user.roleId ?? null,
32
+ role: user.role
33
+ ? {
34
+ id: user.role.id,
35
+ name: user.role.name,
36
+ createdAt: user.role.createdAt ? String(user.role.createdAt) : null,
37
+ updatedAt: user.role.updatedAt ? String(user.role.updatedAt) : null
38
+ }
39
+ : null,
40
+ createdAt: user.createdAt ? String(user.createdAt) : null,
41
+ updatedAt: user.updatedAt ? String(user.updatedAt) : null
42
+ };
43
+ }
44
+
45
+ export function makeResetToken() {
46
+ return randomBytes(32).toString("hex");
47
+ }
48
+
49
+ export function makeEmailVerificationToken() {
50
+ return randomBytes(32).toString("hex");
51
+ }
52
+
53
+ export function hashResetToken(token: string) {
54
+ return createHash("sha256").update(token).digest("hex");
55
+ }
56
+
57
+ export function hashEmailVerificationToken(token: string) {
58
+ return createHash("sha256").update(token).digest("hex");
59
+ }
60
+
61
+ export async function revokeCurrentRefreshToken(request: FastifyRequest) {
62
+ const token = await cookie.getRefresh(request);
63
+ if (!token) return;
64
+
65
+ const payload = await jwt.verifyToken(token, "refresh");
66
+ if (payload?.jti) {
67
+ await db.delete(refreshTokens).where(eq(refreshTokens.jti, payload.jti as string));
68
+ }
69
+ }
70
+
71
+ export async function issueTokens(
72
+ _request: FastifyRequest,
73
+ reply: FastifyReply,
74
+ user: any,
75
+ options?: { remember?: boolean }
76
+ ) {
77
+ const remember = !!options?.remember;
78
+ const refreshExpiry = remember ? jwtConfig.refreshRememberExpirySeconds : jwtConfig.refreshExpirySeconds;
79
+ const role = user.role || null;
80
+ const accessToken = await jwt.generateToken(
81
+ {
82
+ id: user.id,
83
+ email: user.email,
84
+ roleId: role?.id ?? null,
85
+ role: role?.name ?? null,
86
+ remember
87
+ },
88
+ "access"
89
+ );
90
+ const refreshToken = await jwt.generateToken(
91
+ {
92
+ id: user.id,
93
+ email: user.email,
94
+ roleId: role?.id ?? null,
95
+ role: role?.name ?? null,
96
+ remember
97
+ },
98
+ "refresh",
99
+ refreshExpiry
100
+ );
101
+
102
+ if (refreshToken.jti) {
103
+ await db.insert(refreshTokens).values({
104
+ userId: user.id,
105
+ jti: refreshToken.jti,
106
+ revoked: 0,
107
+ expiresAt: new Date(refreshToken.exp * 1000)
108
+ });
109
+ }
110
+
111
+ await cookie.setAuth(reply, accessToken.token);
112
+ await cookie.setRefresh(reply, refreshToken.token, refreshExpiry);
113
+
114
+ return { accessToken: accessToken.token, refreshToken: refreshToken.token };
115
+ }
@@ -0,0 +1,20 @@
1
+ import { dispatchEvent, mail, shouldQueue } from "@/framework/facade.js";
2
+
3
+ shouldQueue("user:forget-password", "mail", async (job: any) => {
4
+ const { email, name, resetUrl } = job.data;
5
+
6
+ await mail.sendMail({
7
+ to: email,
8
+ subject: "Reset Your Password",
9
+ html: `
10
+ <p>Hello ${name},</p>
11
+ <p>Click the link below to reset your password:</p>
12
+ <p><a href="${resetUrl}">${resetUrl}</a></p>
13
+ <p>This link will expire in 15 minutes.</p>
14
+ `
15
+ });
16
+
17
+ await dispatchEvent("user.changed", { email: email }, { broadcast: { auth: true } });
18
+
19
+ return { ok: true, resetUrl };
20
+ });
@@ -0,0 +1,23 @@
1
+ import { DateTime as Datetime } from "luxon";
2
+ import { dispatchEvent, mail, shouldQueue } from "@/framework/facade.js";
3
+
4
+ shouldQueue("user:signup", "mail", async (job: any) => {
5
+ const { email, name, userId } = job.data;
6
+
7
+ await mail.sendMail({
8
+ to: email,
9
+ subject: "Welcome to <AppName>",
10
+ html: `
11
+ <p>Hello ${name},</p>
12
+ <p>Your account was created successfully.</p>
13
+ <p>You can log in with the email and password you chose during signup.</p>
14
+ <p><a href="https://app.example.com/login">Log in</a></p>
15
+ `
16
+ });
17
+
18
+ await dispatchEvent("admin.user.registered", { userId, name, email, createdAt: Datetime.now() }, { broadcast: { roles: ["admin"] } });
19
+
20
+ await dispatchEvent("user.registered", { message: "Welcome! Your account has been created." }, { broadcast: { users: [userId] } });
21
+
22
+ return { ok: true, userId };
23
+ });
@@ -0,0 +1,18 @@
1
+ import { mail, shouldQueue } from "@/framework/facade.js";
2
+
3
+ shouldQueue("user:verify-email", "mail", async (job: any) => {
4
+ const { email, name, verifyUrl } = job.data;
5
+
6
+ await mail.sendMail({
7
+ to: email,
8
+ subject: "Verify Your Email",
9
+ html: `
10
+ <p>Hello ${name},</p>
11
+ <p>Thanks for registering. Please verify your email by clicking the link below:</p>
12
+ <p><a href="${verifyUrl}">${verifyUrl}</a></p>
13
+ <p>This link will expire in 24 hours.</p>
14
+ `
15
+ });
16
+
17
+ return { ok: true, verifyUrl };
18
+ });
@@ -0,0 +1,185 @@
1
+ import type { FastifyPluginAsyncZod } from "fastify-type-provider-zod";
2
+ import { HttpStatusCodes, loginLimiter, ValidationErrorSchema, z } from "@/framework/facade.js";
3
+ import { authMiddleware } from "@/middlewares/auth-middleware.js";
4
+ import {
5
+ forgotPassword,
6
+ login,
7
+ logout,
8
+ logoutAllDevices,
9
+ me,
10
+ refreshToken,
11
+ register,
12
+ resetPassword,
13
+ verifyEmail
14
+ } from "@/modules/auth/controllers/auth.js";
15
+ import {
16
+ AuthResponseSchema,
17
+ ForgotPasswordSchema,
18
+ LoginSchema,
19
+ MeResponseSchema,
20
+ MessageSchema,
21
+ RefreshTokenSchema,
22
+ RegisterResponseSchema,
23
+ RegisterSchema,
24
+ ResetPasswordSchema,
25
+ VerifyEmailSchema
26
+ } from "@/modules/auth/schemas/auth.js";
27
+
28
+ const ErrorSchema = z.object({ message: z.string() });
29
+
30
+ /**
31
+ * Why: Auth HTTP surface, split into public and protected scopes.
32
+ * When: Mounted by the module route loader at `/api/auth`.
33
+ * Where: `src/modules/auth/routes/index.ts`.
34
+ * How: Public routes use the strict login rate limit; protected routes live in
35
+ * a child plugin whose scoped `preHandler` hook resolves `request.auth`.
36
+ */
37
+ const authRoutes: FastifyPluginAsyncZod = async (app) => {
38
+ app.route({
39
+ method: "POST",
40
+ url: "/register",
41
+ schema: {
42
+ tags: ["Auth"],
43
+ description: "Register a new user",
44
+ body: RegisterSchema,
45
+ response: {
46
+ [HttpStatusCodes.CREATED]: RegisterResponseSchema,
47
+ [HttpStatusCodes.UNPROCESSABLE_ENTITY]: ValidationErrorSchema
48
+ }
49
+ },
50
+ config: { rateLimit: loginLimiter },
51
+ handler: register
52
+ });
53
+
54
+ app.route({
55
+ method: "POST",
56
+ url: "/login",
57
+ schema: {
58
+ tags: ["Auth"],
59
+ description: "Login user",
60
+ body: LoginSchema,
61
+ response: {
62
+ [HttpStatusCodes.OK]: AuthResponseSchema,
63
+ [HttpStatusCodes.UNAUTHORIZED]: ErrorSchema,
64
+ [HttpStatusCodes.FORBIDDEN]: ErrorSchema,
65
+ [HttpStatusCodes.UNPROCESSABLE_ENTITY]: ValidationErrorSchema
66
+ }
67
+ },
68
+ config: { rateLimit: loginLimiter },
69
+ handler: login
70
+ });
71
+
72
+ app.route({
73
+ method: "POST",
74
+ url: "/forgot-password",
75
+ schema: {
76
+ tags: ["Auth"],
77
+ description: "Send reset password email",
78
+ body: ForgotPasswordSchema,
79
+ response: {
80
+ [HttpStatusCodes.OK]: MessageSchema,
81
+ [HttpStatusCodes.UNPROCESSABLE_ENTITY]: ValidationErrorSchema
82
+ }
83
+ },
84
+ config: { rateLimit: loginLimiter },
85
+ handler: forgotPassword
86
+ });
87
+
88
+ app.route({
89
+ method: "POST",
90
+ url: "/reset-password",
91
+ schema: {
92
+ tags: ["Auth"],
93
+ description: "Reset password using token",
94
+ body: ResetPasswordSchema,
95
+ response: {
96
+ [HttpStatusCodes.OK]: MessageSchema,
97
+ [HttpStatusCodes.UNPROCESSABLE_ENTITY]: ValidationErrorSchema
98
+ }
99
+ },
100
+ config: { rateLimit: loginLimiter },
101
+ handler: resetPassword
102
+ });
103
+
104
+ app.route({
105
+ method: "POST",
106
+ url: "/verify-email",
107
+ schema: {
108
+ tags: ["Auth"],
109
+ description: "Verify user email using token",
110
+ body: VerifyEmailSchema,
111
+ response: {
112
+ [HttpStatusCodes.OK]: MessageSchema,
113
+ [HttpStatusCodes.UNPROCESSABLE_ENTITY]: ValidationErrorSchema
114
+ }
115
+ },
116
+ config: { rateLimit: loginLimiter },
117
+ handler: verifyEmail
118
+ });
119
+
120
+ app.route({
121
+ method: "POST",
122
+ url: "/refresh-token",
123
+ schema: {
124
+ tags: ["Auth"],
125
+ description: "Refresh access token",
126
+ body: RefreshTokenSchema,
127
+ response: {
128
+ [HttpStatusCodes.OK]: AuthResponseSchema,
129
+ [HttpStatusCodes.UNAUTHORIZED]: ErrorSchema,
130
+ [HttpStatusCodes.UNPROCESSABLE_ENTITY]: ValidationErrorSchema
131
+ }
132
+ },
133
+ config: { rateLimit: loginLimiter },
134
+ handler: refreshToken
135
+ });
136
+
137
+ await app.register(async (protectedScope) => {
138
+ protectedScope.addHook("preHandler", authMiddleware);
139
+
140
+ protectedScope.route({
141
+ method: "GET",
142
+ url: "/me",
143
+ schema: {
144
+ tags: ["Auth"],
145
+ description: "Get authenticated user",
146
+ response: {
147
+ [HttpStatusCodes.OK]: MeResponseSchema,
148
+ [HttpStatusCodes.UNAUTHORIZED]: ErrorSchema,
149
+ [HttpStatusCodes.NOT_FOUND]: ErrorSchema
150
+ }
151
+ },
152
+ handler: me
153
+ });
154
+
155
+ protectedScope.route({
156
+ method: "POST",
157
+ url: "/logout",
158
+ schema: {
159
+ tags: ["Auth"],
160
+ description: "Logout user from current device",
161
+ response: {
162
+ [HttpStatusCodes.OK]: MessageSchema,
163
+ [HttpStatusCodes.UNAUTHORIZED]: ErrorSchema
164
+ }
165
+ },
166
+ handler: logout
167
+ });
168
+
169
+ protectedScope.route({
170
+ method: "POST",
171
+ url: "/logout-all",
172
+ schema: {
173
+ tags: ["Auth"],
174
+ description: "Logout user from all devices",
175
+ response: {
176
+ [HttpStatusCodes.OK]: MessageSchema,
177
+ [HttpStatusCodes.UNAUTHORIZED]: ErrorSchema
178
+ }
179
+ },
180
+ handler: logoutAllDevices
181
+ });
182
+ });
183
+ };
184
+
185
+ export default authRoutes;
@@ -0,0 +1,56 @@
1
+ import type { FastifyPluginAsyncZod } from "fastify-type-provider-zod";
2
+ import { HttpStatusCodes, ValidationErrorSchema, z } from "@/framework/facade.js";
3
+ import { authMiddleware } from "@/middlewares/auth-middleware.js";
4
+ import { requireRole } from "@/middlewares/role-middleware.js";
5
+ import { index, show } from "@/modules/auth/controllers/role.js";
6
+ import { IdParamsSchema, RoleSchema } from "@/modules/auth/schemas/auth.js";
7
+
8
+ const ErrorSchema = z.object({ message: z.string() });
9
+
10
+ /**
11
+ * Why: Admin-only role lookup endpoints.
12
+ * When: Mounted by the module route loader at `/api/auth`.
13
+ * Where: `src/modules/auth/routes/role.ts`.
14
+ * How: A scoped `preHandler` chain runs auth first, then the role check.
15
+ */
16
+ const roleRoutes: FastifyPluginAsyncZod = async (app) => {
17
+ await app.register(async (scope) => {
18
+ scope.addHook("preHandler", authMiddleware);
19
+ scope.addHook("preHandler", requireRole("admin"));
20
+
21
+ scope.route({
22
+ method: "GET",
23
+ url: "/role",
24
+ schema: {
25
+ tags: ["Role"],
26
+ description: "List all roles",
27
+ response: {
28
+ [HttpStatusCodes.OK]: z.object({ message: z.string(), data: z.array(RoleSchema) }),
29
+ [HttpStatusCodes.UNAUTHORIZED]: ErrorSchema,
30
+ [HttpStatusCodes.UNPROCESSABLE_ENTITY]: ValidationErrorSchema,
31
+ [HttpStatusCodes.FORBIDDEN]: ErrorSchema
32
+ }
33
+ },
34
+ handler: index
35
+ });
36
+
37
+ scope.route({
38
+ method: "GET",
39
+ url: "/role/:id",
40
+ schema: {
41
+ tags: ["Role"],
42
+ description: "Show one role",
43
+ params: IdParamsSchema,
44
+ response: {
45
+ [HttpStatusCodes.OK]: z.object({ message: z.string(), data: RoleSchema.nullable() }),
46
+ [HttpStatusCodes.UNAUTHORIZED]: ErrorSchema,
47
+ [HttpStatusCodes.UNPROCESSABLE_ENTITY]: ValidationErrorSchema,
48
+ [HttpStatusCodes.FORBIDDEN]: ErrorSchema
49
+ }
50
+ },
51
+ handler: show
52
+ });
53
+ });
54
+ };
55
+
56
+ export default roleRoutes;
@@ -0,0 +1,116 @@
1
+ import { z } from "@/framework/facade.js";
2
+
3
+ export const MessageSchema = z.object({
4
+ message: z.string()
5
+ });
6
+
7
+ export const RoleSchema = z.object({
8
+ id: z.number(),
9
+ name: z.string(),
10
+ createdAt: z.string().nullable().optional(),
11
+ updatedAt: z.string().nullable().optional()
12
+ });
13
+
14
+ export const UserSchema = z.object({
15
+ id: z.number(),
16
+ name: z.string(),
17
+ email: z.email(),
18
+ roleId: z.number().nullable().optional(),
19
+ role: RoleSchema.nullable().optional(),
20
+ emailVerifiedAt: z.string().nullable().optional(),
21
+ createdAt: z.string().nullable().optional(),
22
+ updatedAt: z.string().nullable().optional()
23
+ });
24
+
25
+ export const RegisterSchema = z
26
+ .object({
27
+ name: z.string().min(2).max(100),
28
+ email: z.email(),
29
+ password: z
30
+ .string()
31
+ .min(6)
32
+ .max(100)
33
+ .regex(/[a-z]/, "Password must contain lowercase letter")
34
+ .regex(/[A-Z]/, "Password must contain uppercase letter")
35
+ .regex(/[^A-Za-z0-9]/, "Password must contain special character"),
36
+ password_confirmation: z.string()
37
+ })
38
+ .superRefine((data, ctx) => {
39
+ if (data.password !== data.password_confirmation) {
40
+ ctx.addIssue({
41
+ code: "custom",
42
+ path: ["password_confirmation"],
43
+ message: "Password confirmation does not match"
44
+ });
45
+ }
46
+ });
47
+
48
+ export const LoginSchema = z.object({
49
+ email: z.email(),
50
+ password: z.string().min(1),
51
+ remember: z.boolean().optional().default(false)
52
+ });
53
+
54
+ export const ForgotPasswordSchema = z.object({
55
+ email: z.email()
56
+ });
57
+
58
+ export const ResetPasswordSchema = z
59
+ .object({
60
+ email: z.email(),
61
+ token: z.string().min(1),
62
+ password: z
63
+ .string()
64
+ .min(6)
65
+ .max(100)
66
+ .regex(/[a-z]/, "Password must contain lowercase letter")
67
+ .regex(/[A-Z]/, "Password must contain uppercase letter")
68
+ .regex(/[^A-Za-z0-9]/, "Password must contain special character"),
69
+ password_confirmation: z.string()
70
+ })
71
+ .superRefine((data, ctx) => {
72
+ if (data.password !== data.password_confirmation) {
73
+ ctx.addIssue({
74
+ code: "custom",
75
+ path: ["password_confirmation"],
76
+ message: "Password confirmation does not match"
77
+ });
78
+ }
79
+ });
80
+
81
+ export const RefreshTokenSchema = z.object({
82
+ refresh_token: z.string().min(1)
83
+ });
84
+
85
+ export const VerifyEmailSchema = z.object({
86
+ email: z.email(),
87
+ token: z.string().min(1)
88
+ });
89
+
90
+ export const AuthResponseSchema = z.object({
91
+ message: z.string(),
92
+ data: z.object({
93
+ user: UserSchema,
94
+ access_token: z.string(),
95
+ refresh_token: z.string(),
96
+ token_type: z.literal("Bearer")
97
+ })
98
+ });
99
+
100
+ /**
101
+ * Register returns 201 with only `message` when email verification is required,
102
+ * so `data` must be optional. Fastify enforces response schemas at runtime.
103
+ */
104
+ export const RegisterResponseSchema = z.object({
105
+ message: z.string(),
106
+ data: AuthResponseSchema.shape.data.optional()
107
+ });
108
+
109
+ export const MeResponseSchema = z.object({
110
+ message: z.string(),
111
+ data: UserSchema
112
+ });
113
+
114
+ export const IdParamsSchema = z.object({
115
+ id: z.coerce.number()
116
+ });