stackkit 0.3.5 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (192) hide show
  1. package/README.md +50 -42
  2. package/dist/cli/add.js +122 -56
  3. package/dist/cli/create.d.ts +2 -0
  4. package/dist/cli/create.js +271 -95
  5. package/dist/cli/doctor.js +1 -0
  6. package/dist/cli/list.d.ts +1 -1
  7. package/dist/cli/list.js +6 -4
  8. package/dist/index.js +234 -191
  9. package/dist/lib/constants.d.ts +4 -0
  10. package/dist/lib/constants.js +4 -0
  11. package/dist/lib/discovery/module-discovery.d.ts +4 -0
  12. package/dist/lib/discovery/module-discovery.js +56 -0
  13. package/dist/lib/generation/code-generator.d.ts +11 -2
  14. package/dist/lib/generation/code-generator.js +42 -3
  15. package/dist/lib/generation/generator-utils.js +3 -1
  16. package/dist/lib/pm/package-manager.js +16 -13
  17. package/dist/lib/ui/logger.js +3 -2
  18. package/dist/lib/utils/path-resolver.d.ts +2 -0
  19. package/dist/lib/utils/path-resolver.js +8 -0
  20. package/dist/meta.json +8312 -0
  21. package/modules/auth/better-auth/files/{shared → express}/config/env.ts +48 -50
  22. package/modules/auth/better-auth/files/express/middlewares/authorize.ts +20 -1
  23. package/modules/auth/better-auth/files/express/modules/auth.controller.ts +349 -0
  24. package/modules/auth/better-auth/files/express/modules/{auth/auth.route.ts → auth.route.ts} +9 -4
  25. package/modules/auth/better-auth/files/express/modules/auth.service.ts +664 -0
  26. package/modules/auth/better-auth/files/express/modules/{auth/auth.type.ts → auth.type.ts} +22 -9
  27. package/modules/auth/better-auth/files/{shared/mongoose/auth/helper.ts → express/mongo-modules/auth.helper.ts} +11 -1
  28. package/modules/auth/better-auth/files/express/types/express.d.ts +11 -0
  29. package/modules/auth/better-auth/files/nextjs/api-route.ts +74 -0
  30. package/modules/auth/better-auth/files/nextjs/dashboard/pages/(user)/page.tsx +6 -0
  31. package/modules/auth/better-auth/files/nextjs/dashboard/pages/admin/page.tsx +6 -0
  32. package/modules/auth/better-auth/files/nextjs/dashboard/pages/layout.tsx +48 -0
  33. package/modules/auth/better-auth/files/nextjs/dashboard/pages/my-profile/page.tsx +5 -0
  34. package/modules/auth/better-auth/files/nextjs/features/services/auth.service.ts +102 -0
  35. package/modules/auth/better-auth/files/nextjs/layout/layout.tsx +13 -0
  36. package/modules/auth/better-auth/files/nextjs/lib/axios/http.ts +158 -0
  37. package/modules/auth/better-auth/files/nextjs/lib/env.ts +35 -0
  38. package/modules/auth/better-auth/files/nextjs/lib/utils/auth.ts +75 -0
  39. package/modules/auth/better-auth/files/nextjs/lib/utils/cookie.ts +29 -0
  40. package/modules/auth/better-auth/files/nextjs/lib/utils/jwt.ts +28 -0
  41. package/modules/auth/better-auth/files/nextjs/lib/utils/token.ts +49 -0
  42. package/modules/auth/better-auth/files/nextjs/pages/forgot-password/page.tsx +5 -0
  43. package/modules/auth/better-auth/files/nextjs/pages/layout.tsx +11 -0
  44. package/modules/auth/better-auth/files/nextjs/pages/login/page.tsx +9 -0
  45. package/modules/auth/better-auth/files/nextjs/pages/register/page.tsx +5 -0
  46. package/modules/auth/better-auth/files/nextjs/pages/reset-password/page.tsx +10 -0
  47. package/modules/auth/better-auth/files/nextjs/pages/verify-email/page.tsx +10 -0
  48. package/modules/auth/better-auth/files/nextjs/proxy.ts +154 -42
  49. package/modules/auth/better-auth/files/nextjs/theme/providers/theme-provider.tsx +11 -0
  50. package/modules/auth/better-auth/files/nextjs/types/api.types.ts +18 -0
  51. package/modules/auth/better-auth/files/react/components/protected-route.tsx +39 -0
  52. package/modules/auth/better-auth/files/react/components/route-guards.tsx +13 -0
  53. package/modules/auth/better-auth/files/react/dashboard/admin/pages/overview.tsx +3 -0
  54. package/modules/auth/better-auth/files/react/dashboard/pages/overview.tsx +3 -0
  55. package/modules/auth/better-auth/files/react/features/pages/forgot-password.tsx +5 -0
  56. package/modules/auth/better-auth/files/react/features/pages/login.tsx +5 -0
  57. package/modules/auth/better-auth/files/react/features/pages/my-profile.tsx +5 -0
  58. package/modules/auth/better-auth/files/react/features/pages/oauth-callback.tsx +59 -0
  59. package/modules/auth/better-auth/files/react/features/pages/register.tsx +5 -0
  60. package/modules/auth/better-auth/files/react/features/pages/reset-password.tsx +10 -0
  61. package/modules/auth/better-auth/files/react/features/pages/verify-email.tsx +10 -0
  62. package/modules/auth/better-auth/files/react/layout/dashboard-layout.tsx +54 -0
  63. package/modules/auth/better-auth/files/react/lib/axios/http.ts +68 -0
  64. package/modules/auth/better-auth/files/react/lib/env.ts +25 -0
  65. package/modules/auth/better-auth/files/react/router.tsx +73 -0
  66. package/modules/auth/better-auth/files/react/theme/components/providers/theme-provider-context.ts +13 -0
  67. package/modules/auth/better-auth/files/react/theme/components/providers/theme-provider.tsx +51 -0
  68. package/modules/auth/better-auth/files/react/theme/hooks/use-theme.ts +8 -0
  69. package/modules/auth/better-auth/files/shared/features/components/change-password-dialog.tsx +113 -0
  70. package/modules/auth/better-auth/files/shared/features/components/forgot-password-form.tsx +84 -0
  71. package/modules/auth/better-auth/files/shared/features/components/login-form.tsx +134 -0
  72. package/modules/auth/better-auth/files/shared/features/components/my-profile.tsx +147 -0
  73. package/modules/auth/better-auth/files/shared/features/components/profile-form.tsx +205 -0
  74. package/modules/auth/better-auth/files/shared/features/components/register-form.tsx +100 -0
  75. package/modules/auth/better-auth/files/shared/features/components/reset-password-form.tsx +111 -0
  76. package/modules/auth/better-auth/files/shared/features/components/social-login-buttons.tsx +47 -0
  77. package/modules/auth/better-auth/files/shared/features/components/user-profile-menu.tsx +106 -0
  78. package/modules/auth/better-auth/files/shared/features/components/verify-email-form.tsx +110 -0
  79. package/modules/auth/better-auth/files/shared/features/queries/auth.mutations.tsx +312 -0
  80. package/modules/auth/better-auth/files/shared/features/queries/auth.querie.ts +19 -0
  81. package/modules/auth/better-auth/files/shared/features/services/auth.api.ts +81 -0
  82. package/modules/auth/better-auth/files/shared/features/types/auth.type.ts +47 -0
  83. package/modules/auth/better-auth/files/shared/features/validators/change-password.validator.ts +18 -0
  84. package/modules/auth/better-auth/files/shared/features/validators/forgot.validator.ts +7 -0
  85. package/modules/auth/better-auth/files/shared/features/validators/login.validator.ts +14 -0
  86. package/modules/auth/better-auth/files/shared/features/validators/profile.validator.ts +8 -0
  87. package/modules/auth/better-auth/files/shared/features/validators/register.validator.ts +9 -0
  88. package/modules/auth/better-auth/files/shared/features/validators/reset.validator.ts +9 -0
  89. package/modules/auth/better-auth/files/shared/features/validators/verify.validator.ts +8 -0
  90. package/modules/auth/better-auth/files/shared/lib/auth-client.ts +2 -1
  91. package/modules/auth/better-auth/files/shared/lib/auth.ts +5 -19
  92. package/modules/auth/better-auth/files/shared/lib/constant/dashboard.ts +90 -0
  93. package/modules/auth/better-auth/files/shared/theme/mode-toggle.tsx +30 -0
  94. package/modules/auth/better-auth/files/shared/ui/shadcn/components/dashboard/dashboard-header.tsx +94 -0
  95. package/modules/auth/better-auth/files/shared/ui/shadcn/components/dashboard/dashboard-sidebar.tsx +255 -0
  96. package/modules/auth/better-auth/files/shared/ui/shadcn/components/footer.tsx +35 -0
  97. package/modules/auth/better-auth/files/shared/ui/shadcn/components/navbar.tsx +145 -0
  98. package/modules/auth/better-auth/files/shared/ui/shadcn/form-field/input-field.tsx +440 -0
  99. package/modules/auth/better-auth/files/shared/utils/email.ts +2 -17
  100. package/modules/auth/better-auth/generator.json +172 -51
  101. package/modules/auth/better-auth/module.json +2 -2
  102. package/modules/components/files/shared/hooks/use-file-upload.ts +412 -0
  103. package/modules/components/files/shared/lib/utils/url-helpers.ts +110 -0
  104. package/modules/components/files/shared/shadcn/dashboard/data-table-column-selector.tsx +52 -0
  105. package/modules/components/files/shared/shadcn/dashboard/data-table-footer.tsx +156 -0
  106. package/modules/components/files/shared/shadcn/dashboard/data-table.tsx +405 -0
  107. package/modules/components/files/shared/shadcn/global/form-field/input-field.tsx +440 -0
  108. package/modules/components/files/shared/shadcn/global/form-field/media-uploader-field.tsx +745 -0
  109. package/modules/components/files/shared/shadcn/global/form-field/multi-select-field.tsx +207 -0
  110. package/modules/components/files/shared/shadcn/global/form-field/select-field.tsx +247 -0
  111. package/modules/components/files/shared/shadcn/global/form-field/textarea-field.tsx +277 -0
  112. package/modules/components/files/shared/shadcn/global/form-field/tiptap-editor-field.tsx +35 -0
  113. package/modules/components/files/shared/shadcn/global/no-results.tsx +41 -0
  114. package/modules/components/files/shared/shadcn/tiptap-editor/editor-menu-bar.tsx +217 -0
  115. package/modules/components/files/shared/shadcn/tiptap-editor/tiptap-editor.tsx +104 -0
  116. package/modules/components/files/shared/url/load-more.tsx +93 -0
  117. package/modules/components/files/shared/url/search-bar.tsx +131 -0
  118. package/modules/components/files/shared/url/sort-select.tsx +118 -0
  119. package/modules/components/files/shared/url/url-tabs.tsx +77 -0
  120. package/modules/components/generator.json +109 -0
  121. package/modules/components/module.json +11 -0
  122. package/modules/database/mongoose/generator.json +3 -14
  123. package/modules/database/mongoose/module.json +2 -2
  124. package/modules/database/prisma/generator.json +6 -12
  125. package/modules/database/prisma/module.json +2 -2
  126. package/modules/storage/cloudinary/files/express/config/env.ts +65 -0
  127. package/modules/storage/cloudinary/files/express/config/media.ts +103 -0
  128. package/modules/storage/cloudinary/files/express/modules/media/media.controller.ts +59 -0
  129. package/modules/storage/cloudinary/files/express/modules/media/media.route.ts +29 -0
  130. package/modules/storage/cloudinary/files/express/modules/media/media.service.ts +113 -0
  131. package/modules/storage/cloudinary/files/express/modules/media/media.type.ts +32 -0
  132. package/modules/storage/cloudinary/generator.json +34 -0
  133. package/modules/storage/cloudinary/module.json +11 -0
  134. package/modules/ui/shadcn/generator.json +21 -0
  135. package/modules/ui/shadcn/module.json +11 -0
  136. package/package.json +24 -26
  137. package/templates/express/README.md +11 -16
  138. package/templates/express/src/config/env.ts +7 -5
  139. package/templates/nextjs/README.md +13 -18
  140. package/templates/nextjs/app/favicon.ico +0 -0
  141. package/templates/nextjs/app/layout.tsx +6 -4
  142. package/templates/nextjs/components/providers/query-provider.tsx +3 -0
  143. package/templates/nextjs/env.example +3 -1
  144. package/templates/nextjs/lib/axios/http.ts +23 -0
  145. package/templates/nextjs/lib/env.ts +7 -5
  146. package/templates/nextjs/package.json +2 -1
  147. package/templates/nextjs/template.json +1 -2
  148. package/templates/react/README.md +9 -14
  149. package/templates/react/index.html +1 -1
  150. package/templates/react/package.json +1 -1
  151. package/templates/react/src/assets/favicon.ico +0 -0
  152. package/templates/react/src/components/providers/query-provider.tsx +38 -0
  153. package/templates/react/src/{shared/components → components}/seo.tsx +4 -8
  154. package/templates/react/src/lib/axios/http.ts +24 -0
  155. package/templates/react/src/main.tsx +8 -11
  156. package/templates/react/src/{features/about/pages → pages}/about.tsx +1 -1
  157. package/templates/react/src/{features/home/pages → pages}/home.tsx +1 -1
  158. package/templates/react/src/router.tsx +6 -6
  159. package/templates/react/src/vite-env.d.ts +2 -1
  160. package/templates/react/template.json +0 -1
  161. package/templates/react/tsconfig.app.json +6 -0
  162. package/templates/react/tsconfig.json +7 -1
  163. package/templates/react/vite.config.ts +12 -0
  164. package/modules/auth/authjs/files/nextjs/api/auth/[...nextauth]/route.ts +0 -3
  165. package/modules/auth/authjs/files/nextjs/proxy.ts +0 -1
  166. package/modules/auth/authjs/files/shared/lib/auth.ts +0 -119
  167. package/modules/auth/authjs/files/shared/prisma/schema.prisma +0 -61
  168. package/modules/auth/authjs/generator.json +0 -64
  169. package/modules/auth/authjs/module.json +0 -13
  170. package/modules/auth/better-auth/files/express/modules/auth/auth.controller.ts +0 -264
  171. package/modules/auth/better-auth/files/express/modules/auth/auth.service.ts +0 -549
  172. package/modules/auth/better-auth/files/express/templates/google-redirect.ejs +0 -24
  173. package/modules/auth/better-auth/files/nextjs/api/auth/[...all]/route.ts +0 -4
  174. package/modules/auth/better-auth/files/nextjs/lib/auth/auth-guards.ts +0 -31
  175. package/modules/auth/better-auth/files/nextjs/templates/email-otp.tsx +0 -74
  176. package/templates/nextjs/lib/api/http.ts +0 -40
  177. package/templates/react/public/vite.svg +0 -1
  178. package/templates/react/src/app/layouts/dashboard-layout.tsx +0 -8
  179. package/templates/react/src/app/layouts/public-layout.tsx +0 -5
  180. package/templates/react/src/app/providers.tsx +0 -20
  181. package/templates/react/src/app/router.tsx +0 -21
  182. package/templates/react/src/assets/react.svg +0 -1
  183. package/templates/react/src/shared/api/http.ts +0 -39
  184. package/templates/react/src/shared/components/loading.tsx +0 -8
  185. package/templates/react/src/shared/lib/query-client.ts +0 -12
  186. package/templates/react/src/utils/storage.ts +0 -35
  187. package/templates/react/src/utils/utils.ts +0 -3
  188. /package/modules/auth/better-auth/files/{shared/mongoose/auth/constants.ts → express/mongo-modules/auth.constants.ts} +0 -0
  189. /package/templates/nextjs/app/{page.tsx → (public)/(root)/page.tsx} +0 -0
  190. /package/templates/react/src/{shared/components → components}/error-boundary.tsx +0 -0
  191. /package/templates/react/src/{shared/components → components}/layout.tsx +0 -0
  192. /package/templates/react/src/{shared/pages → pages}/not-found.tsx +0 -0
@@ -1,61 +0,0 @@
1
- {{#if prismaProvider == "mongodb"}}
2
- {{#var defaultId = @default(auto()) @map("_id") @db.ObjectId}}
3
- {{else}}
4
- {{#var defaultId = @default(cuid())}}
5
- {{/if}}
6
- model Account {
7
- id String @id {{defaultId}}
8
- userId String @map("user_id")
9
- type String
10
- provider String
11
- providerAccountId String @map("provider_account_id")
12
- refresh_token String? @db.Text
13
- access_token String? @db.Text
14
- expires_at Int?
15
- token_type String?
16
- scope String?
17
- id_token String? @db.Text
18
- session_state String?
19
-
20
- user User @relation(fields: [userId], references: [id], onDelete: Cascade)
21
-
22
- @@unique([provider, providerAccountId])
23
- @@map("accounts")
24
- }
25
-
26
- model Session {
27
- id String @id {{defaultId}}
28
- sessionToken String @unique @map("session_token")
29
- userId String {{#if prismaProvider == "mongodb"}} @db.ObjectId{{/if}} @map("user_id")
30
- expires DateTime
31
- user User @relation(fields: [userId], references: [id], onDelete: Cascade)
32
-
33
- @@map("sessions")
34
- }
35
-
36
- model User {
37
- id String @id {{defaultId}}
38
- name String?
39
- email String? @unique
40
- emailVerified DateTime? @map("email_verified")
41
- image String?
42
- role Role @default(USER)
43
- accounts Account[]
44
- sessions Session[]
45
-
46
- @@map("users")
47
- }
48
-
49
- model VerificationToken {
50
- identifier String
51
- token String
52
- expires DateTime
53
-
54
- @@unique([identifier, token])
55
- @@map("verification_tokens")
56
- }
57
-
58
- enum Role {
59
- USER
60
- ADMIN
61
- }
@@ -1,64 +0,0 @@
1
- {
2
- "name": "authjs",
3
- "type": "auth",
4
- "priority": 10,
5
- "operations": [
6
- {
7
- "type": "create-file",
8
- "source": "nextjs/api/auth/[...nextauth]/route.ts",
9
- "destination": "app/api/auth/[...nextauth]/route.ts"
10
- },
11
- {
12
- "type": "create-file",
13
- "source": "nextjs/proxy.ts",
14
- "destination": "proxy.ts"
15
- },
16
- {
17
- "type": "create-file",
18
- "source": "shared/lib/auth.ts",
19
- "destination": "server/auth/auth.ts"
20
- },
21
- {
22
- "type": "patch-file",
23
- "destination": "prisma/schema.prisma",
24
- "condition": { "database": "prisma" },
25
- "operations": [
26
- {
27
- "type": "add-to-bottom",
28
- "source": "shared/prisma/schema.prisma"
29
- }
30
- ]
31
- },
32
- {
33
- "type": "add-dependency",
34
- "condition": { "database": "prisma" },
35
- "dependencies": {
36
- "@auth/prisma-adapter": "^2.11.1"
37
- }
38
- },
39
- {
40
- "type": "add-dependency",
41
- "dependencies": {
42
- "bcryptjs": "^3.0.3",
43
- "next-auth": "^5.0.0-beta.30",
44
- "nodemailer": "^7.0.12"
45
- },
46
- "devDependencies": {
47
- "@types/nodemailer": "^7.0.5"
48
- }
49
- },
50
- {
51
- "type": "add-env",
52
- "envVars": {
53
- "AUTH_SECRET": "",
54
- "AUTH_GOOGLE_ID": "",
55
- "AUTH_GOOGLE_SECRET": "",
56
- "EMAIL_HOST": "smtp.gmail.com",
57
- "EMAIL_PORT": "587",
58
- "EMAIL_USER": "",
59
- "EMAIL_PASS": "",
60
- "EMAIL_FROM": "noreply@yourapp.com"
61
- }
62
- }
63
- ]
64
- }
@@ -1,13 +0,0 @@
1
- {
2
- "name": "authjs",
3
- "displayName": "Auth.js",
4
- "category": "auth",
5
- "provider": "authjs",
6
- "supportedFrameworks": ["nextjs"],
7
- "compatibility": {
8
- "frameworks": ["nextjs"],
9
- "databases": ["prisma"],
10
- "languages": ["typescript", "javascript"],
11
- "packageManagers": ["npm", "yarn", "pnpm", "bun"]
12
- }
13
- }
@@ -1,264 +0,0 @@
1
- import { Request, Response } from "express";
2
- import status from "http-status";
3
- import { envVars } from "../../config/env";
4
- import { auth } from "../../lib/auth";
5
- import { AppError } from "../../shared/errors/app-error";
6
- import { catchAsync } from "../../shared/utils/catch-async";
7
- import { cookieUtils } from "../../shared/utils/cookie";
8
- import { sendResponse } from "../../shared/utils/send-response";
9
- import { tokenUtils } from "../../shared/utils/token";
10
- import { authService } from "./auth.service";
11
-
12
- const registerUser = catchAsync(async (req: Request, res: Response) => {
13
- const payload = req.body;
14
-
15
- const result = await authService.registerUser(payload);
16
-
17
- const { accessToken, refreshToken, token, ...rest } = result;
18
-
19
- tokenUtils.setAccessTokenCookie(res, accessToken);
20
- tokenUtils.setRefreshTokenCookie(res, refreshToken);
21
- tokenUtils.setBetterAuthSessionCookie(res, token as string);
22
-
23
- sendResponse(res, {
24
- status: status.CREATED,
25
- success: true,
26
- message: "User registered successfully",
27
- data: {
28
- token,
29
- accessToken,
30
- refreshToken,
31
- ...rest,
32
- },
33
- });
34
- });
35
-
36
- const loginUser = catchAsync(
37
- async (req: Request, res: Response) => {
38
- const payload = req.body;
39
- const result = await authService.loginUser(payload);
40
- const { accessToken, refreshToken, token, ...rest } = result
41
-
42
- if (!token) {
43
- throw new AppError(
44
- status.INTERNAL_SERVER_ERROR,
45
- "Session token is missing",
46
- );
47
- }
48
-
49
- tokenUtils.setAccessTokenCookie(res, accessToken);
50
- tokenUtils.setRefreshTokenCookie(res, refreshToken);
51
- tokenUtils.setBetterAuthSessionCookie(res, token);
52
-
53
- sendResponse(res, {
54
- status: status.OK,
55
- success: true,
56
- message: "User logged in successfully",
57
- data: {
58
- token,
59
- accessToken,
60
- refreshToken,
61
- ...rest,
62
- },
63
- });
64
- }
65
- )
66
-
67
- const getMe = catchAsync(
68
- async (req: Request, res: Response) => {
69
- const user = req.user;
70
- const result = await authService.getMe(user);
71
- sendResponse(res, {
72
- status: status.OK,
73
- success: true,
74
- message: "User profile fetched successfully",
75
- data: result,
76
- });
77
- }
78
- )
79
-
80
- const getNewToken = catchAsync(
81
- async (req: Request, res: Response) => {
82
- const refreshToken = req.cookies.refreshToken;
83
- const betterAuthSessionToken = req.cookies["better-auth.session_token"];
84
- if (!refreshToken) {
85
- throw new AppError(status.UNAUTHORIZED, "Refresh token is missing");
86
- }
87
- const result = await authService.getNewToken(refreshToken, betterAuthSessionToken);
88
-
89
- const { accessToken, refreshToken: newRefreshToken, sessionToken } = result;
90
-
91
- tokenUtils.setAccessTokenCookie(res, accessToken);
92
- tokenUtils.setRefreshTokenCookie(res, newRefreshToken);
93
- tokenUtils.setBetterAuthSessionCookie(res, sessionToken);
94
-
95
- sendResponse(res, {
96
- status: status.OK,
97
- success: true,
98
- message: "New tokens generated successfully",
99
- data: {
100
- accessToken,
101
- refreshToken: newRefreshToken,
102
- sessionToken,
103
- },
104
- });
105
- }
106
- )
107
-
108
- const changePassword = catchAsync(
109
- async (req: Request, res: Response) => {
110
- const payload = req.body;
111
- const betterAuthSessionToken = req.cookies["better-auth.session_token"];
112
-
113
- const result = await authService.changePassword(payload, betterAuthSessionToken);
114
-
115
- const { accessToken, refreshToken, token } = result;
116
-
117
- tokenUtils.setAccessTokenCookie(res, accessToken);
118
- tokenUtils.setRefreshTokenCookie(res, refreshToken);
119
- tokenUtils.setBetterAuthSessionCookie(res, token as string);
120
-
121
- sendResponse(res, {
122
- status: status.OK,
123
- success: true,
124
- message: "Password changed successfully",
125
- data: result,
126
- });
127
- }
128
- )
129
-
130
- const logoutUser = catchAsync(
131
- async (req: Request, res: Response) => {
132
- const betterAuthSessionToken = req.cookies["better-auth.session_token"];
133
- const result = await authService.logoutUser(betterAuthSessionToken);
134
- cookieUtils.clearCookie(res, 'accessToken', {
135
- httpOnly: true,
136
- secure: true,
137
- sameSite: "none",
138
- });
139
- cookieUtils.clearCookie(res, 'refreshToken', {
140
- httpOnly: true,
141
- secure: true,
142
- sameSite: "none",
143
- });
144
- cookieUtils.clearCookie(res, 'better-auth.session_token', {
145
- httpOnly: true,
146
- secure: true,
147
- sameSite: "none",
148
- });
149
-
150
- sendResponse(res, {
151
- status: status.OK,
152
- success: true,
153
- message: "User logged out successfully",
154
- data: result,
155
- });
156
- }
157
- )
158
-
159
- const verifyEmail = catchAsync(
160
- async (req: Request, res: Response) => {
161
- const { email, otp } = req.body;
162
- await authService.verifyEmail(email, otp);
163
-
164
- sendResponse(res, {
165
- status: status.OK,
166
- success: true,
167
- message: "Email verified successfully",
168
- });
169
- }
170
- )
171
-
172
- const forgetPassword = catchAsync(
173
- async (req: Request, res: Response) => {
174
- const { email } = req.body;
175
- await authService.forgetPassword(email);
176
-
177
- sendResponse(res, {
178
- status: status.OK,
179
- success: true,
180
- message: "Password reset OTP sent to email successfully",
181
- });
182
- }
183
- )
184
-
185
- const resetPassword = catchAsync(
186
- async (req: Request, res: Response) => {
187
- const { email, otp, newPassword } = req.body;
188
- await authService.resetPassword(email, otp, newPassword);
189
-
190
- sendResponse(res, {
191
- status: status.OK,
192
- success: true,
193
- message: "Password reset successfully",
194
- });
195
- }
196
- )
197
-
198
- const googleLogin = catchAsync((req: Request, res: Response) => {
199
- const redirectPath = req.query.redirect || "/dashboard";
200
-
201
- const encodedRedirectPath = encodeURIComponent(redirectPath as string);
202
-
203
- const callbackURL = `${envVars.BETTER_AUTH_URL}/api/v1/auth/google/success?redirect=${encodedRedirectPath}`;
204
-
205
- res.render("googleRedirect", {
206
- callbackURL : callbackURL,
207
- betterAuthUrl : envVars.BETTER_AUTH_URL,
208
- })
209
- })
210
-
211
- const googleLoginSuccess = catchAsync(async (req: Request, res: Response) => {
212
- const redirectPath = req.query.redirect as string || "/dashboard";
213
-
214
- const sessionToken = req.cookies["better-auth.session_token"];
215
-
216
- if(!sessionToken){
217
- return res.redirect(`${envVars.FRONTEND_URL}/login?error=oauth_failed`);
218
- }
219
-
220
- const session = await auth.api.getSession({
221
- headers:{
222
- "Cookie" : `better-auth.session_token=${sessionToken}`
223
- }
224
- })
225
-
226
- if (!session) {
227
- return res.redirect(`${envVars.FRONTEND_URL}/login?error=no_session_found`);
228
- }
229
-
230
- if(session && !session.user){
231
- return res.redirect(`${envVars.FRONTEND_URL}/login?error=no_user_found`);
232
- }
233
-
234
- const result = await authService.googleLoginSuccess(session);
235
-
236
- const {accessToken, refreshToken} = result;
237
-
238
- tokenUtils.setAccessTokenCookie(res, accessToken);
239
- tokenUtils.setRefreshTokenCookie(res, refreshToken);
240
- const isValidRedirectPath = redirectPath.startsWith("/") && !redirectPath.startsWith("//");
241
- const finalRedirectPath = isValidRedirectPath ? redirectPath : "/dashboard";
242
-
243
- res.redirect(`${envVars.FRONTEND_URL}${finalRedirectPath}`);
244
- })
245
-
246
- const handleOAuthError = catchAsync((req: Request, res: Response) => {
247
- const error = req.query.error as string || "oauth_failed";
248
- res.redirect(`${envVars.FRONTEND_URL}/login?error=${error}`);
249
- })
250
-
251
- export const authController = {
252
- registerUser,
253
- loginUser,
254
- getMe,
255
- getNewToken,
256
- changePassword,
257
- logoutUser,
258
- verifyEmail,
259
- forgetPassword,
260
- resetPassword,
261
- googleLogin,
262
- googleLoginSuccess,
263
- handleOAuthError,
264
- };