@imksh/create 1.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 +88 -0
- package/bin/index.js +3 -0
- package/package.json +43 -0
- package/src/commands/create.js +90 -0
- package/src/index.js +41 -0
- package/src/utils/askTemplate.js +25 -0
- package/src/utils/copyTemplate.js +36 -0
- package/src/utils/installPackages.js +25 -0
- package/src/utils/logger.js +17 -0
- package/src/utils/runGit.js +11 -0
- package/templates/mern/_gitignore +2 -0
- package/templates/mern/client/_gitignore +24 -0
- package/templates/mern/client/index.html +14 -0
- package/templates/mern/client/package.json +39 -0
- package/templates/mern/client/public/_redirects +1 -0
- package/templates/mern/client/public/favicon.ico +0 -0
- package/templates/mern/client/public/favicon.svg +1 -0
- package/templates/mern/client/public/logo.png +0 -0
- package/templates/mern/client/public/manifest.json +24 -0
- package/templates/mern/client/public/sw.js +56 -0
- package/templates/mern/client/src/App.jsx +68 -0
- package/templates/mern/client/src/assets/animations/loading.json +1 -0
- package/templates/mern/client/src/assets/data/navigation.js +29 -0
- package/templates/mern/client/src/assets/images/logo.png +0 -0
- package/templates/mern/client/src/components/common/Breadcrumbs.jsx +27 -0
- package/templates/mern/client/src/components/common/Loading.jsx +19 -0
- package/templates/mern/client/src/components/common/LottieIcon.jsx +36 -0
- package/templates/mern/client/src/components/common/NotFound.jsx +78 -0
- package/templates/mern/client/src/components/common/PwaInstallPrompt.jsx +72 -0
- package/templates/mern/client/src/components/common/SEO.jsx +67 -0
- package/templates/mern/client/src/components/common/Scroll.jsx +25 -0
- package/templates/mern/client/src/components/common/Table.jsx +110 -0
- package/templates/mern/client/src/components/common/ToggleSwitch.jsx +38 -0
- package/templates/mern/client/src/components/common/Unauthorized.jsx +76 -0
- package/templates/mern/client/src/components/layout/ProtectedRoute.jsx +17 -0
- package/templates/mern/client/src/components/layout/PublicLayout.jsx +13 -0
- package/templates/mern/client/src/components/layout/SidebarLayout.jsx +37 -0
- package/templates/mern/client/src/components/modals/ConfirmModal.jsx +135 -0
- package/templates/mern/client/src/components/modals/Modal.jsx +94 -0
- package/templates/mern/client/src/components/skeletons/common/CardSkeleton.jsx +23 -0
- package/templates/mern/client/src/components/skeletons/common/DashboardSkeleton.jsx +19 -0
- package/templates/mern/client/src/components/skeletons/common/ListSkeleton.jsx +24 -0
- package/templates/mern/client/src/components/skeletons/common/PageSkeleton.jsx +26 -0
- package/templates/mern/client/src/components/skeletons/common/ProfileSkeleton.jsx +23 -0
- package/templates/mern/client/src/components/skeletons/common/Skeleton.jsx +18 -0
- package/templates/mern/client/src/components/skeletons/common/TableSkeleton.jsx +33 -0
- package/templates/mern/client/src/components/ui/Header.jsx +230 -0
- package/templates/mern/client/src/components/ui/SidebarHeader.jsx +27 -0
- package/templates/mern/client/src/components/ui/sidebar.jsx +152 -0
- package/templates/mern/client/src/config/api.js +22 -0
- package/templates/mern/client/src/config/appConfig.js +44 -0
- package/templates/mern/client/src/config/navigation.js +14 -0
- package/templates/mern/client/src/hooks/useLenis.js +28 -0
- package/templates/mern/client/src/hooks/usePwaInstall.js +45 -0
- package/templates/mern/client/src/hooks/useWindowSize.js +25 -0
- package/templates/mern/client/src/index.css +158 -0
- package/templates/mern/client/src/main.jsx +24 -0
- package/templates/mern/client/src/pages/Home.jsx +154 -0
- package/templates/mern/client/src/pages/Login.jsx +196 -0
- package/templates/mern/client/src/pages/Profile.jsx +9 -0
- package/templates/mern/client/src/services/authService.js +16 -0
- package/templates/mern/client/src/store/useAuthStore.js +98 -0
- package/templates/mern/client/src/store/useUiStore.js +54 -0
- package/templates/mern/client/src/utils/getInitials.js +10 -0
- package/templates/mern/client/vite.config.js +8 -0
- package/templates/mern/package.json +18 -0
- package/templates/mern/server/.env.example +62 -0
- package/templates/mern/server/README.md +65 -0
- package/templates/mern/server/_gitignore +24 -0
- package/templates/mern/server/package.json +32 -0
- package/templates/mern/server/src/app.js +42 -0
- package/templates/mern/server/src/config/cloudinary.js +9 -0
- package/templates/mern/server/src/config/db.js +14 -0
- package/templates/mern/server/src/config/dotenv.js +2 -0
- package/templates/mern/server/src/config/email.js +30 -0
- package/templates/mern/server/src/config/socket.js +54 -0
- package/templates/mern/server/src/config/webPush.js +9 -0
- package/templates/mern/server/src/controllers/auth.controller.js +153 -0
- package/templates/mern/server/src/controllers/upload.controller.js +26 -0
- package/templates/mern/server/src/index.js +24 -0
- package/templates/mern/server/src/middleware/auth.middleware.js +43 -0
- package/templates/mern/server/src/middleware/errorHandler.js +22 -0
- package/templates/mern/server/src/middleware/multer.js +21 -0
- package/templates/mern/server/src/middleware/rateLimiter.js +57 -0
- package/templates/mern/server/src/models/otp.model.js +21 -0
- package/templates/mern/server/src/models/pushSubscription.model.js +32 -0
- package/templates/mern/server/src/models/user.model.js +43 -0
- package/templates/mern/server/src/routes/auth.route.js +22 -0
- package/templates/mern/server/src/routes/index.js +10 -0
- package/templates/mern/server/src/routes/upload.route.js +12 -0
- package/templates/mern/server/src/services/auth.service.js +162 -0
- package/templates/mern/server/src/services/auth.service.ts +0 -0
- package/templates/mern/server/src/utils/authToken.js +26 -0
- package/templates/mern/server/src/utils/cloudinary.js +27 -0
- package/templates/mern/server/src/utils/cloudinaryUpload.js +87 -0
- package/templates/mern/server/src/utils/emailOtp.js +190 -0
- package/templates/mern/server/src/utils/genOtpToken.js +20 -0
- package/templates/mern/server/src/utils/generateVapidKeys.js +12 -0
- package/templates/mern/server/src/utils/jwt.js +25 -0
- package/templates/mern/server/src/utils/logger.js +25 -0
- package/templates/mern-ts/_gitignore +2 -0
- package/templates/mern-ts/client/_gitignore +24 -0
- package/templates/mern-ts/client/index.html +14 -0
- package/templates/mern-ts/client/package.json +45 -0
- package/templates/mern-ts/client/public/_redirects +1 -0
- package/templates/mern-ts/client/public/favicon.ico +0 -0
- package/templates/mern-ts/client/public/favicon.svg +1 -0
- package/templates/mern-ts/client/public/logo.png +0 -0
- package/templates/mern-ts/client/public/manifest.json +24 -0
- package/templates/mern-ts/client/public/sw.js +56 -0
- package/templates/mern-ts/client/src/App.tsx +68 -0
- package/templates/mern-ts/client/src/assets/animations/loading.json +1 -0
- package/templates/mern-ts/client/src/assets/data/navigation.ts +29 -0
- package/templates/mern-ts/client/src/assets/images/logo.png +0 -0
- package/templates/mern-ts/client/src/components/common/Breadcrumbs.tsx +27 -0
- package/templates/mern-ts/client/src/components/common/Loading.tsx +19 -0
- package/templates/mern-ts/client/src/components/common/LottieIcon.tsx +36 -0
- package/templates/mern-ts/client/src/components/common/NotFound.tsx +78 -0
- package/templates/mern-ts/client/src/components/common/PwaInstallPrompt.tsx +72 -0
- package/templates/mern-ts/client/src/components/common/SEO.tsx +67 -0
- package/templates/mern-ts/client/src/components/common/Scroll.tsx +25 -0
- package/templates/mern-ts/client/src/components/common/Table.tsx +118 -0
- package/templates/mern-ts/client/src/components/common/ToggleSwitch.tsx +38 -0
- package/templates/mern-ts/client/src/components/common/Unauthorized.tsx +76 -0
- package/templates/mern-ts/client/src/components/layout/ProtectedRoute.tsx +23 -0
- package/templates/mern-ts/client/src/components/layout/PublicLayout.tsx +13 -0
- package/templates/mern-ts/client/src/components/layout/SidebarLayout.tsx +37 -0
- package/templates/mern-ts/client/src/components/modals/ConfirmModal.tsx +135 -0
- package/templates/mern-ts/client/src/components/modals/Modal.tsx +94 -0
- package/templates/mern-ts/client/src/components/skeletons/common/CardSkeleton.tsx +23 -0
- package/templates/mern-ts/client/src/components/skeletons/common/DashboardSkeleton.tsx +19 -0
- package/templates/mern-ts/client/src/components/skeletons/common/ListSkeleton.tsx +24 -0
- package/templates/mern-ts/client/src/components/skeletons/common/PageSkeleton.tsx +26 -0
- package/templates/mern-ts/client/src/components/skeletons/common/ProfileSkeleton.tsx +23 -0
- package/templates/mern-ts/client/src/components/skeletons/common/Skeleton.tsx +18 -0
- package/templates/mern-ts/client/src/components/skeletons/common/TableSkeleton.tsx +33 -0
- package/templates/mern-ts/client/src/components/ui/Header.tsx +230 -0
- package/templates/mern-ts/client/src/components/ui/SidebarHeader.tsx +27 -0
- package/templates/mern-ts/client/src/components/ui/sidebar.tsx +152 -0
- package/templates/mern-ts/client/src/config/api.ts +22 -0
- package/templates/mern-ts/client/src/config/appConfig.ts +44 -0
- package/templates/mern-ts/client/src/config/navigation.ts +14 -0
- package/templates/mern-ts/client/src/hooks/useLenis.ts +28 -0
- package/templates/mern-ts/client/src/hooks/usePwaInstall.ts +45 -0
- package/templates/mern-ts/client/src/hooks/useWindowSize.ts +25 -0
- package/templates/mern-ts/client/src/index.css +158 -0
- package/templates/mern-ts/client/src/main.tsx +24 -0
- package/templates/mern-ts/client/src/pages/Home.tsx +154 -0
- package/templates/mern-ts/client/src/pages/Login.tsx +196 -0
- package/templates/mern-ts/client/src/pages/Profile.tsx +9 -0
- package/templates/mern-ts/client/src/services/authService.ts +16 -0
- package/templates/mern-ts/client/src/store/useAuthStore.ts +98 -0
- package/templates/mern-ts/client/src/store/useUiStore.ts +54 -0
- package/templates/mern-ts/client/src/utils/getInitials.ts +10 -0
- package/templates/mern-ts/client/tsconfig.json +25 -0
- package/templates/mern-ts/client/tsconfig.node.json +10 -0
- package/templates/mern-ts/client/vite.config.ts +8 -0
- package/templates/mern-ts/package.json +19 -0
- package/templates/mern-ts/server/.env.example +62 -0
- package/templates/mern-ts/server/README.md +69 -0
- package/templates/mern-ts/server/_gitignore +24 -0
- package/templates/mern-ts/server/package.json +47 -0
- package/templates/mern-ts/server/src/app.ts +36 -0
- package/templates/mern-ts/server/src/config/cloudinary.ts +9 -0
- package/templates/mern-ts/server/src/config/db.ts +15 -0
- package/templates/mern-ts/server/src/config/dotenv.ts +2 -0
- package/templates/mern-ts/server/src/config/email.ts +28 -0
- package/templates/mern-ts/server/src/config/socket.ts +54 -0
- package/templates/mern-ts/server/src/config/webPush.ts +9 -0
- package/templates/mern-ts/server/src/controllers/auth.controller.ts +126 -0
- package/templates/mern-ts/server/src/controllers/upload.controller.ts +22 -0
- package/templates/mern-ts/server/src/index.ts +17 -0
- package/templates/mern-ts/server/src/middleware/auth.middleware.ts +38 -0
- package/templates/mern-ts/server/src/middleware/errorHandler.ts +16 -0
- package/templates/mern-ts/server/src/middleware/multer.ts +20 -0
- package/templates/mern-ts/server/src/middleware/rateLimiter.ts +53 -0
- package/templates/mern-ts/server/src/models/otp.model.ts +21 -0
- package/templates/mern-ts/server/src/models/pushSubscription.model.ts +32 -0
- package/templates/mern-ts/server/src/models/user.model.ts +43 -0
- package/templates/mern-ts/server/src/routes/auth.route.ts +22 -0
- package/templates/mern-ts/server/src/routes/index.ts +10 -0
- package/templates/mern-ts/server/src/routes/upload.route.ts +11 -0
- package/templates/mern-ts/server/src/services/auth.service.ts +115 -0
- package/templates/mern-ts/server/src/types/express.d.ts +10 -0
- package/templates/mern-ts/server/src/utils/cloudinaryUpload.ts +44 -0
- package/templates/mern-ts/server/src/utils/emailOtp.ts +30 -0
- package/templates/mern-ts/server/src/utils/genOtpToken.ts +22 -0
- package/templates/mern-ts/server/src/utils/generateVapidKeys.ts +12 -0
- package/templates/mern-ts/server/src/utils/jwt.ts +27 -0
- package/templates/mern-ts/server/src/utils/logger.ts +27 -0
- package/templates/mern-ts/server/tsconfig.json +14 -0
- package/templates/next/_gitignore +24 -0
- package/templates/next/package.json +20 -0
- package/templates/next/src/app/layout.js +7 -0
- package/templates/next/src/app/page.js +218 -0
- package/templates/next-ts/_gitignore +24 -0
- package/templates/next-ts/package.json +24 -0
- package/templates/next-ts/src/app/layout.tsx +9 -0
- package/templates/next-ts/src/app/page.tsx +218 -0
- package/templates/next-ts/tsconfig.json +27 -0
- package/templates/node/.env.example +62 -0
- package/templates/node/README.md +65 -0
- package/templates/node/_gitignore +24 -0
- package/templates/node/package.json +32 -0
- package/templates/node/src/app.js +42 -0
- package/templates/node/src/config/cloudinary.js +9 -0
- package/templates/node/src/config/db.js +14 -0
- package/templates/node/src/config/dotenv.js +2 -0
- package/templates/node/src/config/email.js +30 -0
- package/templates/node/src/config/socket.js +54 -0
- package/templates/node/src/config/webPush.js +9 -0
- package/templates/node/src/controllers/auth.controller.js +153 -0
- package/templates/node/src/controllers/upload.controller.js +26 -0
- package/templates/node/src/index.js +24 -0
- package/templates/node/src/middleware/auth.middleware.js +43 -0
- package/templates/node/src/middleware/errorHandler.js +22 -0
- package/templates/node/src/middleware/multer.js +21 -0
- package/templates/node/src/middleware/rateLimiter.js +57 -0
- package/templates/node/src/models/otp.model.js +21 -0
- package/templates/node/src/models/pushSubscription.model.js +32 -0
- package/templates/node/src/models/user.model.js +43 -0
- package/templates/node/src/routes/auth.route.js +22 -0
- package/templates/node/src/routes/index.js +10 -0
- package/templates/node/src/routes/upload.route.js +12 -0
- package/templates/node/src/services/auth.service.js +162 -0
- package/templates/node/src/services/auth.service.ts +0 -0
- package/templates/node/src/utils/authToken.js +26 -0
- package/templates/node/src/utils/cloudinary.js +27 -0
- package/templates/node/src/utils/cloudinaryUpload.js +87 -0
- package/templates/node/src/utils/emailOtp.js +190 -0
- package/templates/node/src/utils/genOtpToken.js +20 -0
- package/templates/node/src/utils/generateVapidKeys.js +12 -0
- package/templates/node/src/utils/jwt.js +25 -0
- package/templates/node/src/utils/logger.js +25 -0
- package/templates/node-prisma/.env.example +63 -0
- package/templates/node-prisma/README.md +69 -0
- package/templates/node-prisma/_gitignore +24 -0
- package/templates/node-prisma/package.json +35 -0
- package/templates/node-prisma/prisma/schema.prisma +41 -0
- package/templates/node-prisma/src/app.js +42 -0
- package/templates/node-prisma/src/config/cloudinary.js +9 -0
- package/templates/node-prisma/src/config/db.js +16 -0
- package/templates/node-prisma/src/config/dotenv.js +2 -0
- package/templates/node-prisma/src/config/email.js +30 -0
- package/templates/node-prisma/src/config/socket.js +54 -0
- package/templates/node-prisma/src/config/webPush.js +9 -0
- package/templates/node-prisma/src/controllers/auth.controller.js +146 -0
- package/templates/node-prisma/src/controllers/upload.controller.js +26 -0
- package/templates/node-prisma/src/index.js +24 -0
- package/templates/node-prisma/src/middleware/auth.middleware.js +44 -0
- package/templates/node-prisma/src/middleware/errorHandler.js +22 -0
- package/templates/node-prisma/src/middleware/multer.js +21 -0
- package/templates/node-prisma/src/middleware/rateLimiter.js +57 -0
- package/templates/node-prisma/src/routes/auth.route.js +22 -0
- package/templates/node-prisma/src/routes/index.js +10 -0
- package/templates/node-prisma/src/routes/upload.route.js +12 -0
- package/templates/node-prisma/src/services/auth.service.js +163 -0
- package/templates/node-prisma/src/services/auth.service.ts +0 -0
- package/templates/node-prisma/src/utils/authToken.js +26 -0
- package/templates/node-prisma/src/utils/cloudinary.js +27 -0
- package/templates/node-prisma/src/utils/cloudinaryUpload.js +87 -0
- package/templates/node-prisma/src/utils/emailOtp.js +190 -0
- package/templates/node-prisma/src/utils/genOtpToken.js +20 -0
- package/templates/node-prisma/src/utils/generateVapidKeys.js +12 -0
- package/templates/node-prisma/src/utils/jwt.js +25 -0
- package/templates/node-prisma/src/utils/logger.js +25 -0
- package/templates/node-prisma-ts/.env.example +63 -0
- package/templates/node-prisma-ts/README.md +73 -0
- package/templates/node-prisma-ts/_gitignore +24 -0
- package/templates/node-prisma-ts/package.json +48 -0
- package/templates/node-prisma-ts/prisma/schema.prisma +41 -0
- package/templates/node-prisma-ts/src/app.ts +36 -0
- package/templates/node-prisma-ts/src/config/cloudinary.ts +9 -0
- package/templates/node-prisma-ts/src/config/db.ts +16 -0
- package/templates/node-prisma-ts/src/config/dotenv.ts +2 -0
- package/templates/node-prisma-ts/src/config/email.ts +28 -0
- package/templates/node-prisma-ts/src/config/socket.ts +54 -0
- package/templates/node-prisma-ts/src/config/webPush.ts +9 -0
- package/templates/node-prisma-ts/src/controllers/auth.controller.ts +124 -0
- package/templates/node-prisma-ts/src/controllers/upload.controller.ts +22 -0
- package/templates/node-prisma-ts/src/index.ts +17 -0
- package/templates/node-prisma-ts/src/middleware/auth.middleware.ts +45 -0
- package/templates/node-prisma-ts/src/middleware/errorHandler.ts +16 -0
- package/templates/node-prisma-ts/src/middleware/multer.ts +20 -0
- package/templates/node-prisma-ts/src/middleware/rateLimiter.ts +53 -0
- package/templates/node-prisma-ts/src/routes/auth.route.ts +22 -0
- package/templates/node-prisma-ts/src/routes/index.ts +10 -0
- package/templates/node-prisma-ts/src/routes/upload.route.ts +11 -0
- package/templates/node-prisma-ts/src/services/auth.service.ts +163 -0
- package/templates/node-prisma-ts/src/types/express.d.ts +10 -0
- package/templates/node-prisma-ts/src/utils/cloudinaryUpload.ts +44 -0
- package/templates/node-prisma-ts/src/utils/emailOtp.ts +30 -0
- package/templates/node-prisma-ts/src/utils/genOtpToken.ts +22 -0
- package/templates/node-prisma-ts/src/utils/generateVapidKeys.ts +12 -0
- package/templates/node-prisma-ts/src/utils/jwt.ts +27 -0
- package/templates/node-prisma-ts/src/utils/logger.ts +27 -0
- package/templates/node-prisma-ts/tsconfig.json +14 -0
- package/templates/node-ts/.env.example +62 -0
- package/templates/node-ts/README.md +69 -0
- package/templates/node-ts/_gitignore +24 -0
- package/templates/node-ts/package.json +47 -0
- package/templates/node-ts/src/app.ts +36 -0
- package/templates/node-ts/src/config/cloudinary.ts +9 -0
- package/templates/node-ts/src/config/db.ts +15 -0
- package/templates/node-ts/src/config/dotenv.ts +2 -0
- package/templates/node-ts/src/config/email.ts +28 -0
- package/templates/node-ts/src/config/socket.ts +54 -0
- package/templates/node-ts/src/config/webPush.ts +9 -0
- package/templates/node-ts/src/controllers/auth.controller.ts +126 -0
- package/templates/node-ts/src/controllers/upload.controller.ts +22 -0
- package/templates/node-ts/src/index.ts +17 -0
- package/templates/node-ts/src/middleware/auth.middleware.ts +38 -0
- package/templates/node-ts/src/middleware/errorHandler.ts +16 -0
- package/templates/node-ts/src/middleware/multer.ts +20 -0
- package/templates/node-ts/src/middleware/rateLimiter.ts +53 -0
- package/templates/node-ts/src/models/otp.model.ts +21 -0
- package/templates/node-ts/src/models/pushSubscription.model.ts +32 -0
- package/templates/node-ts/src/models/user.model.ts +43 -0
- package/templates/node-ts/src/routes/auth.route.ts +22 -0
- package/templates/node-ts/src/routes/index.ts +10 -0
- package/templates/node-ts/src/routes/upload.route.ts +11 -0
- package/templates/node-ts/src/services/auth.service.ts +115 -0
- package/templates/node-ts/src/types/express.d.ts +10 -0
- package/templates/node-ts/src/utils/cloudinaryUpload.ts +44 -0
- package/templates/node-ts/src/utils/emailOtp.ts +30 -0
- package/templates/node-ts/src/utils/genOtpToken.ts +22 -0
- package/templates/node-ts/src/utils/generateVapidKeys.ts +12 -0
- package/templates/node-ts/src/utils/jwt.ts +27 -0
- package/templates/node-ts/src/utils/logger.ts +27 -0
- package/templates/node-ts/tsconfig.json +18 -0
- package/templates/react/.env.example +1 -0
- package/templates/react/_gitignore +24 -0
- package/templates/react/index.html +14 -0
- package/templates/react/package.json +39 -0
- package/templates/react/public/_redirects +1 -0
- package/templates/react/public/favicon.ico +0 -0
- package/templates/react/public/favicon.svg +1 -0
- package/templates/react/public/logo.png +0 -0
- package/templates/react/public/manifest.json +24 -0
- package/templates/react/public/sw.js +56 -0
- package/templates/react/src/App.jsx +68 -0
- package/templates/react/src/assets/animations/loading.json +1 -0
- package/templates/react/src/assets/data/navigation.js +29 -0
- package/templates/react/src/assets/images/logo.png +0 -0
- package/templates/react/src/components/common/Breadcrumbs.jsx +27 -0
- package/templates/react/src/components/common/Loading.jsx +19 -0
- package/templates/react/src/components/common/LottieIcon.jsx +36 -0
- package/templates/react/src/components/common/NotFound.jsx +78 -0
- package/templates/react/src/components/common/PwaInstallPrompt.jsx +72 -0
- package/templates/react/src/components/common/SEO.jsx +67 -0
- package/templates/react/src/components/common/Scroll.jsx +25 -0
- package/templates/react/src/components/common/Table.jsx +110 -0
- package/templates/react/src/components/common/ToggleSwitch.jsx +38 -0
- package/templates/react/src/components/common/Unauthorized.jsx +76 -0
- package/templates/react/src/components/layout/ProtectedRoute.jsx +17 -0
- package/templates/react/src/components/layout/PublicLayout.jsx +13 -0
- package/templates/react/src/components/layout/SidebarLayout.jsx +37 -0
- package/templates/react/src/components/modals/ConfirmModal.jsx +135 -0
- package/templates/react/src/components/modals/Modal.jsx +94 -0
- package/templates/react/src/components/skeletons/common/CardSkeleton.jsx +23 -0
- package/templates/react/src/components/skeletons/common/DashboardSkeleton.jsx +19 -0
- package/templates/react/src/components/skeletons/common/ListSkeleton.jsx +24 -0
- package/templates/react/src/components/skeletons/common/PageSkeleton.jsx +26 -0
- package/templates/react/src/components/skeletons/common/ProfileSkeleton.jsx +23 -0
- package/templates/react/src/components/skeletons/common/Skeleton.jsx +18 -0
- package/templates/react/src/components/skeletons/common/TableSkeleton.jsx +33 -0
- package/templates/react/src/components/ui/Header.jsx +230 -0
- package/templates/react/src/components/ui/SidebarHeader.jsx +27 -0
- package/templates/react/src/components/ui/sidebar.jsx +152 -0
- package/templates/react/src/config/api.js +22 -0
- package/templates/react/src/config/appConfig.js +44 -0
- package/templates/react/src/config/navigation.js +14 -0
- package/templates/react/src/hooks/useLenis.js +28 -0
- package/templates/react/src/hooks/usePwaInstall.js +45 -0
- package/templates/react/src/hooks/useWindowSize.js +25 -0
- package/templates/react/src/index.css +158 -0
- package/templates/react/src/main.jsx +24 -0
- package/templates/react/src/pages/Home.jsx +154 -0
- package/templates/react/src/pages/Login.jsx +196 -0
- package/templates/react/src/pages/Profile.jsx +9 -0
- package/templates/react/src/services/authService.js +16 -0
- package/templates/react/src/store/useAuthStore.js +98 -0
- package/templates/react/src/store/useUiStore.js +54 -0
- package/templates/react/src/utils/getInitials.js +10 -0
- package/templates/react/vite.config.js +8 -0
- package/templates/react-ts/_gitignore +24 -0
- package/templates/react-ts/index.html +14 -0
- package/templates/react-ts/package.json +45 -0
- package/templates/react-ts/public/_redirects +1 -0
- package/templates/react-ts/public/favicon.ico +0 -0
- package/templates/react-ts/public/favicon.svg +1 -0
- package/templates/react-ts/public/logo.png +0 -0
- package/templates/react-ts/public/manifest.json +24 -0
- package/templates/react-ts/public/sw.js +56 -0
- package/templates/react-ts/src/App.tsx +68 -0
- package/templates/react-ts/src/assets/animations/loading.json +1 -0
- package/templates/react-ts/src/assets/data/navigation.ts +29 -0
- package/templates/react-ts/src/assets/images/logo.png +0 -0
- package/templates/react-ts/src/components/common/Breadcrumbs.tsx +27 -0
- package/templates/react-ts/src/components/common/Loading.tsx +19 -0
- package/templates/react-ts/src/components/common/LottieIcon.tsx +36 -0
- package/templates/react-ts/src/components/common/NotFound.tsx +78 -0
- package/templates/react-ts/src/components/common/PwaInstallPrompt.tsx +72 -0
- package/templates/react-ts/src/components/common/SEO.tsx +67 -0
- package/templates/react-ts/src/components/common/Scroll.tsx +25 -0
- package/templates/react-ts/src/components/common/Table.tsx +118 -0
- package/templates/react-ts/src/components/common/ToggleSwitch.tsx +38 -0
- package/templates/react-ts/src/components/common/Unauthorized.tsx +76 -0
- package/templates/react-ts/src/components/layout/ProtectedRoute.tsx +23 -0
- package/templates/react-ts/src/components/layout/PublicLayout.tsx +13 -0
- package/templates/react-ts/src/components/layout/SidebarLayout.tsx +37 -0
- package/templates/react-ts/src/components/modals/ConfirmModal.tsx +135 -0
- package/templates/react-ts/src/components/modals/Modal.tsx +94 -0
- package/templates/react-ts/src/components/skeletons/common/CardSkeleton.tsx +23 -0
- package/templates/react-ts/src/components/skeletons/common/DashboardSkeleton.tsx +19 -0
- package/templates/react-ts/src/components/skeletons/common/ListSkeleton.tsx +24 -0
- package/templates/react-ts/src/components/skeletons/common/PageSkeleton.tsx +26 -0
- package/templates/react-ts/src/components/skeletons/common/ProfileSkeleton.tsx +23 -0
- package/templates/react-ts/src/components/skeletons/common/Skeleton.tsx +18 -0
- package/templates/react-ts/src/components/skeletons/common/TableSkeleton.tsx +33 -0
- package/templates/react-ts/src/components/ui/Header.tsx +230 -0
- package/templates/react-ts/src/components/ui/SidebarHeader.tsx +27 -0
- package/templates/react-ts/src/components/ui/sidebar.tsx +152 -0
- package/templates/react-ts/src/config/api.ts +22 -0
- package/templates/react-ts/src/config/appConfig.ts +44 -0
- package/templates/react-ts/src/config/navigation.ts +14 -0
- package/templates/react-ts/src/hooks/useLenis.ts +28 -0
- package/templates/react-ts/src/hooks/usePwaInstall.ts +45 -0
- package/templates/react-ts/src/hooks/useWindowSize.ts +25 -0
- package/templates/react-ts/src/index.css +158 -0
- package/templates/react-ts/src/main.tsx +24 -0
- package/templates/react-ts/src/pages/Home.tsx +154 -0
- package/templates/react-ts/src/pages/Login.tsx +196 -0
- package/templates/react-ts/src/pages/Profile.tsx +9 -0
- package/templates/react-ts/src/services/authService.ts +16 -0
- package/templates/react-ts/src/store/useAuthStore.ts +98 -0
- package/templates/react-ts/src/store/useUiStore.ts +54 -0
- package/templates/react-ts/src/utils/getInitials.ts +10 -0
- package/templates/react-ts/tsconfig.json +25 -0
- package/templates/react-ts/tsconfig.node.json +10 -0
- package/templates/react-ts/vite.config.ts +8 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import express from "express";
|
|
2
|
+
import { upload } from "../middleware/multer.js";
|
|
3
|
+
import { uploadFile } from "../controllers/upload.controller.js";
|
|
4
|
+
import { protect } from "../middleware/auth.middleware.js";
|
|
5
|
+
import { uploadLimiter } from "../middleware/rateLimiter.js";
|
|
6
|
+
|
|
7
|
+
const router = express.Router();
|
|
8
|
+
|
|
9
|
+
// Mount file upload route (protected by auth and rate-limited)
|
|
10
|
+
router.post("/", protect, uploadLimiter, upload.single("file"), uploadFile);
|
|
11
|
+
|
|
12
|
+
export default router;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import User from "../models/user.model.js";
|
|
2
|
+
import Otp from "../models/otp.model.js";
|
|
3
|
+
import bcrypt from "bcrypt";
|
|
4
|
+
import { generateToken } from "../utils/jwt.js";
|
|
5
|
+
import { sendOtpEmail } from "../utils/emailOtp.js";
|
|
6
|
+
import { uploadSingleToCloudinary, deleteFromCloudinary } from "../utils/cloudinaryUpload.js";
|
|
7
|
+
import logger from "../utils/logger.js";
|
|
8
|
+
|
|
9
|
+
export const authService = {
|
|
10
|
+
/**
|
|
11
|
+
* User Signup
|
|
12
|
+
*/
|
|
13
|
+
signup: async ({ name, email, phone, password }) => {
|
|
14
|
+
const existingUser = await User.findOne({ email });
|
|
15
|
+
if (existingUser) {
|
|
16
|
+
const err = new Error("User already exists");
|
|
17
|
+
err.status = 409;
|
|
18
|
+
throw err;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const salt = await bcrypt.genSalt(10);
|
|
22
|
+
const hashedPassword = await bcrypt.hash(password, salt);
|
|
23
|
+
|
|
24
|
+
const photoURL = `https://placehold.co/600x400?text=${name.charAt(0).toUpperCase()}`;
|
|
25
|
+
|
|
26
|
+
const newUser = await User.create({
|
|
27
|
+
name,
|
|
28
|
+
email: email.toLowerCase(),
|
|
29
|
+
phone,
|
|
30
|
+
role: "user",
|
|
31
|
+
password: hashedPassword,
|
|
32
|
+
avatar: {
|
|
33
|
+
url: photoURL,
|
|
34
|
+
publicId: "",
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return newUser;
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* User Login
|
|
43
|
+
*/
|
|
44
|
+
login: async ({ email, password }) => {
|
|
45
|
+
const user = await User.findOne({ email });
|
|
46
|
+
if (!user) {
|
|
47
|
+
const err = new Error("User not found");
|
|
48
|
+
err.status = 404;
|
|
49
|
+
throw err;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const isValid = await bcrypt.compare(password, user.password);
|
|
53
|
+
if (!isValid) {
|
|
54
|
+
const err = new Error("Invalid Credentials");
|
|
55
|
+
err.status = 401;
|
|
56
|
+
throw err;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return user;
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Generate and Send OTP
|
|
64
|
+
*/
|
|
65
|
+
generateOtp: async (email) => {
|
|
66
|
+
const user = await User.findOne({ email });
|
|
67
|
+
if (!user) {
|
|
68
|
+
const err = new Error("User not found");
|
|
69
|
+
err.status = 404;
|
|
70
|
+
throw err;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const existingOtp = await Otp.findOne({ email });
|
|
74
|
+
if (existingOtp) {
|
|
75
|
+
await existingOtp.deleteOne();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const otp = Math.floor(100000 + Math.random() * 900000).toString();
|
|
79
|
+
const hashedOtp = await bcrypt.hash(otp, 10);
|
|
80
|
+
|
|
81
|
+
await Otp.create({
|
|
82
|
+
email,
|
|
83
|
+
otp: hashedOtp,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
await sendOtpEmail(email, otp);
|
|
87
|
+
return true;
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Verify OTP
|
|
92
|
+
*/
|
|
93
|
+
verifyOtp: async ({ email, otp }) => {
|
|
94
|
+
const user = await User.findOne({ email });
|
|
95
|
+
if (!user) {
|
|
96
|
+
const err = new Error("User not found");
|
|
97
|
+
err.status = 404;
|
|
98
|
+
throw err;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const existingOtp = await Otp.findOne({ email });
|
|
102
|
+
if (!existingOtp) {
|
|
103
|
+
const err = new Error("OTP match failed");
|
|
104
|
+
err.status = 400;
|
|
105
|
+
throw err;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const isMatched = await bcrypt.compare(otp, existingOtp.otp);
|
|
109
|
+
if (!isMatched) {
|
|
110
|
+
const err = new Error("OTP match failed");
|
|
111
|
+
err.status = 400;
|
|
112
|
+
throw err;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return user;
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Reset Password
|
|
120
|
+
*/
|
|
121
|
+
resetPassword: async (user, newPassword) => {
|
|
122
|
+
const hashedPassword = await bcrypt.hash(newPassword, 10);
|
|
123
|
+
user.password = hashedPassword;
|
|
124
|
+
await user.save();
|
|
125
|
+
return true;
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Update Profile
|
|
130
|
+
*/
|
|
131
|
+
updateProfile: async (userId, { name, phone, file }) => {
|
|
132
|
+
const user = await User.findById(userId);
|
|
133
|
+
if (!user) {
|
|
134
|
+
const err = new Error("User not found");
|
|
135
|
+
err.status = 404;
|
|
136
|
+
throw err;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (name) user.name = name;
|
|
140
|
+
if (phone) user.phone = phone;
|
|
141
|
+
|
|
142
|
+
if (file) {
|
|
143
|
+
const uploadResult = await uploadSingleToCloudinary(file, {
|
|
144
|
+
folder: "codelab/avatars",
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
if (user.avatar && user.avatar.publicId) {
|
|
148
|
+
await deleteFromCloudinary(user.avatar.publicId).catch((err) =>
|
|
149
|
+
logger.error("Old avatar delete error", err)
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
user.avatar = {
|
|
154
|
+
url: uploadResult.url,
|
|
155
|
+
publicId: uploadResult.publicId,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
await user.save();
|
|
160
|
+
return user;
|
|
161
|
+
},
|
|
162
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import jwt from "jsonwebtoken";
|
|
2
|
+
|
|
3
|
+
export const genToken = async (user, res) => {
|
|
4
|
+
try {
|
|
5
|
+
const payload = {
|
|
6
|
+
id: user._id,
|
|
7
|
+
role: user.role || "admin",
|
|
8
|
+
};
|
|
9
|
+
const token = await jwt.sign(payload, process.env.JWT_SECRET, {
|
|
10
|
+
expiresIn: "1d",
|
|
11
|
+
});
|
|
12
|
+
//expires in day=1d,in hour=1h,in seconds=1
|
|
13
|
+
|
|
14
|
+
console.log(token);
|
|
15
|
+
res.cookie("token", token, {
|
|
16
|
+
maxAge: 1000 * 60 * 60 * 24,
|
|
17
|
+
httpOnly: process.env.NODE_ENV !== "production" ? false : true,
|
|
18
|
+
secure: process.env.NODE_ENV !== "production" ? false : true,
|
|
19
|
+
sameSite: process.env.NODE_ENV !== "production" ? "lax" : "none",
|
|
20
|
+
});
|
|
21
|
+
return token;
|
|
22
|
+
} catch (error) {
|
|
23
|
+
console.log(error);
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { v2 as cloudinary } from "cloudinary";
|
|
2
|
+
import { CloudinaryStorage } from "multer-storage-cloudinary";
|
|
3
|
+
import multer from "multer";
|
|
4
|
+
|
|
5
|
+
cloudinary.config({
|
|
6
|
+
cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
|
|
7
|
+
api_key: process.env.CLOUDINARY_API_KEY,
|
|
8
|
+
api_secret: process.env.CLOUDINARY_API_SECRET,
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
// Storage engine for profile images / file submissions
|
|
12
|
+
const storage = new CloudinaryStorage({
|
|
13
|
+
cloudinary,
|
|
14
|
+
params: (req, file) => ({
|
|
15
|
+
folder: "lms-uploads",
|
|
16
|
+
allowed_formats: ["jpg", "jpeg", "png", "gif", "pdf", "webp"],
|
|
17
|
+
resource_type: file.mimetype.startsWith("image/") ? "image" : "raw",
|
|
18
|
+
public_id: `${Date.now()}-${file.originalname.replace(/\s+/g, "_")}`,
|
|
19
|
+
}),
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export const upload = multer({
|
|
23
|
+
storage,
|
|
24
|
+
limits: { fileSize: 10 * 1024 * 1024 }, // 10 MB cap
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export { cloudinary };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import cloudinary from "../config/cloudinary.js";
|
|
2
|
+
import logger from "./logger.js";
|
|
3
|
+
|
|
4
|
+
const uploadToCloudinary = async (
|
|
5
|
+
file,
|
|
6
|
+
{
|
|
7
|
+
folder = "uploads",
|
|
8
|
+
width,
|
|
9
|
+
height,
|
|
10
|
+
crop,
|
|
11
|
+
quality = "auto",
|
|
12
|
+
format = "auto",
|
|
13
|
+
...options
|
|
14
|
+
} = {},
|
|
15
|
+
) => {
|
|
16
|
+
if (!file?.buffer) {
|
|
17
|
+
throw new Error("Invalid file.");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const dataURI = `data:${file.mimetype};base64,${file.buffer.toString(
|
|
21
|
+
"base64",
|
|
22
|
+
)}`;
|
|
23
|
+
|
|
24
|
+
const result = await cloudinary.uploader.upload(dataURI, {
|
|
25
|
+
folder,
|
|
26
|
+
width,
|
|
27
|
+
height,
|
|
28
|
+
crop,
|
|
29
|
+
quality,
|
|
30
|
+
format,
|
|
31
|
+
...options,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
url: result.secure_url,
|
|
36
|
+
publicId: result.public_id,
|
|
37
|
+
assetId: result.asset_id,
|
|
38
|
+
width: result.width,
|
|
39
|
+
height: result.height,
|
|
40
|
+
format: result.format,
|
|
41
|
+
bytes: result.bytes,
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Upload Single Image
|
|
47
|
+
*/
|
|
48
|
+
export const uploadSingleToCloudinary = async (
|
|
49
|
+
file,
|
|
50
|
+
options = {},
|
|
51
|
+
) => {
|
|
52
|
+
try {
|
|
53
|
+
return await uploadToCloudinary(file, options);
|
|
54
|
+
} catch (error) {
|
|
55
|
+
logger.error("Cloudinary Upload Error", error);
|
|
56
|
+
throw new Error("Failed to upload image.");
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Upload Multiple Images
|
|
62
|
+
*/
|
|
63
|
+
export const uploadMultipleToCloudinary = async (
|
|
64
|
+
files = [],
|
|
65
|
+
options = {},
|
|
66
|
+
) => {
|
|
67
|
+
try {
|
|
68
|
+
return await Promise.all(
|
|
69
|
+
files.map((file) => uploadToCloudinary(file, options)),
|
|
70
|
+
);
|
|
71
|
+
} catch (error) {
|
|
72
|
+
logger.error("Cloudinary Upload Error", error);
|
|
73
|
+
throw new Error("Failed to upload images.");
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Delete Image
|
|
79
|
+
*/
|
|
80
|
+
export const deleteFromCloudinary = async (publicId) => {
|
|
81
|
+
try {
|
|
82
|
+
return await cloudinary.uploader.destroy(publicId);
|
|
83
|
+
} catch (error) {
|
|
84
|
+
logger.error("Cloudinary Delete Error", error);
|
|
85
|
+
throw new Error("Failed to delete image.");
|
|
86
|
+
}
|
|
87
|
+
};
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import sendEmail from "../config/email.js";
|
|
2
|
+
|
|
3
|
+
const APP_NAME = process.env.APP_NAME || "My App";
|
|
4
|
+
const APP_URL = process.env.APP_URL || "";
|
|
5
|
+
const APP_PRIMARY_COLOR =
|
|
6
|
+
process.env.APP_PRIMARY_COLOR || "#2563eb";
|
|
7
|
+
|
|
8
|
+
export const emailOtp = (otp, expiry = 10) => ({
|
|
9
|
+
subject: `${APP_NAME} - Verification Code`,
|
|
10
|
+
html: `
|
|
11
|
+
<!DOCTYPE html>
|
|
12
|
+
<html lang="en">
|
|
13
|
+
|
|
14
|
+
<head>
|
|
15
|
+
<meta charset="UTF-8" />
|
|
16
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
17
|
+
<title>${APP_NAME}</title>
|
|
18
|
+
</head>
|
|
19
|
+
|
|
20
|
+
<body style="margin:0;padding:40px;background:#f3f4f6;font-family:Arial,Helvetica,sans-serif;">
|
|
21
|
+
|
|
22
|
+
<table width="100%" cellpadding="0" cellspacing="0">
|
|
23
|
+
<tr>
|
|
24
|
+
<td align="center">
|
|
25
|
+
|
|
26
|
+
<table
|
|
27
|
+
width="600"
|
|
28
|
+
cellpadding="0"
|
|
29
|
+
cellspacing="0"
|
|
30
|
+
style="
|
|
31
|
+
background:#ffffff;
|
|
32
|
+
border-radius:16px;
|
|
33
|
+
overflow:hidden;
|
|
34
|
+
box-shadow:0 10px 30px rgba(0,0,0,.08);
|
|
35
|
+
"
|
|
36
|
+
>
|
|
37
|
+
|
|
38
|
+
<!-- Header -->
|
|
39
|
+
<tr>
|
|
40
|
+
<td
|
|
41
|
+
align="center"
|
|
42
|
+
style="
|
|
43
|
+
background:${APP_PRIMARY_COLOR};
|
|
44
|
+
padding:30px;
|
|
45
|
+
"
|
|
46
|
+
>
|
|
47
|
+
<h1
|
|
48
|
+
style="
|
|
49
|
+
margin:0;
|
|
50
|
+
color:#ffffff;
|
|
51
|
+
font-size:26px;
|
|
52
|
+
font-weight:700;
|
|
53
|
+
"
|
|
54
|
+
>
|
|
55
|
+
${APP_NAME}
|
|
56
|
+
</h1>
|
|
57
|
+
|
|
58
|
+
<p
|
|
59
|
+
style="
|
|
60
|
+
margin:8px 0 0;
|
|
61
|
+
color:#ffffff;
|
|
62
|
+
opacity:.9;
|
|
63
|
+
font-size:14px;
|
|
64
|
+
"
|
|
65
|
+
>
|
|
66
|
+
Verification Code
|
|
67
|
+
</p>
|
|
68
|
+
</td>
|
|
69
|
+
</tr>
|
|
70
|
+
|
|
71
|
+
<!-- Body -->
|
|
72
|
+
<tr>
|
|
73
|
+
<td style="padding:40px;">
|
|
74
|
+
|
|
75
|
+
<h2
|
|
76
|
+
style="
|
|
77
|
+
margin-top:0;
|
|
78
|
+
color:#111827;
|
|
79
|
+
"
|
|
80
|
+
>
|
|
81
|
+
Hello 👋
|
|
82
|
+
</h2>
|
|
83
|
+
|
|
84
|
+
<p
|
|
85
|
+
style="
|
|
86
|
+
font-size:15px;
|
|
87
|
+
color:#4b5563;
|
|
88
|
+
line-height:1.7;
|
|
89
|
+
"
|
|
90
|
+
>
|
|
91
|
+
Use the verification code below to continue with your request.
|
|
92
|
+
This code is valid for
|
|
93
|
+
<strong>${expiry} minutes</strong>.
|
|
94
|
+
</p>
|
|
95
|
+
|
|
96
|
+
<div
|
|
97
|
+
style="
|
|
98
|
+
text-align:center;
|
|
99
|
+
margin:40px 0;
|
|
100
|
+
"
|
|
101
|
+
>
|
|
102
|
+
<span
|
|
103
|
+
style="
|
|
104
|
+
display:inline-block;
|
|
105
|
+
padding:18px 40px;
|
|
106
|
+
border-radius:12px;
|
|
107
|
+
background:#eff6ff;
|
|
108
|
+
color:${APP_PRIMARY_COLOR};
|
|
109
|
+
font-size:34px;
|
|
110
|
+
font-weight:bold;
|
|
111
|
+
letter-spacing:8px;
|
|
112
|
+
"
|
|
113
|
+
>
|
|
114
|
+
${otp}
|
|
115
|
+
</span>
|
|
116
|
+
</div>
|
|
117
|
+
|
|
118
|
+
<p
|
|
119
|
+
style="
|
|
120
|
+
font-size:14px;
|
|
121
|
+
color:#6b7280;
|
|
122
|
+
line-height:1.7;
|
|
123
|
+
"
|
|
124
|
+
>
|
|
125
|
+
If you didn't request this code, you can safely ignore this
|
|
126
|
+
email. No further action is required.
|
|
127
|
+
</p>
|
|
128
|
+
|
|
129
|
+
</td>
|
|
130
|
+
</tr>
|
|
131
|
+
|
|
132
|
+
<!-- Footer -->
|
|
133
|
+
<tr>
|
|
134
|
+
<td
|
|
135
|
+
align="center"
|
|
136
|
+
style="
|
|
137
|
+
background:#f9fafb;
|
|
138
|
+
padding:24px;
|
|
139
|
+
border-top:1px solid #e5e7eb;
|
|
140
|
+
"
|
|
141
|
+
>
|
|
142
|
+
|
|
143
|
+
${
|
|
144
|
+
APP_URL
|
|
145
|
+
? `
|
|
146
|
+
<a
|
|
147
|
+
href="${APP_URL}"
|
|
148
|
+
style="
|
|
149
|
+
color:${APP_PRIMARY_COLOR};
|
|
150
|
+
text-decoration:none;
|
|
151
|
+
font-size:14px;
|
|
152
|
+
font-weight:600;
|
|
153
|
+
"
|
|
154
|
+
>
|
|
155
|
+
${APP_URL}
|
|
156
|
+
</a>
|
|
157
|
+
|
|
158
|
+
<br><br>
|
|
159
|
+
`
|
|
160
|
+
: ""
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
<span
|
|
164
|
+
style="
|
|
165
|
+
color:#9ca3af;
|
|
166
|
+
font-size:13px;
|
|
167
|
+
"
|
|
168
|
+
>
|
|
169
|
+
© ${new Date().getFullYear()} ${APP_NAME}. All rights reserved.
|
|
170
|
+
</span>
|
|
171
|
+
|
|
172
|
+
</td>
|
|
173
|
+
</tr>
|
|
174
|
+
|
|
175
|
+
</table>
|
|
176
|
+
|
|
177
|
+
</td>
|
|
178
|
+
</tr>
|
|
179
|
+
</table>
|
|
180
|
+
|
|
181
|
+
</body>
|
|
182
|
+
|
|
183
|
+
</html>
|
|
184
|
+
`,
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
export const sendOtpEmail = async (to, otp, expiry = 10) => {
|
|
188
|
+
const template = emailOtp(otp, expiry);
|
|
189
|
+
await sendEmail(to, template.subject, template.html);
|
|
190
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import jwt from "jsonwebtoken";
|
|
2
|
+
|
|
3
|
+
const genOtpToken = (user, res) => {
|
|
4
|
+
const token = jwt.sign({ id: user._id || user.id }, process.env.JWT_SECRET, {
|
|
5
|
+
expiresIn: "10m",
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
if (res) {
|
|
9
|
+
res.cookie("token", token, {
|
|
10
|
+
httpOnly: true,
|
|
11
|
+
secure: process.env.NODE_ENV === "production",
|
|
12
|
+
sameSite: "strict",
|
|
13
|
+
maxAge: 10 * 60 * 1000, // 10 minutes
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return token;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default genOtpToken;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import webpush from "web-push";
|
|
2
|
+
import logger from "./logger.js";
|
|
3
|
+
|
|
4
|
+
const generateVapidKeys = () => {
|
|
5
|
+
const vapidKeys = webpush.generateVAPIDKeys();
|
|
6
|
+
logger.info("Generated VAPID Keys:");
|
|
7
|
+
logger.info(`Public Key: ${vapidKeys.publicKey}`);
|
|
8
|
+
logger.info(`Private Key: ${vapidKeys.privateKey}`);
|
|
9
|
+
return vapidKeys;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default generateVapidKeys;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import jwt from "jsonwebtoken";
|
|
2
|
+
|
|
3
|
+
export const generateToken = (user, res) => {
|
|
4
|
+
const payload = { id: user._id || user.id };
|
|
5
|
+
const token = jwt.sign(payload, process.env.JWT_SECRET, { expiresIn: "30d" });
|
|
6
|
+
|
|
7
|
+
if (res) {
|
|
8
|
+
res.cookie("token", token, {
|
|
9
|
+
httpOnly: true,
|
|
10
|
+
secure: process.env.NODE_ENV === "production",
|
|
11
|
+
sameSite: "strict",
|
|
12
|
+
maxAge: 30 * 24 * 60 * 60 * 1000, // 30 days
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return token;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const verifyToken = (token) => {
|
|
19
|
+
try {
|
|
20
|
+
const JWT_SECRET = process.env.JWT_SECRET;
|
|
21
|
+
return jwt.verify(token, JWT_SECRET);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const colors = {
|
|
2
|
+
reset: "\x1b[0m",
|
|
3
|
+
info: "\x1b[36m", // Cyan
|
|
4
|
+
success: "\x1b[32m", // Green
|
|
5
|
+
warn: "\x1b[33m", // Yellow
|
|
6
|
+
error: "\x1b[31m", // Red
|
|
7
|
+
timestamp: "\x1b[90m", // Gray
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const formatMessage = (level, message) => {
|
|
11
|
+
const timestamp = new Date().toISOString();
|
|
12
|
+
return `${colors.timestamp}[${timestamp}]${colors.reset} ${colors[level] || colors.reset}[${level.toUpperCase()}]${colors.reset} ${message}`;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const logger = {
|
|
16
|
+
info: (msg) => console.log(formatMessage("info", msg)),
|
|
17
|
+
success: (msg) => console.log(formatMessage("success", msg)),
|
|
18
|
+
warn: (msg) => console.warn(formatMessage("warn", msg)),
|
|
19
|
+
error: (msg, err) => {
|
|
20
|
+
console.error(formatMessage("error", msg));
|
|
21
|
+
if (err) console.error(err);
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default logger;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# ==========================
|
|
2
|
+
# Application
|
|
3
|
+
# ==========================
|
|
4
|
+
NODE_ENV=development
|
|
5
|
+
PORT=5000
|
|
6
|
+
|
|
7
|
+
APP_NAME=My App
|
|
8
|
+
APP_URL=http://localhost:5173
|
|
9
|
+
APP_EMAIL=noreply@example.com
|
|
10
|
+
APP_PRIMARY_COLOR=#2563eb
|
|
11
|
+
|
|
12
|
+
# ==========================
|
|
13
|
+
# Database
|
|
14
|
+
# ==========================
|
|
15
|
+
|
|
16
|
+
DATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public"
|
|
17
|
+
|
|
18
|
+
# ==========================
|
|
19
|
+
# JWT
|
|
20
|
+
# ==========================
|
|
21
|
+
JWT_SECRET=
|
|
22
|
+
JWT_EXPIRES_IN=7d
|
|
23
|
+
|
|
24
|
+
# ==========================
|
|
25
|
+
# Cloudinary
|
|
26
|
+
# ==========================
|
|
27
|
+
CLOUDINARY_CLOUD_NAME=
|
|
28
|
+
CLOUDINARY_API_KEY=
|
|
29
|
+
CLOUDINARY_API_SECRET=
|
|
30
|
+
|
|
31
|
+
# ==========================
|
|
32
|
+
# Email (SMTP)
|
|
33
|
+
# ==========================
|
|
34
|
+
SMTP_HOST=smtp.gmail.com
|
|
35
|
+
SMTP_PORT=587
|
|
36
|
+
SMTP_SECURE=false
|
|
37
|
+
SMTP_USER=
|
|
38
|
+
SMTP_PASS=
|
|
39
|
+
SMTP_FROM="My App <noreply@example.com>"
|
|
40
|
+
|
|
41
|
+
# ==========================
|
|
42
|
+
# CORS
|
|
43
|
+
# ==========================
|
|
44
|
+
CLIENT_URL=http://localhost:5173
|
|
45
|
+
|
|
46
|
+
# ==========================
|
|
47
|
+
# Cookie
|
|
48
|
+
# ==========================
|
|
49
|
+
COOKIE_NAME=token
|
|
50
|
+
COOKIE_EXPIRES_IN=7d
|
|
51
|
+
|
|
52
|
+
# ==========================
|
|
53
|
+
# Rate Limiting
|
|
54
|
+
# ==========================
|
|
55
|
+
RATE_LIMIT_WINDOW=15
|
|
56
|
+
RATE_LIMIT_MAX=100
|
|
57
|
+
|
|
58
|
+
# ==========================
|
|
59
|
+
# Rate Limiting
|
|
60
|
+
# ==========================
|
|
61
|
+
VAPID_PRIVATE_KEY=
|
|
62
|
+
VAPID_PUBLIC_KEY=
|
|
63
|
+
VAPID_SUBJECT=mailto:noreply@example.com
|