create-nexwire 4.0.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.
- package/README.md +233 -0
- package/express/.dockerignore +14 -0
- package/express/.env +44 -0
- package/express/.env.example +42 -0
- package/express/.vscode/settings.json +26 -0
- package/express/LICENSE +21 -0
- package/express/README.md +211 -0
- package/express/biome.json +66 -0
- package/express/drizzle.config.ts +25 -0
- package/express/gitignore-stub +24 -0
- package/express/package.json +108 -0
- package/express/public/.gitkeep +0 -0
- package/express/src/config/app.ts +41 -0
- package/express/src/config/auth.ts +12 -0
- package/express/src/config/cache.ts +16 -0
- package/express/src/config/cookie.ts +15 -0
- package/express/src/config/cors.ts +12 -0
- package/express/src/config/database.ts +29 -0
- package/express/src/config/index.ts +83 -0
- package/express/src/config/jwt.ts +19 -0
- package/express/src/config/logging.ts +13 -0
- package/express/src/config/mail.ts +24 -0
- package/express/src/config/openapi.ts +54 -0
- package/express/src/config/queue.ts +30 -0
- package/express/src/config/rateLimit.ts +17 -0
- package/express/src/config/realtime.ts +15 -0
- package/express/src/config/redis.ts +18 -0
- package/express/src/config/security.ts +44 -0
- package/express/src/config/session.ts +17 -0
- package/express/src/config/storage.ts +22 -0
- package/express/src/config/validate.ts +40 -0
- package/express/src/database/migrations/sqlite/0000_init.sql +61 -0
- package/express/src/database/migrations/sqlite/meta/0000_snapshot.json +412 -0
- package/express/src/database/migrations/sqlite/meta/_journal.json +13 -0
- package/express/src/database/schema.ts +3 -0
- package/express/src/env.ts +76 -0
- package/express/src/framework/cache/cache.ts +81 -0
- package/express/src/framework/circuit-breaker/cb.ts +60 -0
- package/express/src/framework/database/connection.ts +196 -0
- package/express/src/framework/database/migrate-hooks.ts +87 -0
- package/express/src/framework/database/paginate.ts +227 -0
- package/express/src/framework/database/schema.ts +20 -0
- package/express/src/framework/database/seed.ts +139 -0
- package/express/src/framework/events/dispatcher.ts +49 -0
- package/express/src/framework/facade.ts +48 -0
- package/express/src/framework/http/app.ts +107 -0
- package/express/src/framework/http/cors.ts +7 -0
- package/express/src/framework/http/logger.ts +69 -0
- package/express/src/framework/http/metrics.ts +22 -0
- package/express/src/framework/http/openapi.ts +54 -0
- package/express/src/framework/http/ratelimiter.ts +16 -0
- package/express/src/framework/http/router.ts +178 -0
- package/express/src/framework/http/security.ts +23 -0
- package/express/src/framework/http/static.ts +23 -0
- package/express/src/framework/http/validation.ts +18 -0
- package/express/src/framework/kernel.ts +52 -0
- package/express/src/framework/maker-cli/db/core.mjs +288 -0
- package/express/src/framework/maker-cli/db/index.mjs +204 -0
- package/express/src/framework/maker-cli/deploy/core.mjs +1047 -0
- package/express/src/framework/maker-cli/deploy/index.mjs +91 -0
- package/express/src/framework/maker-cli/index.mjs +53 -0
- package/express/src/framework/maker-cli/middleware/core.mjs +47 -0
- package/express/src/framework/maker-cli/middleware/index.mjs +17 -0
- package/express/src/framework/maker-cli/module/core.mjs +684 -0
- package/express/src/framework/maker-cli/module/index.mjs +140 -0
- package/express/src/framework/maker-cli/runtime/build-ui.mjs +16 -0
- package/express/src/framework/maker-cli/runtime/core.mjs +543 -0
- package/express/src/framework/maker-cli/runtime/index.mjs +104 -0
- package/express/src/framework/maker-cli/runtime/redis-commander-patch.cjs +20 -0
- package/express/src/framework/maker-cli/stubs/controller/openapi.ts.stub +47 -0
- package/express/src/framework/maker-cli/stubs/controller/openapi.with-model.ts.stub +48 -0
- package/express/src/framework/maker-cli/stubs/controller/plain.ts.stub +54 -0
- package/express/src/framework/maker-cli/stubs/controller/schema.plain.ts.stub +14 -0
- package/express/src/framework/maker-cli/stubs/controller/schema.ts.stub +33 -0
- package/express/src/framework/maker-cli/stubs/deploy/Dockerfile.bun.stub +52 -0
- package/express/src/framework/maker-cli/stubs/deploy/Dockerfile.pnpm.stub +55 -0
- package/express/src/framework/maker-cli/stubs/deploy/Dockerfile.stub +51 -0
- package/express/src/framework/maker-cli/stubs/deploy/Dockerfile.yarn.stub +55 -0
- package/express/src/framework/maker-cli/stubs/deploy/README.stub +59 -0
- package/express/src/framework/maker-cli/stubs/deploy/compose/mysql.server.stub +45 -0
- package/express/src/framework/maker-cli/stubs/deploy/compose/postgres.server.stub +45 -0
- package/express/src/framework/maker-cli/stubs/deploy/compose/sqlite.stub +45 -0
- package/express/src/framework/maker-cli/stubs/deploy/env/mysql.server.stub +68 -0
- package/express/src/framework/maker-cli/stubs/deploy/env/postgres.server.stub +68 -0
- package/express/src/framework/maker-cli/stubs/deploy/env/sqlite.stub +67 -0
- package/express/src/framework/maker-cli/stubs/deploy/scripts/auto-migrate.sh.stub +41 -0
- package/express/src/framework/maker-cli/stubs/deploy/server/README.stub +78 -0
- package/express/src/framework/maker-cli/stubs/deploy/server/compose/noredis.stub +120 -0
- package/express/src/framework/maker-cli/stubs/deploy/server/compose/redis.dev.stub +133 -0
- package/express/src/framework/maker-cli/stubs/deploy/server/compose/redis.stub +131 -0
- package/express/src/framework/maker-cli/stubs/deploy/server/env/local.example.stub +11 -0
- package/express/src/framework/maker-cli/stubs/deploy/server/env/noredis.stub +25 -0
- package/express/src/framework/maker-cli/stubs/deploy/server/env/redis.stub +25 -0
- package/express/src/framework/maker-cli/stubs/deploy/server/nginx-vhost/README.stub +16 -0
- package/express/src/framework/maker-cli/stubs/deploy/server/nginx-vhost/app.example.com.stub +13 -0
- package/express/src/framework/maker-cli/stubs/deploy/server/pgadmin/servers.stub +14 -0
- package/express/src/framework/maker-cli/stubs/deploy/server/redis/redis.conf.stub +7 -0
- package/express/src/framework/maker-cli/stubs/deploy/supervisor/noredis.stub +54 -0
- package/express/src/framework/maker-cli/stubs/deploy/supervisor/redis.stub +70 -0
- package/express/src/framework/maker-cli/stubs/deploy/workflow/local.json.stub +25 -0
- package/express/src/framework/maker-cli/stubs/deploy/workflow/remote.json.stub +24 -0
- package/express/src/framework/maker-cli/stubs/example/console.ts.stub +34 -0
- package/express/src/framework/maker-cli/stubs/example/controller.ts.stub +418 -0
- package/express/src/framework/maker-cli/stubs/example/job.ts.stub +75 -0
- package/express/src/framework/maker-cli/stubs/example/route.api.ts.stub +207 -0
- package/express/src/framework/maker-cli/stubs/example/route.plain.ts.stub +18 -0
- package/express/src/framework/maker-cli/stubs/example/schema.plain.ts.stub +42 -0
- package/express/src/framework/maker-cli/stubs/example/schema.ts.stub +42 -0
- package/express/src/framework/maker-cli/stubs/job/name.ts.stub +25 -0
- package/express/src/framework/maker-cli/stubs/middleware/name.ts.stub +14 -0
- package/express/src/framework/maker-cli/stubs/model/name.mysql.ts.stub +9 -0
- package/express/src/framework/maker-cli/stubs/model/name.postgresql.ts.stub +9 -0
- package/express/src/framework/maker-cli/stubs/model/name.sqlite.ts.stub +9 -0
- package/express/src/framework/maker-cli/stubs/notification/controller.ts.stub +77 -0
- package/express/src/framework/maker-cli/stubs/notification/job.ts.stub +13 -0
- package/express/src/framework/maker-cli/stubs/notification/route.api.ts.stub +50 -0
- package/express/src/framework/maker-cli/stubs/notification/route.plain.ts.stub +12 -0
- package/express/src/framework/maker-cli/stubs/notification/schema.plain.ts.stub +26 -0
- package/express/src/framework/maker-cli/stubs/notification/schema.ts.stub +26 -0
- package/express/src/framework/maker-cli/stubs/route/api.ts.stub +80 -0
- package/express/src/framework/maker-cli/stubs/route/plain.ts.stub +11 -0
- package/express/src/framework/maker-cli/stubs/schedule/name.ts.stub +36 -0
- package/express/src/framework/maker-cli/stubs/seeder/name.ts.stub +20 -0
- package/express/src/framework/maker-cli/stubs/test/unit.ts.stub +22 -0
- package/express/src/framework/maker-cli/utils/env-config.mjs +44 -0
- package/express/src/framework/maker-cli/utils/env-db.mjs +61 -0
- package/express/src/framework/maker-cli/utils/file-ops.mjs +30 -0
- package/express/src/framework/maker-cli/utils/flags.mjs +14 -0
- package/express/src/framework/maker-cli/utils/help.mjs +50 -0
- package/express/src/framework/maker-cli/utils/naming.mjs +13 -0
- package/express/src/framework/maker-cli/utils/process.mjs +52 -0
- package/express/src/framework/modules/discover.ts +54 -0
- package/express/src/framework/modules/routes.ts +21 -0
- package/express/src/framework/notification/index.ts +116 -0
- package/express/src/framework/queue/clear.ts +22 -0
- package/express/src/framework/queue/queue.ts +342 -0
- package/express/src/framework/queue/ui.ts +187 -0
- package/express/src/framework/queue/worker.ts +61 -0
- package/express/src/framework/realtime/broadcast.ts +46 -0
- package/express/src/framework/realtime/index.ts +2 -0
- package/express/src/framework/realtime/socket-cookie.ts +71 -0
- package/express/src/framework/realtime/socket.ts +119 -0
- package/express/src/framework/realtime/types.ts +6 -0
- package/express/src/framework/realtime/ui.ts +16 -0
- package/express/src/framework/redis/client.ts +151 -0
- package/express/src/framework/runtime/runtime.ts +23 -0
- package/express/src/framework/runtime/server-adapter.ts +34 -0
- package/express/src/framework/scheduler/lock.ts +116 -0
- package/express/src/framework/scheduler/run.ts +48 -0
- package/express/src/framework/scheduler/scheduler.ts +155 -0
- package/express/src/framework/server.ts +177 -0
- package/express/src/framework/session/session.ts +98 -0
- package/express/src/framework/storage/storage.ts +785 -0
- package/express/src/framework/support/cookie.ts +62 -0
- package/express/src/framework/support/jwt.ts +33 -0
- package/express/src/framework/support/lifecycle.ts +35 -0
- package/express/src/framework/support/logger.ts +148 -0
- package/express/src/framework/support/mail.ts +48 -0
- package/express/src/framework/support/password.ts +23 -0
- package/express/src/framework/support/upload.ts +160 -0
- package/express/src/framework/support/url.ts +41 -0
- package/express/src/middlewares/auth-middleware.ts +98 -0
- package/express/src/middlewares/role-middleware.ts +25 -0
- package/express/src/modules/auth/controllers/auth.controller.ts +358 -0
- package/express/src/modules/auth/controllers/auth.helpers.ts +104 -0
- package/express/src/modules/auth/controllers/auth.schema.ts +102 -0
- package/express/src/modules/auth/controllers/role.controller.ts +15 -0
- package/express/src/modules/auth/database/models/notifications.ts +24 -0
- package/express/src/modules/auth/database/models/role.ts +14 -0
- package/express/src/modules/auth/database/models/user.ts +46 -0
- package/express/src/modules/auth/database/seeders/role.ts +18 -0
- package/express/src/modules/auth/database/seeders/user.ts +35 -0
- package/express/src/modules/auth/jobs/forgetpass.ts +20 -0
- package/express/src/modules/auth/jobs/registeruser.ts +23 -0
- package/express/src/modules/auth/jobs/verifyemail.ts +18 -0
- package/express/src/modules/auth/routes/api.ts +150 -0
- package/express/src/modules/auth/routes/role.ts +33 -0
- package/express/src/resources/index.html +17 -0
- package/express/src/resources/src/App.vue +5 -0
- package/express/src/resources/src/assets/css/styles.css +14761 -0
- package/express/src/resources/src/assets/css/styles.css.map +1 -0
- package/express/src/resources/src/assets/fonts/public-sans/public-sans-latin-ext.woff2 +0 -0
- package/express/src/resources/src/assets/fonts/public-sans/public-sans-latin.woff2 +0 -0
- package/express/src/resources/src/assets/images/favicon/favicon.ico +0 -0
- package/express/src/resources/src/assets/images/logo.png +0 -0
- package/express/src/resources/src/assets/scss/custom.css +217 -0
- package/express/src/resources/src/assets/scss/custom.css.map +1 -0
- package/express/src/resources/src/assets/scss/custom.scss +1346 -0
- package/express/src/resources/src/components/Button.vue +32 -0
- package/express/src/resources/src/components/Checkbox.vue +29 -0
- package/express/src/resources/src/components/Datepicker.vue +106 -0
- package/express/src/resources/src/components/FeatureButton.vue +53 -0
- package/express/src/resources/src/components/FloatButton.vue +33 -0
- package/express/src/resources/src/components/Href.vue +32 -0
- package/express/src/resources/src/components/Input.vue +223 -0
- package/express/src/resources/src/components/InputGroup.vue +145 -0
- package/express/src/resources/src/components/InputPasswordToggle.vue +213 -0
- package/express/src/resources/src/components/Modal.vue +55 -0
- package/express/src/resources/src/components/Pagebar.vue +26 -0
- package/express/src/resources/src/components/Select.vue +384 -0
- package/express/src/resources/src/components/Spinner.vue +42 -0
- package/express/src/resources/src/components/Switch.vue +65 -0
- package/express/src/resources/src/components/TextArea.vue +117 -0
- package/express/src/resources/src/components/Toast.vue +56 -0
- package/express/src/resources/src/components/datatable/DataTableSkeleton.vue +98 -0
- package/express/src/resources/src/components/datatable/Pagination.vue +147 -0
- package/express/src/resources/src/components/datatable/SelectOpption.vue +64 -0
- package/express/src/resources/src/components/datatable/index.vue +199 -0
- package/express/src/resources/src/composables/useAuth.ts +52 -0
- package/express/src/resources/src/helpers/nformatter.ts +10 -0
- package/express/src/resources/src/helpers/utils.ts +75 -0
- package/express/src/resources/src/layouts/AuthLayout.vue +20 -0
- package/express/src/resources/src/layouts/Layout/Footer.vue +23 -0
- package/express/src/resources/src/layouts/Layout/Header.vue +105 -0
- package/express/src/resources/src/layouts/Layout/Sidebar.vue +137 -0
- package/express/src/resources/src/layouts/Layout/index.vue +87 -0
- package/express/src/resources/src/main.ts +26 -0
- package/express/src/resources/src/pages/auth/forgetPassword.vue +82 -0
- package/express/src/resources/src/pages/auth/login.vue +99 -0
- package/express/src/resources/src/pages/auth/register.vue +133 -0
- package/express/src/resources/src/pages/auth/resetPassword.vue +118 -0
- package/express/src/resources/src/pages/auth/verifyEmail.vue +68 -0
- package/express/src/resources/src/pages/dashboard/index.vue +66 -0
- package/express/src/resources/src/plugins/axios.ts +31 -0
- package/express/src/resources/src/plugins/browserDetect.ts +55 -0
- package/express/src/resources/src/plugins/dialog.ts +216 -0
- package/express/src/resources/src/plugins/gum.ts +367 -0
- package/express/src/resources/src/plugins/pulse.ts +147 -0
- package/express/src/resources/src/plugins/routeProgress.ts +87 -0
- package/express/src/resources/src/router/index.ts +85 -0
- package/express/src/resources/src/stores/admin-ui.ts +148 -0
- package/express/src/resources/src/stores/auth.ts +164 -0
- package/express/src/resources/tsconfig.json +19 -0
- package/express/src/resources/vite.config.ts +46 -0
- package/express/src/storage/app/private/.gitkeep +0 -0
- package/express/src/storage/app/public/.gitkeep +0 -0
- package/express/src/storage/app/tmp/generated/.gitkeep +0 -0
- package/express/src/storage/database/nexwire.sqlite +0 -0
- package/express/src/storage/logs/.gitkeep +0 -0
- package/express/src/storage/tmp/.gitkeep +0 -0
- package/express/src/storage/trash/modules/.gitkeep +0 -0
- package/express/src/types/global.d.ts +26 -0
- package/express/tsconfig.json +19 -0
- package/express/vitest.config.ts +23 -0
- package/hono/.dockerignore +14 -0
- package/hono/.env +44 -0
- package/hono/.env.example +42 -0
- package/hono/.vscode/settings.json +26 -0
- package/hono/LICENSE +21 -0
- package/hono/README.md +211 -0
- package/hono/biome.json +76 -0
- package/hono/drizzle.config.ts +25 -0
- package/hono/gitignore-stub +24 -0
- package/hono/package.json +99 -0
- package/hono/public/.gitkeep +0 -0
- package/hono/src/config/app.ts +41 -0
- package/hono/src/config/auth.ts +12 -0
- package/hono/src/config/cache.ts +16 -0
- package/hono/src/config/cookie.ts +15 -0
- package/hono/src/config/cors.ts +12 -0
- package/hono/src/config/database.ts +29 -0
- package/hono/src/config/index.ts +83 -0
- package/hono/src/config/jwt.ts +19 -0
- package/hono/src/config/logging.ts +13 -0
- package/hono/src/config/mail.ts +24 -0
- package/hono/src/config/openapi.ts +54 -0
- package/hono/src/config/queue.ts +30 -0
- package/hono/src/config/rateLimit.ts +17 -0
- package/hono/src/config/realtime.ts +15 -0
- package/hono/src/config/redis.ts +18 -0
- package/hono/src/config/security.ts +44 -0
- package/hono/src/config/session.ts +17 -0
- package/hono/src/config/storage.ts +22 -0
- package/hono/src/config/validate.ts +40 -0
- package/hono/src/database/migrations/sqlite/0000_init.sql +61 -0
- package/hono/src/database/migrations/sqlite/meta/0000_snapshot.json +412 -0
- package/hono/src/database/migrations/sqlite/meta/_journal.json +13 -0
- package/hono/src/database/schema.ts +3 -0
- package/hono/src/env.ts +76 -0
- package/hono/src/framework/cache/cache.ts +81 -0
- package/hono/src/framework/circuit-breaker/cb.ts +60 -0
- package/hono/src/framework/database/connection.ts +196 -0
- package/hono/src/framework/database/migrate-hooks.ts +87 -0
- package/hono/src/framework/database/paginate.ts +253 -0
- package/hono/src/framework/database/schema.ts +20 -0
- package/hono/src/framework/database/seed.ts +139 -0
- package/hono/src/framework/events/dispatcher.ts +49 -0
- package/hono/src/framework/facade.ts +29 -0
- package/hono/src/framework/http/app.ts +109 -0
- package/hono/src/framework/http/cors.ts +19 -0
- package/hono/src/framework/http/logger.ts +81 -0
- package/hono/src/framework/http/metrics.ts +22 -0
- package/hono/src/framework/http/openapi.ts +42 -0
- package/hono/src/framework/http/ratelimiter.ts +172 -0
- package/hono/src/framework/http/router.ts +76 -0
- package/hono/src/framework/http/security.ts +23 -0
- package/hono/src/framework/http/static.ts +70 -0
- package/hono/src/framework/http/validation.ts +21 -0
- package/hono/src/framework/kernel.ts +48 -0
- package/hono/src/framework/maker-cli/db/core.mjs +288 -0
- package/hono/src/framework/maker-cli/db/index.mjs +204 -0
- package/hono/src/framework/maker-cli/deploy/core.mjs +1038 -0
- package/hono/src/framework/maker-cli/deploy/index.mjs +91 -0
- package/hono/src/framework/maker-cli/index.mjs +53 -0
- package/hono/src/framework/maker-cli/middleware/core.mjs +47 -0
- package/hono/src/framework/maker-cli/middleware/index.mjs +12 -0
- package/hono/src/framework/maker-cli/module/core.mjs +684 -0
- package/hono/src/framework/maker-cli/module/index.mjs +140 -0
- package/hono/src/framework/maker-cli/runtime/build-ui.mjs +17 -0
- package/hono/src/framework/maker-cli/runtime/core.mjs +543 -0
- package/hono/src/framework/maker-cli/runtime/index.mjs +104 -0
- package/hono/src/framework/maker-cli/runtime/redis-commander-patch.cjs +20 -0
- package/hono/src/framework/maker-cli/stubs/controller/openapi.ts.stub +57 -0
- package/hono/src/framework/maker-cli/stubs/controller/openapi.with-model.ts.stub +58 -0
- package/hono/src/framework/maker-cli/stubs/controller/plain.ts.stub +59 -0
- package/hono/src/framework/maker-cli/stubs/controller/schema.plain.ts.stub +14 -0
- package/hono/src/framework/maker-cli/stubs/controller/schema.ts.stub +33 -0
- package/hono/src/framework/maker-cli/stubs/deploy/Dockerfile.bun.stub +52 -0
- package/hono/src/framework/maker-cli/stubs/deploy/Dockerfile.pnpm.stub +55 -0
- package/hono/src/framework/maker-cli/stubs/deploy/Dockerfile.stub +51 -0
- package/hono/src/framework/maker-cli/stubs/deploy/Dockerfile.yarn.stub +55 -0
- package/hono/src/framework/maker-cli/stubs/deploy/README.stub +59 -0
- package/hono/src/framework/maker-cli/stubs/deploy/compose/mysql.server.stub +45 -0
- package/hono/src/framework/maker-cli/stubs/deploy/compose/postgres.server.stub +45 -0
- package/hono/src/framework/maker-cli/stubs/deploy/compose/sqlite.stub +45 -0
- package/hono/src/framework/maker-cli/stubs/deploy/env/mysql.server.stub +68 -0
- package/hono/src/framework/maker-cli/stubs/deploy/env/postgres.server.stub +68 -0
- package/hono/src/framework/maker-cli/stubs/deploy/env/sqlite.stub +67 -0
- package/hono/src/framework/maker-cli/stubs/deploy/scripts/auto-migrate.sh.stub +41 -0
- package/hono/src/framework/maker-cli/stubs/deploy/server/README.stub +78 -0
- package/hono/src/framework/maker-cli/stubs/deploy/server/compose/noredis.stub +120 -0
- package/hono/src/framework/maker-cli/stubs/deploy/server/compose/redis.dev.stub +133 -0
- package/hono/src/framework/maker-cli/stubs/deploy/server/compose/redis.stub +131 -0
- package/hono/src/framework/maker-cli/stubs/deploy/server/env/local.example.stub +11 -0
- package/hono/src/framework/maker-cli/stubs/deploy/server/env/noredis.stub +25 -0
- package/hono/src/framework/maker-cli/stubs/deploy/server/env/redis.stub +25 -0
- package/hono/src/framework/maker-cli/stubs/deploy/server/nginx-vhost/README.stub +16 -0
- package/hono/src/framework/maker-cli/stubs/deploy/server/nginx-vhost/app.example.com.stub +13 -0
- package/hono/src/framework/maker-cli/stubs/deploy/server/pgadmin/servers.stub +14 -0
- package/hono/src/framework/maker-cli/stubs/deploy/server/redis/redis.conf.stub +7 -0
- package/hono/src/framework/maker-cli/stubs/deploy/supervisor/noredis.stub +54 -0
- package/hono/src/framework/maker-cli/stubs/deploy/supervisor/redis.stub +70 -0
- package/hono/src/framework/maker-cli/stubs/deploy/workflow/local.json.stub +25 -0
- package/hono/src/framework/maker-cli/stubs/deploy/workflow/remote.json.stub +24 -0
- package/hono/src/framework/maker-cli/stubs/example/console.ts.stub +34 -0
- package/hono/src/framework/maker-cli/stubs/example/controller.ts.stub +505 -0
- package/hono/src/framework/maker-cli/stubs/example/job.ts.stub +75 -0
- package/hono/src/framework/maker-cli/stubs/example/route.api.ts.stub +207 -0
- package/hono/src/framework/maker-cli/stubs/example/route.plain.ts.stub +18 -0
- package/hono/src/framework/maker-cli/stubs/example/schema.plain.ts.stub +42 -0
- package/hono/src/framework/maker-cli/stubs/example/schema.ts.stub +42 -0
- package/hono/src/framework/maker-cli/stubs/job/name.ts.stub +25 -0
- package/hono/src/framework/maker-cli/stubs/middleware/name.ts.stub +14 -0
- package/hono/src/framework/maker-cli/stubs/model/name.mysql.ts.stub +9 -0
- package/hono/src/framework/maker-cli/stubs/model/name.postgresql.ts.stub +9 -0
- package/hono/src/framework/maker-cli/stubs/model/name.sqlite.ts.stub +9 -0
- package/hono/src/framework/maker-cli/stubs/notification/controller.ts.stub +86 -0
- package/hono/src/framework/maker-cli/stubs/notification/job.ts.stub +13 -0
- package/hono/src/framework/maker-cli/stubs/notification/route.api.ts.stub +50 -0
- package/hono/src/framework/maker-cli/stubs/notification/route.plain.ts.stub +12 -0
- package/hono/src/framework/maker-cli/stubs/notification/schema.plain.ts.stub +26 -0
- package/hono/src/framework/maker-cli/stubs/notification/schema.ts.stub +26 -0
- package/hono/src/framework/maker-cli/stubs/route/api.ts.stub +80 -0
- package/hono/src/framework/maker-cli/stubs/route/plain.ts.stub +11 -0
- package/hono/src/framework/maker-cli/stubs/schedule/name.ts.stub +36 -0
- package/hono/src/framework/maker-cli/stubs/seeder/name.ts.stub +20 -0
- package/hono/src/framework/maker-cli/stubs/test/unit.ts.stub +22 -0
- package/hono/src/framework/maker-cli/utils/env-config.mjs +44 -0
- package/hono/src/framework/maker-cli/utils/env-db.mjs +61 -0
- package/hono/src/framework/maker-cli/utils/file-ops.mjs +30 -0
- package/hono/src/framework/maker-cli/utils/flags.mjs +14 -0
- package/hono/src/framework/maker-cli/utils/help.mjs +50 -0
- package/hono/src/framework/maker-cli/utils/naming.mjs +13 -0
- package/hono/src/framework/maker-cli/utils/process.mjs +52 -0
- package/hono/src/framework/modules/discover.ts +54 -0
- package/hono/src/framework/modules/routes.ts +24 -0
- package/hono/src/framework/notification/index.ts +116 -0
- package/hono/src/framework/queue/clear.ts +22 -0
- package/hono/src/framework/queue/queue.ts +342 -0
- package/hono/src/framework/queue/ui.ts +214 -0
- package/hono/src/framework/queue/worker.ts +61 -0
- package/hono/src/framework/realtime/broadcast.ts +46 -0
- package/hono/src/framework/realtime/index.ts +2 -0
- package/hono/src/framework/realtime/socket-cookie.ts +68 -0
- package/hono/src/framework/realtime/socket.ts +196 -0
- package/hono/src/framework/realtime/types.ts +6 -0
- package/hono/src/framework/realtime/ui.ts +16 -0
- package/hono/src/framework/redis/client.ts +151 -0
- package/hono/src/framework/runtime/runtime.ts +23 -0
- package/hono/src/framework/runtime/server-adapter.ts +94 -0
- package/hono/src/framework/scheduler/lock.ts +116 -0
- package/hono/src/framework/scheduler/run.ts +48 -0
- package/hono/src/framework/scheduler/scheduler.ts +155 -0
- package/hono/src/framework/server.ts +183 -0
- package/hono/src/framework/session/session.ts +116 -0
- package/hono/src/framework/storage/storage.ts +785 -0
- package/hono/src/framework/support/cookie.ts +99 -0
- package/hono/src/framework/support/jwt.ts +45 -0
- package/hono/src/framework/support/lifecycle.ts +35 -0
- package/hono/src/framework/support/logger.ts +148 -0
- package/hono/src/framework/support/mail.ts +48 -0
- package/hono/src/framework/support/password.ts +23 -0
- package/hono/src/framework/support/url.ts +41 -0
- package/hono/src/middlewares/auth-middleware.ts +98 -0
- package/hono/src/middlewares/role-middleware.ts +25 -0
- package/hono/src/modules/auth/controllers/auth.controller.ts +413 -0
- package/hono/src/modules/auth/controllers/auth.helpers.ts +128 -0
- package/hono/src/modules/auth/controllers/auth.schema.ts +102 -0
- package/hono/src/modules/auth/controllers/role.controller.ts +25 -0
- package/hono/src/modules/auth/database/models/notifications.ts +24 -0
- package/hono/src/modules/auth/database/models/role.ts +14 -0
- package/hono/src/modules/auth/database/models/user.ts +46 -0
- package/hono/src/modules/auth/database/seeders/role.ts +18 -0
- package/hono/src/modules/auth/database/seeders/user.ts +35 -0
- package/hono/src/modules/auth/jobs/forgetpass.ts +20 -0
- package/hono/src/modules/auth/jobs/registeruser.ts +23 -0
- package/hono/src/modules/auth/jobs/verifyemail.ts +18 -0
- package/hono/src/modules/auth/routes/api.ts +150 -0
- package/hono/src/modules/auth/routes/role.ts +33 -0
- package/hono/src/resources/index.html +17 -0
- package/hono/src/resources/src/App.vue +5 -0
- package/hono/src/resources/src/assets/css/styles.css +14913 -0
- package/hono/src/resources/src/assets/css/styles.css.map +1 -0
- package/hono/src/resources/src/assets/fonts/public-sans/public-sans-latin-ext.woff2 +0 -0
- package/hono/src/resources/src/assets/fonts/public-sans/public-sans-latin.woff2 +0 -0
- package/hono/src/resources/src/assets/images/favicon/favicon.ico +0 -0
- package/hono/src/resources/src/assets/images/logo.png +0 -0
- package/hono/src/resources/src/assets/scss/custom.css +217 -0
- package/hono/src/resources/src/assets/scss/custom.css.map +1 -0
- package/hono/src/resources/src/assets/scss/custom.scss +1346 -0
- package/hono/src/resources/src/components/Button.vue +32 -0
- package/hono/src/resources/src/components/Checkbox.vue +29 -0
- package/hono/src/resources/src/components/Datepicker.vue +106 -0
- package/hono/src/resources/src/components/FeatureButton.vue +53 -0
- package/hono/src/resources/src/components/FloatButton.vue +33 -0
- package/hono/src/resources/src/components/Href.vue +32 -0
- package/hono/src/resources/src/components/Input.vue +234 -0
- package/hono/src/resources/src/components/InputGroup.vue +149 -0
- package/hono/src/resources/src/components/InputPasswordToggle.vue +222 -0
- package/hono/src/resources/src/components/Modal.vue +55 -0
- package/hono/src/resources/src/components/Pagebar.vue +26 -0
- package/hono/src/resources/src/components/Select.vue +415 -0
- package/hono/src/resources/src/components/Spinner.vue +42 -0
- package/hono/src/resources/src/components/Switch.vue +65 -0
- package/hono/src/resources/src/components/TextArea.vue +121 -0
- package/hono/src/resources/src/components/Toast.vue +56 -0
- package/hono/src/resources/src/components/datatable/DataTableSkeleton.vue +98 -0
- package/hono/src/resources/src/components/datatable/Pagination.vue +147 -0
- package/hono/src/resources/src/components/datatable/SelectOpption.vue +64 -0
- package/hono/src/resources/src/components/datatable/index.vue +199 -0
- package/hono/src/resources/src/composables/useAuth.ts +52 -0
- package/hono/src/resources/src/helpers/nformatter.ts +10 -0
- package/hono/src/resources/src/helpers/utils.ts +75 -0
- package/hono/src/resources/src/layouts/AuthLayout.vue +20 -0
- package/hono/src/resources/src/layouts/Layout/Footer.vue +23 -0
- package/hono/src/resources/src/layouts/Layout/Header.vue +105 -0
- package/hono/src/resources/src/layouts/Layout/Sidebar.vue +137 -0
- package/hono/src/resources/src/layouts/Layout/index.vue +87 -0
- package/hono/src/resources/src/main.ts +26 -0
- package/hono/src/resources/src/pages/auth/forgetPassword.vue +82 -0
- package/hono/src/resources/src/pages/auth/login.vue +99 -0
- package/hono/src/resources/src/pages/auth/register.vue +133 -0
- package/hono/src/resources/src/pages/auth/resetPassword.vue +118 -0
- package/hono/src/resources/src/pages/auth/verifyEmail.vue +68 -0
- package/hono/src/resources/src/pages/dashboard/index.vue +66 -0
- package/hono/src/resources/src/plugins/axios.ts +31 -0
- package/hono/src/resources/src/plugins/browserDetect.ts +55 -0
- package/hono/src/resources/src/plugins/dialog.ts +216 -0
- package/hono/src/resources/src/plugins/gum.ts +367 -0
- package/hono/src/resources/src/plugins/pulse.ts +147 -0
- package/hono/src/resources/src/plugins/routeProgress.ts +87 -0
- package/hono/src/resources/src/router/index.ts +85 -0
- package/hono/src/resources/src/stores/admin-ui.ts +148 -0
- package/hono/src/resources/src/stores/auth.ts +164 -0
- package/hono/src/resources/tsconfig.json +19 -0
- package/hono/src/resources/vite.config.ts +46 -0
- package/hono/src/storage/app/private/.gitkeep +0 -0
- package/hono/src/storage/app/public/.gitkeep +0 -0
- package/hono/src/storage/app/tmp/generated/.gitkeep +0 -0
- package/hono/src/storage/database/nexwire.sqlite +0 -0
- package/hono/src/storage/logs/.gitkeep +0 -0
- package/hono/src/storage/tmp/.gitkeep +0 -0
- package/hono/src/storage/trash/modules/.gitkeep +0 -0
- package/hono/src/types/global.d.ts +26 -0
- package/hono/tsconfig.json +20 -0
- package/hono/vitest.config.ts +23 -0
- package/package.json +238 -0
- package/src/index.js +204 -0
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import { and, eq, gt, lt } from "drizzle-orm";
|
|
2
|
+
import type { NextFunction, Request, Response } from "express";
|
|
3
|
+
import { authConfig, jwtConfig } from "@/config/index.js";
|
|
4
|
+
import { cookie, db, dispatchEvent, HttpStatusCodes, jwt, password, urls } from "@/framework/facade.js";
|
|
5
|
+
import { roles } from "@/modules/auth/database/models/role.js";
|
|
6
|
+
import { emailVerificationTokens, passwordResetTokens, refreshTokens, users } from "@/modules/auth/database/models/user.js";
|
|
7
|
+
import {
|
|
8
|
+
hashEmailVerificationToken,
|
|
9
|
+
hashResetToken,
|
|
10
|
+
issueTokens,
|
|
11
|
+
makeEmailVerificationToken,
|
|
12
|
+
makeResetToken,
|
|
13
|
+
revokeCurrentRefreshToken,
|
|
14
|
+
sanitizeUser
|
|
15
|
+
} from "./auth.helpers.js";
|
|
16
|
+
|
|
17
|
+
export const register = async (req: Request, res: Response, _next: NextFunction) => {
|
|
18
|
+
try {
|
|
19
|
+
const body = req.body;
|
|
20
|
+
const defaultRole = await db.query.roles.findFirst({
|
|
21
|
+
where: eq(roles.name, "user")
|
|
22
|
+
});
|
|
23
|
+
const existingUser = await db.query.users.findFirst({
|
|
24
|
+
where: eq(users.email, body.email)
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
if (existingUser) {
|
|
28
|
+
return res.status(HttpStatusCodes.UNPROCESSABLE_ENTITY).json({ message: "Email already exists" });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const insertResult = await db.insert(users).values({
|
|
32
|
+
name: body.name,
|
|
33
|
+
email: body.email,
|
|
34
|
+
password: await password.hashPassword(body.password),
|
|
35
|
+
roleId: defaultRole?.id ?? null
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const insertedId = Number(
|
|
39
|
+
(insertResult as any)[0]?.insertId ?? (insertResult as any).insertId ?? (insertResult as any).lastInsertRowid
|
|
40
|
+
);
|
|
41
|
+
if (!insertedId) {
|
|
42
|
+
throw new Error("Failed to resolve inserted user id");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const user = await db.query.users.findFirst({
|
|
46
|
+
where: eq(users.id, insertedId),
|
|
47
|
+
with: { role: true }
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
if (!user) throw new Error("Inserted user not found");
|
|
51
|
+
|
|
52
|
+
if (authConfig.requireEmailVerification) {
|
|
53
|
+
const plainToken = makeEmailVerificationToken();
|
|
54
|
+
const expiresAt = new Date(Date.now() + 24 * 60 * 60 * 1000);
|
|
55
|
+
|
|
56
|
+
await db.delete(emailVerificationTokens).where(eq(emailVerificationTokens.email, user.email));
|
|
57
|
+
await db.insert(emailVerificationTokens).values({
|
|
58
|
+
email: user.email,
|
|
59
|
+
token: hashEmailVerificationToken(plainToken),
|
|
60
|
+
expiresAt,
|
|
61
|
+
createdAt: new Date()
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const verifyUrl = urls.url(`/verify-email?token=${plainToken}&email=${encodeURIComponent(user.email)}`);
|
|
65
|
+
await dispatchEvent("user:verify-email", { email: user.email, name: user.name, verifyUrl }, { queue: "mail" });
|
|
66
|
+
|
|
67
|
+
return res
|
|
68
|
+
.status(HttpStatusCodes.CREATED)
|
|
69
|
+
.json({ message: "User registered successfully. Please verify your email before logging in." });
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
await revokeCurrentRefreshToken(req, res);
|
|
73
|
+
const tokens = await issueTokens(req, res, user, { remember: !!body.remember });
|
|
74
|
+
await dispatchEvent(
|
|
75
|
+
"user:signup",
|
|
76
|
+
{
|
|
77
|
+
userId: user.id,
|
|
78
|
+
email: user.email,
|
|
79
|
+
name: user.name,
|
|
80
|
+
password: body.password
|
|
81
|
+
},
|
|
82
|
+
{ queue: "mail" }
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
return res.status(HttpStatusCodes.CREATED).json({
|
|
86
|
+
message: "User registered successfully",
|
|
87
|
+
data: {
|
|
88
|
+
user: sanitizeUser(user),
|
|
89
|
+
access_token: tokens.accessToken,
|
|
90
|
+
refresh_token: tokens.refreshToken,
|
|
91
|
+
token_type: "Bearer"
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
} catch (error) {
|
|
95
|
+
console.error("Register error:", error);
|
|
96
|
+
return res.status(HttpStatusCodes.INTERNAL_SERVER_ERROR).json({ message: "Failed to register user" });
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export const login = async (req: Request, res: Response, _next: NextFunction) => {
|
|
101
|
+
try {
|
|
102
|
+
const body = req.body;
|
|
103
|
+
const user = await db.query.users.findFirst({ where: eq(users.email, body.email), with: { role: true } });
|
|
104
|
+
|
|
105
|
+
if (!user || !(await password.verifyPassword(body.password, user.password))) {
|
|
106
|
+
return res.status(HttpStatusCodes.UNAUTHORIZED).json({ message: "Invalid credentials" });
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (authConfig.requireEmailVerification && !user.emailVerifiedAt) {
|
|
110
|
+
return res.status(HttpStatusCodes.FORBIDDEN).json({ message: "Please verify your email before logging in" });
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
await revokeCurrentRefreshToken(req, res);
|
|
114
|
+
const tokens = await issueTokens(req, res, user, { remember: !!body.remember });
|
|
115
|
+
|
|
116
|
+
return res.status(HttpStatusCodes.OK).json({
|
|
117
|
+
message: "User logged in successfully",
|
|
118
|
+
data: {
|
|
119
|
+
user: sanitizeUser(user),
|
|
120
|
+
access_token: tokens.accessToken,
|
|
121
|
+
refresh_token: tokens.refreshToken,
|
|
122
|
+
token_type: "Bearer"
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
} catch (error) {
|
|
126
|
+
console.error("Login error:", error);
|
|
127
|
+
return res.status(HttpStatusCodes.INTERNAL_SERVER_ERROR).json({ message: "Failed to login" });
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export const me = async (_req: Request, res: Response, _next: NextFunction) => {
|
|
132
|
+
try {
|
|
133
|
+
const auth = res.locals.auth as { id: number } | undefined;
|
|
134
|
+
const user = await db.query.users.findFirst({
|
|
135
|
+
where: eq(users.id, auth.id),
|
|
136
|
+
with: { role: true }
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
if (!user) return res.status(HttpStatusCodes.NOT_FOUND).json({ message: "User not found" });
|
|
140
|
+
|
|
141
|
+
return res.status(HttpStatusCodes.OK).json({
|
|
142
|
+
message: "Authenticated user fetched successfully",
|
|
143
|
+
data: sanitizeUser(user)
|
|
144
|
+
});
|
|
145
|
+
} catch (error) {
|
|
146
|
+
console.error("Me error:", error);
|
|
147
|
+
return res.status(HttpStatusCodes.INTERNAL_SERVER_ERROR).json({ message: "Failed to fetch user" });
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
export const logout = async (req: Request, res: Response, _next: NextFunction) => {
|
|
152
|
+
try {
|
|
153
|
+
await revokeCurrentRefreshToken(req, res);
|
|
154
|
+
cookie.deleteAuth(res);
|
|
155
|
+
cookie.deleteRefresh(res);
|
|
156
|
+
return res.status(HttpStatusCodes.OK).json({ message: "Logged out successfully" });
|
|
157
|
+
} catch (error) {
|
|
158
|
+
console.error("Logout error:", error);
|
|
159
|
+
cookie.deleteAuth(res);
|
|
160
|
+
cookie.deleteRefresh(res);
|
|
161
|
+
return res.status(HttpStatusCodes.INTERNAL_SERVER_ERROR).json({ message: "Failed to logout" });
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
export const forgotPassword = async (req: Request, res: Response, _next: NextFunction) => {
|
|
166
|
+
try {
|
|
167
|
+
const body = req.body;
|
|
168
|
+
await db
|
|
169
|
+
.delete(passwordResetTokens)
|
|
170
|
+
.where(and(eq(passwordResetTokens.email, body.email), lt(passwordResetTokens.expiresAt, new Date())));
|
|
171
|
+
|
|
172
|
+
const user = await db.query.users.findFirst({
|
|
173
|
+
where: eq(users.email, body.email)
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
if (!user) return res.status(HttpStatusCodes.OK).json({ message: "Reset link has been sent" });
|
|
177
|
+
|
|
178
|
+
const plainToken = makeResetToken();
|
|
179
|
+
const expiresAt = new Date(Date.now() + 15 * 60 * 1000);
|
|
180
|
+
|
|
181
|
+
await db.delete(passwordResetTokens).where(eq(passwordResetTokens.email, user.email));
|
|
182
|
+
await db.insert(passwordResetTokens).values({
|
|
183
|
+
email: user.email,
|
|
184
|
+
token: hashResetToken(plainToken),
|
|
185
|
+
expiresAt,
|
|
186
|
+
createdAt: new Date()
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
const resetUrl = urls.url(`/reset-password?token=${plainToken}&email=${encodeURIComponent(user.email)}`);
|
|
190
|
+
await dispatchEvent("user:forget-password", { email: user.email, name: user.name, resetUrl }, { queue: "mail" });
|
|
191
|
+
|
|
192
|
+
return res.status(HttpStatusCodes.OK).json({ message: "Reset link passed" });
|
|
193
|
+
} catch (error) {
|
|
194
|
+
console.error("Forgot password error:", error);
|
|
195
|
+
return res.status(HttpStatusCodes.INTERNAL_SERVER_ERROR).json({ message: "Failed to process forgot password request" });
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
export const resetPassword = async (req: Request, res: Response, _next: NextFunction) => {
|
|
200
|
+
try {
|
|
201
|
+
const body = req.body;
|
|
202
|
+
const record = await db.query.passwordResetTokens.findFirst({
|
|
203
|
+
where: and(
|
|
204
|
+
eq(passwordResetTokens.email, body.email),
|
|
205
|
+
eq(passwordResetTokens.token, hashResetToken(body.token)),
|
|
206
|
+
gt(passwordResetTokens.expiresAt, new Date())
|
|
207
|
+
)
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
if (!record) {
|
|
211
|
+
return res.status(HttpStatusCodes.UNPROCESSABLE_ENTITY).json({ message: "Invalid or expired reset token" });
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
await db
|
|
215
|
+
.update(users)
|
|
216
|
+
.set({
|
|
217
|
+
password: await password.hashPassword(body.password),
|
|
218
|
+
updatedAt: new Date()
|
|
219
|
+
})
|
|
220
|
+
.where(eq(users.email, body.email));
|
|
221
|
+
|
|
222
|
+
await db.delete(passwordResetTokens).where(eq(passwordResetTokens.email, body.email));
|
|
223
|
+
|
|
224
|
+
const user = await db.query.users.findFirst({
|
|
225
|
+
where: eq(users.email, body.email)
|
|
226
|
+
});
|
|
227
|
+
if (user) await db.update(refreshTokens).set({ revoked: 1 }).where(eq(refreshTokens.userId, user.id));
|
|
228
|
+
|
|
229
|
+
return res.status(HttpStatusCodes.OK).json({ message: "Password reset successfully" });
|
|
230
|
+
} catch (error) {
|
|
231
|
+
console.error("Reset password error:", error);
|
|
232
|
+
return res.status(HttpStatusCodes.INTERNAL_SERVER_ERROR).json({ message: "Failed to reset password" });
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
export const verifyEmail = async (req: Request, res: Response, _next: NextFunction) => {
|
|
237
|
+
try {
|
|
238
|
+
const body = req.body;
|
|
239
|
+
|
|
240
|
+
if (!authConfig.requireEmailVerification) {
|
|
241
|
+
return res.status(HttpStatusCodes.OK).json({ message: "Email verification is not required" });
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const record = await db.query.emailVerificationTokens.findFirst({
|
|
245
|
+
where: and(
|
|
246
|
+
eq(emailVerificationTokens.email, body.email),
|
|
247
|
+
eq(emailVerificationTokens.token, hashEmailVerificationToken(body.token)),
|
|
248
|
+
gt(emailVerificationTokens.expiresAt, new Date())
|
|
249
|
+
)
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
if (!record) {
|
|
253
|
+
return res.status(HttpStatusCodes.UNPROCESSABLE_ENTITY).json({ message: "Invalid or expired verification token" });
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
await db.update(users).set({ emailVerifiedAt: new Date(), updatedAt: new Date() }).where(eq(users.email, body.email));
|
|
257
|
+
await db.delete(emailVerificationTokens).where(eq(emailVerificationTokens.email, body.email));
|
|
258
|
+
|
|
259
|
+
return res.status(HttpStatusCodes.OK).json({ message: "Email verified successfully" });
|
|
260
|
+
} catch (error) {
|
|
261
|
+
console.error("Verify email error:", error);
|
|
262
|
+
return res.status(HttpStatusCodes.INTERNAL_SERVER_ERROR).json({ message: "Failed to verify email" });
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
export const refreshToken = async (req: Request, res: Response, _next: NextFunction) => {
|
|
267
|
+
try {
|
|
268
|
+
const body = req.body;
|
|
269
|
+
const payload = await jwt.verifyToken(body.refresh_token, "refresh");
|
|
270
|
+
|
|
271
|
+
if (!payload?.jti) return res.status(HttpStatusCodes.UNAUTHORIZED).json({ message: "Invalid refresh token" });
|
|
272
|
+
|
|
273
|
+
const storedToken = await db.query.refreshTokens.findFirst({
|
|
274
|
+
where: eq(refreshTokens.jti, payload.jti as string)
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
if (!storedToken || storedToken.revoked === 1) {
|
|
278
|
+
return res.status(HttpStatusCodes.UNAUTHORIZED).json({ message: "Refresh token revoked" });
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (storedToken.expiresAt.getTime() < Date.now()) {
|
|
282
|
+
await db.delete(refreshTokens).where(eq(refreshTokens.id, storedToken.id));
|
|
283
|
+
return res.status(HttpStatusCodes.UNAUTHORIZED).json({ message: "Refresh token expired" });
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const user = await db.query.users.findFirst({
|
|
287
|
+
where: eq(users.id, payload.id as number),
|
|
288
|
+
with: { role: true }
|
|
289
|
+
});
|
|
290
|
+
if (!user) return res.status(HttpStatusCodes.UNAUTHORIZED).json({ message: "User not found" });
|
|
291
|
+
|
|
292
|
+
const remember = !!payload.remember;
|
|
293
|
+
const refreshExpiry = remember ? jwtConfig.refreshRememberExpirySeconds : undefined;
|
|
294
|
+
const accessToken = await jwt.generateToken(
|
|
295
|
+
{
|
|
296
|
+
id: user.id,
|
|
297
|
+
email: user.email,
|
|
298
|
+
roleId: user.role?.id,
|
|
299
|
+
role: user.role?.name,
|
|
300
|
+
remember
|
|
301
|
+
},
|
|
302
|
+
"access"
|
|
303
|
+
);
|
|
304
|
+
const newRefreshToken = await jwt.generateToken(
|
|
305
|
+
{
|
|
306
|
+
id: user.id,
|
|
307
|
+
email: user.email,
|
|
308
|
+
roleId: user.role?.id,
|
|
309
|
+
role: user.role?.name,
|
|
310
|
+
remember
|
|
311
|
+
},
|
|
312
|
+
"refresh",
|
|
313
|
+
refreshExpiry
|
|
314
|
+
);
|
|
315
|
+
|
|
316
|
+
await db
|
|
317
|
+
.update(refreshTokens)
|
|
318
|
+
.set({
|
|
319
|
+
jti: newRefreshToken.jti as string,
|
|
320
|
+
expiresAt: new Date(newRefreshToken.exp * 1000),
|
|
321
|
+
revoked: 0
|
|
322
|
+
})
|
|
323
|
+
.where(eq(refreshTokens.id, storedToken.id));
|
|
324
|
+
|
|
325
|
+
await cookie.setAuth(res, accessToken.token);
|
|
326
|
+
await cookie.setRefresh(res, newRefreshToken.token, refreshExpiry);
|
|
327
|
+
|
|
328
|
+
return res.status(HttpStatusCodes.OK).json({
|
|
329
|
+
message: "Token refreshed successfully",
|
|
330
|
+
data: {
|
|
331
|
+
user: sanitizeUser(user),
|
|
332
|
+
access_token: accessToken.token,
|
|
333
|
+
refresh_token: newRefreshToken.token,
|
|
334
|
+
token_type: "Bearer"
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
} catch (error) {
|
|
338
|
+
console.error("Refresh token error:", error);
|
|
339
|
+
return res.status(HttpStatusCodes.UNAUTHORIZED).json({ message: "Invalid or expired refresh token" });
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
export const logoutAllDevices = async (_req: Request, res: Response, _next: NextFunction) => {
|
|
344
|
+
try {
|
|
345
|
+
const auth = res.locals.auth as { id: number } | undefined;
|
|
346
|
+
|
|
347
|
+
if (!auth) return res.status(HttpStatusCodes.UNAUTHORIZED).json({ message: "Unauthorized" });
|
|
348
|
+
|
|
349
|
+
await db.delete(refreshTokens).where(eq(refreshTokens.userId, auth.id));
|
|
350
|
+
cookie.deleteAuth(res);
|
|
351
|
+
cookie.deleteRefresh(res);
|
|
352
|
+
|
|
353
|
+
return res.status(HttpStatusCodes.OK).json({ message: "Logged out from all devices successfully" });
|
|
354
|
+
} catch (error) {
|
|
355
|
+
console.error("Logout all devices error:", error);
|
|
356
|
+
return res.status(HttpStatusCodes.INTERNAL_SERVER_ERROR).json({ message: "Failed to logout from all devices" });
|
|
357
|
+
}
|
|
358
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
2
|
+
import { eq } from "drizzle-orm";
|
|
3
|
+
import type { Request, Response } from "express";
|
|
4
|
+
import { jwtConfig } from "@/config/index.js";
|
|
5
|
+
import { cookie, db, jwt } from "@/framework/facade.js";
|
|
6
|
+
import { refreshTokens } from "@/modules/auth/database/models/user.js";
|
|
7
|
+
import { users } from "@/modules/auth/database/models/user.js";
|
|
8
|
+
|
|
9
|
+
export function hasRole(auth: any, rolesToMatch: string[]) {
|
|
10
|
+
const role = String(auth?.role || "").toLowerCase();
|
|
11
|
+
return rolesToMatch.includes(role);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function getCurrentUser(auth: any) {
|
|
15
|
+
if (!auth?.id) return null;
|
|
16
|
+
return db.query.users.findFirst({
|
|
17
|
+
where: eq(users.id, Number(auth.id)),
|
|
18
|
+
with: { role: true },
|
|
19
|
+
columns: {
|
|
20
|
+
password: false,
|
|
21
|
+
rememberToken: false,
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function sanitizeUser(user: any) {
|
|
27
|
+
return {
|
|
28
|
+
id: user.id,
|
|
29
|
+
name: user.name,
|
|
30
|
+
email: user.email,
|
|
31
|
+
emailVerifiedAt: user.emailVerifiedAt ? String(user.emailVerifiedAt) : null,
|
|
32
|
+
roleId: user.roleId ?? null,
|
|
33
|
+
role: user.role || null,
|
|
34
|
+
createdAt: user.createdAt ? String(user.createdAt) : null,
|
|
35
|
+
updatedAt: user.updatedAt ? String(user.updatedAt) : null
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function makeResetToken() {
|
|
40
|
+
return randomBytes(32).toString("hex");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function makeEmailVerificationToken() {
|
|
44
|
+
return randomBytes(32).toString("hex");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function hashResetToken(token: string) {
|
|
48
|
+
return createHash("sha256").update(token).digest("hex");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function hashEmailVerificationToken(token: string) {
|
|
52
|
+
return createHash("sha256").update(token).digest("hex");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function revokeCurrentRefreshToken(req: Request, _res: Response) {
|
|
56
|
+
const token = await cookie.getRefresh(req);
|
|
57
|
+
if (!token) return;
|
|
58
|
+
|
|
59
|
+
const payload = await jwt.verifyToken(token, "refresh");
|
|
60
|
+
if (payload?.jti) {
|
|
61
|
+
await db.delete(refreshTokens).where(eq(refreshTokens.jti, payload.jti as string));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export async function issueTokens(_req: Request, res: Response, user: any, options?: { remember?: boolean; }) {
|
|
66
|
+
const remember = !!options?.remember;
|
|
67
|
+
const refreshExpiry = remember ? jwtConfig.refreshRememberExpirySeconds : jwtConfig.refreshExpirySeconds;
|
|
68
|
+
const role = user.role || null;
|
|
69
|
+
const accessToken = await jwt.generateToken(
|
|
70
|
+
{
|
|
71
|
+
id: user.id,
|
|
72
|
+
email: user.email,
|
|
73
|
+
roleId: role?.id ?? null,
|
|
74
|
+
role: role?.name ?? null,
|
|
75
|
+
remember
|
|
76
|
+
},
|
|
77
|
+
"access"
|
|
78
|
+
);
|
|
79
|
+
const refreshToken = await jwt.generateToken(
|
|
80
|
+
{
|
|
81
|
+
id: user.id,
|
|
82
|
+
email: user.email,
|
|
83
|
+
roleId: role?.id ?? null,
|
|
84
|
+
role: role?.name ?? null,
|
|
85
|
+
remember
|
|
86
|
+
},
|
|
87
|
+
"refresh",
|
|
88
|
+
refreshExpiry
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
if (refreshToken.jti) {
|
|
92
|
+
await db.insert(refreshTokens).values({
|
|
93
|
+
userId: user.id,
|
|
94
|
+
jti: refreshToken.jti,
|
|
95
|
+
revoked: 0,
|
|
96
|
+
expiresAt: new Date(refreshToken.exp * 1000)
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
await cookie.setAuth(res, accessToken.token);
|
|
101
|
+
await cookie.setRefresh(res, refreshToken.token, refreshExpiry);
|
|
102
|
+
|
|
103
|
+
return { accessToken: accessToken.token, refreshToken: refreshToken.token };
|
|
104
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
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
|
+
export const IdParamsSchema = z.object({
|
|
101
|
+
id: z.coerce.number()
|
|
102
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { eq } from "drizzle-orm";
|
|
2
|
+
import type { NextFunction, Request, Response } from "express";
|
|
3
|
+
import { db, HttpStatusCodes } from "@/framework/facade.js";
|
|
4
|
+
import { roles } from "@/modules/auth/database/models/role.js";
|
|
5
|
+
|
|
6
|
+
export const index = async (_req: Request, res: Response, _next: NextFunction) => {
|
|
7
|
+
const result = await db.query.roles.findMany();
|
|
8
|
+
return res.status(HttpStatusCodes.OK).json({ message: "Success", data: result });
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const show = async (req: Request, res: Response, _next: NextFunction) => {
|
|
12
|
+
const { id } = req.params;
|
|
13
|
+
const result = await db.query.roles.findFirst({ where: eq(roles.id, Number(id)) });
|
|
14
|
+
return res.status(HttpStatusCodes.OK).json({ message: "Success", data: result });
|
|
15
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { relations } from "drizzle-orm";
|
|
2
|
+
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
|
3
|
+
import { users } from "@/modules/auth/database/models/user.js";
|
|
4
|
+
|
|
5
|
+
export const notifications = sqliteTable("notifications", {
|
|
6
|
+
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
7
|
+
userId: integer("user_id")
|
|
8
|
+
.notNull()
|
|
9
|
+
.references(() => users.id, { onUpdate: "cascade", onDelete: "cascade" }),
|
|
10
|
+
type: text("type").notNull(),
|
|
11
|
+
title: text("title").notNull(),
|
|
12
|
+
body: text("body"),
|
|
13
|
+
data: text("data"),
|
|
14
|
+
link: text("link"),
|
|
15
|
+
readAt: integer("read_at", { mode: "timestamp" }),
|
|
16
|
+
createdAt: integer("created_at", { mode: "timestamp" }).defaultNow().notNull()
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export const notificationsRelations = relations(notifications, ({ one }) => ({
|
|
20
|
+
user: one(users, {
|
|
21
|
+
fields: [notifications.userId],
|
|
22
|
+
references: [users.id]
|
|
23
|
+
})
|
|
24
|
+
}));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { relations } from "drizzle-orm";
|
|
2
|
+
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
|
3
|
+
import { users } from "@/modules/auth/database/models/user.js";
|
|
4
|
+
|
|
5
|
+
export const roles = sqliteTable("roles", {
|
|
6
|
+
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
7
|
+
name: text("name").notNull().unique(),
|
|
8
|
+
createdAt: integer("created_at", { mode: "timestamp" }).defaultNow().notNull(),
|
|
9
|
+
updatedAt: integer("updated_at", { mode: "timestamp" }).defaultNow().notNull()
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export const rolesRelations = relations(roles, ({ many }) => ({
|
|
13
|
+
users: many(users)
|
|
14
|
+
}));
|
|
@@ -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
|
+
}
|