@tulip-systems/core 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (249) hide show
  1. package/dist/auth/server.d.ts +2 -2
  2. package/dist/auth/server.js +3 -3
  3. package/dist/components/common/icons.d.ts +51 -51
  4. package/dist/components/common/icons.d.ts.map +1 -1
  5. package/dist/components/common/status.d.ts +3 -3
  6. package/dist/components/common/status.d.ts.map +1 -1
  7. package/dist/components/editor/components/content.client.d.ts +2 -2
  8. package/dist/components/editor/components/fixed-menu.client.d.ts +2 -2
  9. package/dist/components/editor/context.client.d.ts +4 -4
  10. package/dist/components/editor/context.client.d.ts.map +1 -1
  11. package/dist/components/editor/index.client.d.ts +2 -2
  12. package/dist/components/editor/preview.client.d.ts +2 -2
  13. package/dist/components/header/back-button.client.d.ts +2 -2
  14. package/dist/components/header/bottom-bar.client.d.ts +3 -3
  15. package/dist/components/header/breadcrumbs.client.d.ts +7 -7
  16. package/dist/components/header/header.client.d.ts +2 -2
  17. package/dist/components/header/mobile-nav-switcher.client.d.ts +2 -2
  18. package/dist/components/header/top-bar.client.d.ts +4 -4
  19. package/dist/components/layouts/admin-content.client.d.ts +2 -2
  20. package/dist/components/layouts/admin-layout.d.ts +2 -2
  21. package/dist/components/layouts/admin-layout.js +1 -1
  22. package/dist/components/layouts/admin-layout.js.map +1 -1
  23. package/dist/components/layouts/admin-loading.d.ts +2 -2
  24. package/dist/components/layouts/admin-loading.d.ts.map +1 -1
  25. package/dist/components/layouts/empty-page.d.ts +4 -4
  26. package/dist/components/layouts/empty-page.d.ts.map +1 -1
  27. package/dist/components/layouts/list-layout.d.ts +2 -2
  28. package/dist/components/layouts/list-layout.d.ts.map +1 -1
  29. package/dist/components/layouts/not-found-page.d.ts +4 -3
  30. package/dist/components/layouts/not-found-page.d.ts.map +1 -1
  31. package/dist/components/layouts/not-found-page.js +8 -2
  32. package/dist/components/layouts/not-found-page.js.map +1 -1
  33. package/dist/components/layouts/not-found-section.js +1 -1
  34. package/dist/components/layouts/not-found-section.js.map +1 -1
  35. package/dist/components/layouts/providers.client.d.ts +2 -2
  36. package/dist/components/layouts/root-layout.server.d.ts +2 -2
  37. package/dist/components/layouts/root-layout.server.d.ts.map +1 -1
  38. package/dist/components/layouts/root-loading.d.ts +2 -2
  39. package/dist/components/layouts/root-loading.d.ts.map +1 -1
  40. package/dist/components/layouts/tab-layout.d.ts +2 -2
  41. package/dist/components/layouts/tab-layout.d.ts.map +1 -1
  42. package/dist/components/lists/data-list.d.ts +5 -5
  43. package/dist/components/lists/data-list.d.ts.map +1 -1
  44. package/dist/components/lists/data-stack.d.ts +8 -8
  45. package/dist/components/lists/data-stack.d.ts.map +1 -1
  46. package/dist/components/navigation/admin-sidebar-paths.client.d.ts +10 -10
  47. package/dist/components/ui/accordion.d.ts +5 -5
  48. package/dist/components/ui/accordion.d.ts.map +1 -1
  49. package/dist/components/ui/alert-dialog.d.ts +12 -12
  50. package/dist/components/ui/alert-dialog.d.ts.map +1 -1
  51. package/dist/components/ui/alert.d.ts +4 -4
  52. package/dist/components/ui/alert.d.ts.map +1 -1
  53. package/dist/components/ui/aspect-ratio.d.ts +2 -2
  54. package/dist/components/ui/aspect-ratio.d.ts.map +1 -1
  55. package/dist/components/ui/avatar.client.d.ts +4 -4
  56. package/dist/components/ui/badge.d.ts +2 -2
  57. package/dist/components/ui/badge.d.ts.map +1 -1
  58. package/dist/components/ui/breadcrumb.d.ts +8 -8
  59. package/dist/components/ui/breadcrumb.d.ts.map +1 -1
  60. package/dist/components/ui/button.d.ts +3 -3
  61. package/dist/components/ui/button.d.ts.map +1 -1
  62. package/dist/components/ui/calendar.d.ts +2 -2
  63. package/dist/components/ui/calendar.d.ts.map +1 -1
  64. package/dist/components/ui/card.d.ts +7 -7
  65. package/dist/components/ui/card.d.ts.map +1 -1
  66. package/dist/components/ui/carousel.d.ts +6 -6
  67. package/dist/components/ui/carousel.d.ts.map +1 -1
  68. package/dist/components/ui/chart.client.d.ts +5 -5
  69. package/dist/components/ui/checkbox.d.ts +2 -2
  70. package/dist/components/ui/checkbox.d.ts.map +1 -1
  71. package/dist/components/ui/collapsible.client.d.ts +4 -4
  72. package/dist/components/ui/color-picker.client.d.ts +2 -2
  73. package/dist/components/ui/combobox-dropdown.client.d.ts +2 -2
  74. package/dist/components/ui/combobox.client.d.ts +2 -2
  75. package/dist/components/ui/command.d.ts +10 -10
  76. package/dist/components/ui/command.d.ts.map +1 -1
  77. package/dist/components/ui/context-menu.d.ts +16 -16
  78. package/dist/components/ui/dialog.client.d.ts +11 -11
  79. package/dist/components/ui/drawer.client.d.ts +11 -11
  80. package/dist/components/ui/dropdown-menu.d.ts +16 -16
  81. package/dist/components/ui/form.client.d.ts +7 -7
  82. package/dist/components/ui/hover-card.client.d.ts +4 -4
  83. package/dist/components/ui/input.d.ts +2 -2
  84. package/dist/components/ui/label.d.ts +2 -2
  85. package/dist/components/ui/navigation-menu.d.ts +9 -9
  86. package/dist/components/ui/pagination.d.ts +8 -8
  87. package/dist/components/ui/pagination.d.ts.map +1 -1
  88. package/dist/components/ui/popover.d.ts +5 -5
  89. package/dist/components/ui/progress.client.d.ts +2 -2
  90. package/dist/components/ui/radio-group.d.ts +3 -3
  91. package/dist/components/ui/resizable.client.d.ts +4 -4
  92. package/dist/components/ui/scroll-area.d.ts +3 -3
  93. package/dist/components/ui/select.client.d.ts +11 -11
  94. package/dist/components/ui/separator.d.ts +2 -2
  95. package/dist/components/ui/sheet.client.d.ts +9 -9
  96. package/dist/components/ui/sidebar.client.d.ts +26 -26
  97. package/dist/components/ui/skeleton.d.ts +2 -2
  98. package/dist/components/ui/slider.d.ts +2 -2
  99. package/dist/components/ui/sonner.client.d.ts +2 -2
  100. package/dist/components/ui/switch.d.ts +2 -2
  101. package/dist/components/ui/tabs.d.ts +5 -5
  102. package/dist/components/ui/textarea.d.ts +2 -2
  103. package/dist/components/ui/time-input.client.d.ts +2 -2
  104. package/dist/components/ui/toggle-group.client.d.ts +3 -3
  105. package/dist/components/ui/toggle.d.ts +4 -4
  106. package/dist/components/ui/toggle.d.ts.map +1 -1
  107. package/dist/components/ui/tooltip.client.d.ts +5 -5
  108. package/dist/components/ui/tree.client.d.ts +5 -5
  109. package/dist/components/ui/tree.client.d.ts.map +1 -1
  110. package/dist/components.d.ts +2 -2
  111. package/dist/components.js +2 -2
  112. package/dist/lib/hooks/use-indicator.d.ts +2 -2
  113. package/dist/modules/auth/components/allowed.client.d.ts +2 -2
  114. package/dist/modules/auth/components/auth-layout.server.d.ts +2 -2
  115. package/dist/modules/auth/components/auth-layout.server.d.ts.map +1 -1
  116. package/dist/modules/auth/components/auth-loading.d.ts +2 -2
  117. package/dist/modules/auth/components/auth-loading.js +1 -1
  118. package/dist/modules/auth/components/auth-loading.js.map +1 -1
  119. package/dist/modules/auth/components/forget-password-page.client.d.ts +2 -2
  120. package/dist/modules/auth/components/{guard.js → guard.client.js} +2 -2
  121. package/dist/modules/auth/components/guard.client.js.map +1 -0
  122. package/dist/modules/auth/components/login-page.client.d.ts +2 -2
  123. package/dist/modules/auth/components/login-page.client.js +35 -26
  124. package/dist/modules/auth/components/login-page.client.js.map +1 -1
  125. package/dist/modules/auth/components/reset-password-page.client.d.ts +2 -2
  126. package/dist/modules/auth/components/update-password-command.d.ts +2 -2
  127. package/dist/modules/auth/handler/client.client.d.ts +96 -96
  128. package/dist/modules/auth/handler/client.client.d.ts.map +1 -1
  129. package/dist/modules/auth/handler/proxy.server.d.ts +13 -0
  130. package/dist/modules/auth/handler/proxy.server.d.ts.map +1 -0
  131. package/dist/modules/auth/handler/proxy.server.js +22 -0
  132. package/dist/modules/auth/handler/proxy.server.js.map +1 -0
  133. package/dist/modules/auth/handler/server.server.js +3 -1
  134. package/dist/modules/auth/handler/server.server.js.map +1 -1
  135. package/dist/modules/auth/lib/helpers.server.d.ts +1 -1
  136. package/dist/modules/auth/lib/helpers.server.d.ts.map +1 -1
  137. package/dist/modules/auth/lib/helpers.server.js +1 -4
  138. package/dist/modules/auth/lib/helpers.server.js.map +1 -1
  139. package/dist/modules/auth/lib/validators.d.ts +3 -3
  140. package/dist/modules/auth/lib/validators.d.ts.map +1 -1
  141. package/dist/modules/commands/components/alert-dialog-command.client.d.ts +10 -10
  142. package/dist/modules/commands/components/alert-dialog-command.client.d.ts.map +1 -1
  143. package/dist/modules/commands/components/click-command.client.d.ts +2 -2
  144. package/dist/modules/commands/components/click-command.client.d.ts.map +1 -1
  145. package/dist/modules/commands/components/command-trigger.client.d.ts +6 -6
  146. package/dist/modules/commands/components/command-trigger.client.d.ts.map +1 -1
  147. package/dist/modules/commands/components/dialog-command.client.d.ts +8 -8
  148. package/dist/modules/commands/components/dialog-command.client.d.ts.map +1 -1
  149. package/dist/modules/commands/components/dropdown-command.client.d.ts +5 -5
  150. package/dist/modules/commands/components/dropdown-command.client.d.ts.map +1 -1
  151. package/dist/modules/commands/components/empty-command.client.d.ts +2 -2
  152. package/dist/modules/commands/components/empty-command.client.d.ts.map +1 -1
  153. package/dist/modules/commands/components/form-dialog-command.client.d.ts +11 -11
  154. package/dist/modules/commands/components/form-dialog-command.client.d.ts.map +1 -1
  155. package/dist/modules/commands/menus/context-menu.client.d.ts +2 -2
  156. package/dist/modules/commands/menus/context-menu.client.d.ts.map +1 -1
  157. package/dist/modules/commands/menus/dropdown-menu.client.d.ts +3 -3
  158. package/dist/modules/commands/menus/dropdown-menu.client.d.ts.map +1 -1
  159. package/dist/modules/commands/menus/inline-menu.client.d.ts +3 -3
  160. package/dist/modules/commands/menus/inline-menu.client.d.ts.map +1 -1
  161. package/dist/modules/commands/menus/responsive-menu.client.d.ts +3 -3
  162. package/dist/modules/commands/menus/responsive-menu.client.d.ts.map +1 -1
  163. package/dist/modules/commands/utils/archive-command.client.d.ts +3 -3
  164. package/dist/modules/commands/utils/archive-command.client.d.ts.map +1 -1
  165. package/dist/modules/commands/utils/delete-command.client.d.ts +2 -2
  166. package/dist/modules/commands/utils/delete-command.client.d.ts.map +1 -1
  167. package/dist/modules/commands/utils/send-mail-command.client.d.ts +2 -2
  168. package/dist/modules/commands/utils/send-mail-command.client.d.ts.map +1 -1
  169. package/dist/modules/config/db/helpers.d.ts +4 -4
  170. package/dist/modules/config/db/helpers.d.ts.map +1 -1
  171. package/dist/modules/config/lib/resolve.server.d.ts +3 -0
  172. package/dist/modules/config/lib/resolve.server.d.ts.map +1 -1
  173. package/dist/modules/config/router/client.server.d.ts +2 -2
  174. package/dist/modules/config/router/context.server.d.ts +3 -0
  175. package/dist/modules/config/router/context.server.d.ts.map +1 -1
  176. package/dist/modules/config/router/init.server.d.ts +9 -6
  177. package/dist/modules/config/router/init.server.d.ts.map +1 -1
  178. package/dist/modules/data-tables/components/column-header.d.ts +2 -2
  179. package/dist/modules/data-tables/components/column-header.d.ts.map +1 -1
  180. package/dist/modules/data-tables/components/header.d.ts +4 -4
  181. package/dist/modules/data-tables/components/header.d.ts.map +1 -1
  182. package/dist/modules/data-tables/components/layout.d.ts +2 -2
  183. package/dist/modules/data-tables/components/layout.d.ts.map +1 -1
  184. package/dist/modules/data-tables/components/skeleton.d.ts +2 -2
  185. package/dist/modules/data-tables/components/skeleton.d.ts.map +1 -1
  186. package/dist/modules/data-tables/components/table.d.ts +7 -7
  187. package/dist/modules/data-tables/components/table.d.ts.map +1 -1
  188. package/dist/modules/data-tables/components/toolbar.d.ts +3 -3
  189. package/dist/modules/data-tables/components/toolbar.d.ts.map +1 -1
  190. package/dist/modules/data-tables/tables/data-table/components/table.d.ts +2 -2
  191. package/dist/modules/data-tables/tables/inline-table/components/inputs/select.client.d.ts +2 -2
  192. package/dist/modules/data-tables/tables/inline-table/components/table.d.ts +2 -2
  193. package/dist/modules/data-tables/tables/inline-table/hooks/context.client.d.ts +2 -2
  194. package/dist/modules/inline-edit/components/combobox-dropdown.client.d.ts +2 -2
  195. package/dist/modules/inline-edit/components/combobox-dropdown.client.d.ts.map +1 -1
  196. package/dist/modules/inline-edit/components/combobox.client.d.ts +2 -2
  197. package/dist/modules/inline-edit/components/combobox.client.d.ts.map +1 -1
  198. package/dist/modules/inline-edit/components/date-input.client.d.ts +2 -2
  199. package/dist/modules/inline-edit/components/date-input.client.d.ts.map +1 -1
  200. package/dist/modules/inline-edit/components/date-picker.client.d.ts +2 -2
  201. package/dist/modules/inline-edit/components/date-picker.client.d.ts.map +1 -1
  202. package/dist/modules/inline-edit/components/editor.client.d.ts +2 -2
  203. package/dist/modules/inline-edit/components/editor.client.d.ts.map +1 -1
  204. package/dist/modules/inline-edit/components/input-toggle.client.d.ts +2 -2
  205. package/dist/modules/inline-edit/components/input-toggle.client.d.ts.map +1 -1
  206. package/dist/modules/inline-edit/components/input.client.d.ts +3 -3
  207. package/dist/modules/inline-edit/components/input.client.d.ts.map +1 -1
  208. package/dist/modules/inline-edit/components/richtext.client.d.ts +2 -2
  209. package/dist/modules/inline-edit/components/richtext.client.d.ts.map +1 -1
  210. package/dist/modules/inline-edit/components/select.client.d.ts +6 -6
  211. package/dist/modules/inline-edit/components/select.client.d.ts.map +1 -1
  212. package/dist/modules/inline-edit/components/switch.client.d.ts +2 -2
  213. package/dist/modules/inline-edit/components/switch.client.d.ts.map +1 -1
  214. package/dist/modules/inline-edit/components/toggle.client.d.ts +2 -2
  215. package/dist/modules/inline-edit/components/toggle.client.d.ts.map +1 -1
  216. package/dist/modules/inline-edit/hooks/context.client.d.ts +2 -2
  217. package/dist/modules/inline-edit/hooks/context.client.d.ts.map +1 -1
  218. package/dist/modules/uploads/components/button.client.d.ts +2 -2
  219. package/dist/modules/uploads/components/button.client.d.ts.map +1 -1
  220. package/dist/modules/uploads/components/images/grid.client.d.ts +2 -2
  221. package/dist/modules/uploads/components/images/grid.client.d.ts.map +1 -1
  222. package/dist/modules/uploads/components/images/input.client.d.ts +2 -2
  223. package/dist/modules/uploads/components/images/input.client.d.ts.map +1 -1
  224. package/dist/modules/uploads/components/preview-dialog.client.d.ts +2 -2
  225. package/dist/modules/uploads/components/preview-dialog.client.d.ts.map +1 -1
  226. package/dist/modules/uploads/components/zone.client.d.ts +2 -2
  227. package/dist/modules/uploads/components/zone.client.d.ts.map +1 -1
  228. package/dist/modules/uploads/lib/proxy.server.js +1 -1
  229. package/dist/modules/uploads/lib/route.server.js +1 -1
  230. package/dist/modules/uploads/lib/router.server.d.ts +31 -31
  231. package/dist/modules/uploads/lib/router.server.js +1 -1
  232. package/dist/modules/uploads/lib/validators.d.ts +51 -51
  233. package/package.json +2 -1
  234. package/src/components/layouts/admin-layout.tsx +2 -2
  235. package/src/components/layouts/not-found-page.tsx +9 -1
  236. package/src/components/layouts/not-found-section.tsx +10 -5
  237. package/src/modules/auth/components/auth-loading.tsx +1 -1
  238. package/src/modules/auth/components/login-page.client.tsx +42 -35
  239. package/src/modules/auth/entry.server.ts +1 -1
  240. package/src/modules/auth/handler/proxy.server.ts +28 -0
  241. package/src/modules/auth/handler/server.server.ts +5 -0
  242. package/src/modules/auth/lib/helpers.server.ts +1 -5
  243. package/dist/modules/auth/components/allowed.server.d.ts +0 -23
  244. package/dist/modules/auth/components/allowed.server.d.ts.map +0 -1
  245. package/dist/modules/auth/components/allowed.server.js +0 -24
  246. package/dist/modules/auth/components/allowed.server.js.map +0 -1
  247. package/dist/modules/auth/components/guard.js.map +0 -1
  248. package/src/modules/auth/components/allowed.server.tsx +0 -41
  249. /package/src/modules/auth/components/{guard.tsx → guard.client.tsx} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tulip-systems/core",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "license": "MIT",
@@ -104,6 +104,7 @@
104
104
  "superjson": "^2.2.2",
105
105
  "tailwind-merge": "^3.0.2",
106
106
  "tailwindcss-animate": "^1.0.7",
107
+ "urlpattern-polyfill": "^10.1.0",
107
108
  "use-debounce": "^10.0.4",
108
109
  "uuid": "^13.0.0",
109
110
  "vaul": "^1.1.2",
@@ -1,6 +1,6 @@
1
- import { AuthGuard } from "@/modules/auth/components/guard";
1
+ import { AuthGuard } from "@/modules/auth/components/guard.client";
2
2
  import { PropsWithChildren } from "react";
3
- import { SidebarProvider } from "../entry.client";
3
+ import { SidebarProvider } from "../ui/sidebar.client";
4
4
 
5
5
  export function AdminLayout(props: PropsWithChildren) {
6
6
  return (
@@ -1,9 +1,17 @@
1
1
  import { NotFoundSection } from "./not-found-section";
2
2
 
3
+ export function AdminNotFoundPage() {
4
+ return (
5
+ <div className="relative z-0 grid h-[100dvh] w-full place-items-center">
6
+ <NotFoundSection href="/admin" />
7
+ </div>
8
+ );
9
+ }
10
+
3
11
  export function NotFoundPage() {
4
12
  return (
5
13
  <div className="relative z-0 grid h-[100dvh] w-full place-items-center">
6
- <NotFoundSection href="/" />
14
+ <NotFoundSection />
7
15
  </div>
8
16
  );
9
17
  }
@@ -4,7 +4,7 @@ import { HomeIcon } from "lucide-react";
4
4
  import type { Route } from "next";
5
5
  import Link from "next/link";
6
6
 
7
- export function NotFoundSection({ href }: { href: Route }) {
7
+ export function NotFoundSection({ href }: { href?: Route }) {
8
8
  return (
9
9
  <div className="flex flex-col items-center gap-12 text-center">
10
10
  <span className="text-foreground space-y-2">
@@ -12,10 +12,15 @@ export function NotFoundSection({ href }: { href: Route }) {
12
12
  <h1 className="text-2xl font-bold lg:text-3xl">Oeps, deze pagina is niet gevonden.</h1>
13
13
  </span>
14
14
 
15
- <Link href={href} className={cn(buttonVariants({ variant: "secondary" }), "text-foreground")}>
16
- <HomeIcon className="mr-2 size-4" />
17
- Terug naar home
18
- </Link>
15
+ {href && (
16
+ <Link
17
+ href={href}
18
+ className={cn(buttonVariants({ variant: "secondary" }), "text-foreground")}
19
+ >
20
+ <HomeIcon className="mr-2 size-4" />
21
+ Terug naar home
22
+ </Link>
23
+ )}
19
24
  </div>
20
25
  );
21
26
  }
@@ -2,7 +2,7 @@ import { Skeleton } from "@/components/ui/skeleton";
2
2
 
3
3
  export function AuthLoading() {
4
4
  return (
5
- <div className="flex flex-col gap-4">
5
+ <div className="mx-auto flex w-full flex-col gap-4 sm:w-[350px]">
6
6
  <Skeleton className="h-7 w-full" />
7
7
  <Skeleton className="h-48 w-full" />
8
8
  <Skeleton className="h-12 w-full" />
@@ -5,10 +5,10 @@ import { Button } from "@/components/ui/button";
5
5
  import { Form, FormControl, FormField, FormItem, FormMessage } from "@/components/ui/form.client";
6
6
  import { Input } from "@/components/ui/input";
7
7
  import { standardSchemaResolver } from "@hookform/resolvers/standard-schema";
8
+ import { useMutation, useQueryClient } from "@tanstack/react-query";
8
9
  import Link from "next/link";
9
10
  import { useRouter } from "next/navigation";
10
11
  import { parseAsString, useQueryState } from "nuqs";
11
- import React from "react";
12
12
  import { useForm } from "react-hook-form";
13
13
  import { toast } from "sonner";
14
14
  import * as z from "zod";
@@ -16,11 +16,50 @@ import { authClient } from "../handler/client.client";
16
16
  import { loginSchema } from "../lib/validators";
17
17
 
18
18
  export function LoginPage() {
19
+ const queryClient = useQueryClient();
19
20
  const [callbackURL] = useQueryState("callbackURL", parseAsString);
20
21
 
21
22
  const router = useRouter();
22
23
 
23
- const [isPending, startTransition] = React.useTransition();
24
+ const { mutate, isPending } = useMutation({
25
+ mutationFn: async (data: z.infer<typeof loginSchema>) => {
26
+ const result = await authClient.signIn.email(data);
27
+ if (result.error) throw result.error;
28
+
29
+ const session = await authClient.getSession();
30
+ if (session.error) throw session.error;
31
+
32
+ queryClient.setQueryData(["session"], session.data);
33
+
34
+ return result.data;
35
+ },
36
+ onSuccess: () => {
37
+ router.push(callbackURL ?? "/admin");
38
+ toast.success("Succesvol ingelogd");
39
+ },
40
+ onError: (err) => {
41
+ console.error("Login error: ", err);
42
+
43
+ if ("status" in err) {
44
+ if (err.status === 401) {
45
+ toast.error("Ongeldige email of wachtwoord");
46
+ return;
47
+ }
48
+
49
+ if (err.status === 403) {
50
+ toast.error("Account is geblokkeerd");
51
+ return;
52
+ }
53
+
54
+ if (err.status === 429) {
55
+ toast.error("Te veel login pogingen");
56
+ return;
57
+ }
58
+ }
59
+
60
+ toast.error("Er is iets misgegaan");
61
+ },
62
+ });
24
63
 
25
64
  const form = useForm<z.infer<typeof loginSchema>>({
26
65
  resolver: standardSchemaResolver(loginSchema),
@@ -38,39 +77,7 @@ export function LoginPage() {
38
77
  </div>
39
78
 
40
79
  <Form {...form}>
41
- <form
42
- className="space-y-6"
43
- onSubmit={form.handleSubmit((data) =>
44
- startTransition(async () => {
45
- await authClient.signIn.email(data, {
46
- onSuccess: () => {
47
- router.replace(callbackURL ?? "/");
48
- toast.success("Succesvol ingelogd");
49
- },
50
- onError: ({ error }) => {
51
- console.error("Login error: ", error);
52
-
53
- if (error.status === 401) {
54
- toast.error("Ongeldige email of wachtwoord");
55
- return;
56
- }
57
-
58
- if (error.status === 403) {
59
- toast.error("Account is geblokkeerd");
60
- return;
61
- }
62
-
63
- if (error.status === 429) {
64
- toast.error("Te veel login pogingen");
65
- return;
66
- }
67
-
68
- toast.error("Er is iets misgegaan");
69
- },
70
- });
71
- }),
72
- )}
73
- >
80
+ <form className="space-y-6" onSubmit={form.handleSubmit((data) => mutate(data))}>
74
81
  <div className="flex flex-col gap-3">
75
82
  <FormField
76
83
  control={form.control}
@@ -1,4 +1,4 @@
1
- export * from "./components/allowed.server";
2
1
  export * from "./components/auth-layout.server";
2
+ export * from "./handler/proxy.server";
3
3
  export * from "./handler/route.server";
4
4
  export * from "./lib/helpers.server";
@@ -0,0 +1,28 @@
1
+ import { getSessionCookie } from "better-auth/cookies";
2
+ import { NextRequest, NextResponse } from "next/server";
3
+ import { URLPattern } from "urlpattern-polyfill";
4
+ import { authCookiePrefix } from "./server.server";
5
+
6
+ /**
7
+ * Create auth proxy
8
+ */
9
+ export function createAuthProxy(props: { publicRoutes: string[] }) {
10
+ return (req: NextRequest) => {
11
+ // 1. Check if the current route is protected or public
12
+ const pathname = req.nextUrl.pathname;
13
+
14
+ const isPublicRoute = props.publicRoutes.some((route) =>
15
+ new URLPattern({ pathname: route }).test({ pathname }),
16
+ );
17
+
18
+ // 2. Check if a session cookie is present
19
+ const sessionCookie = getSessionCookie(req, { cookiePrefix: authCookiePrefix });
20
+
21
+ // 3. Redirect to /auth/login if the user is not authenticated
22
+ if (!isPublicRoute && !sessionCookie) {
23
+ return NextResponse.redirect(new URL("/auth/login", req.nextUrl));
24
+ }
25
+
26
+ return NextResponse.next();
27
+ };
28
+ }
@@ -10,6 +10,8 @@ import { nextCookies } from "better-auth/next-js";
10
10
  import { admin, emailOTP } from "better-auth/plugins";
11
11
  import { Resend } from "resend";
12
12
 
13
+ export const authCookiePrefix = "tulip";
14
+
13
15
  type CreateServerAuthParams<TSchema extends TDatabaseSchema> = Pick<
14
16
  TulipConfig<TSchema>,
15
17
  "email" | "auth"
@@ -23,6 +25,9 @@ export const createServerAuth = <TSchema extends TDatabaseSchema>(
23
25
  config: CreateServerAuthParams<TSchema>,
24
26
  ) =>
25
27
  betterAuth({
28
+ advanced: {
29
+ cookiePrefix: authCookiePrefix,
30
+ },
26
31
  database: drizzleAdapter(config.db, {
27
32
  provider: "pg",
28
33
  schema: config.schema,
@@ -5,7 +5,6 @@ import { GetTulipReturn } from "@/modules/config/lib/resolve.server";
5
5
  import { ServerError } from "@/modules/config/router/error.server";
6
6
  import { eq } from "drizzle-orm";
7
7
  import { headers } from "next/headers";
8
- import { redirect } from "next/navigation";
9
8
  import { users } from "../entry";
10
9
  import { CreateUserSchema, UpdateUserSchema } from "./validators";
11
10
 
@@ -15,10 +14,7 @@ import { CreateUserSchema, UpdateUserSchema } from "./validators";
15
14
  export async function getSession<TSchema extends TDatabaseSchema>({
16
15
  auth,
17
16
  }: Pick<GetTulipReturn<TSchema>, "auth">) {
18
- const session = await auth.api.getSession({ headers: await headers() });
19
- if (!session) redirect("/auth/login");
20
-
21
- return session;
17
+ return auth.api.getSession({ headers: await headers() });
22
18
  }
23
19
 
24
20
  /**
@@ -1,23 +0,0 @@
1
- import { Permission } from "../lib/permissions.js";
2
- import { TDatabaseSchema } from "../../config/db/types.js";
3
- import { TulipConfig } from "../../config/lib/config.server.js";
4
- import * as react_jsx_runtime190 from "react/jsx-runtime";
5
- import { JSX } from "react";
6
- import "server-cli-only";
7
-
8
- //#region src/modules/auth/components/allowed.server.d.ts
9
- type AllowedProps<TSchema extends TDatabaseSchema> = {
10
- config: TulipConfig<TSchema>;
11
- permission: Permission;
12
- fallback?: JSX.Element | string;
13
- children: React.ReactNode;
14
- };
15
- declare function Allowed<TSchema extends TDatabaseSchema>({
16
- config,
17
- permission,
18
- fallback,
19
- children
20
- }: AllowedProps<TSchema>): Promise<react_jsx_runtime190.JSX.Element>;
21
- //#endregion
22
- export { Allowed };
23
- //# sourceMappingURL=allowed.server.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"allowed.server.d.ts","names":[],"sources":["../../../../src/modules/auth/components/allowed.server.tsx"],"sourcesContent":[],"mappings":";;;;;;;;KASK,6BAA6B;UACxB,YAAY;cACR;EAFT,QAAA,CAAA,EAGQ,GAAA,CAAI,OAHA,GAAA,MAAA;EAAA,QAAA,EAIL,KAAA,CAAM,SAJD;;AACK,iBAMA,OANA,CAAA,gBAMwB,eANxB,CAAA,CAAA;EAAA,MAAA;EAAA,UAAA;EAAA,QAAA;EAAA;AAAA,CAAA,EAWnB,YAXmB,CAWN,OAXM,CAAA,CAAA,EAWE,OAXF,CAWE,oBAAA,CAAA,GAAA,CAAA,OAAA,CAXF"}
@@ -1,24 +0,0 @@
1
- import { getTulip } from "../../config/lib/resolve.server.js";
2
- import { getSession } from "../lib/helpers.server.js";
3
- import { Fragment, jsx } from "react/jsx-runtime";
4
- import "server-cli-only";
5
-
6
- //#region src/modules/auth/components/allowed.server.tsx
7
- async function Allowed({ config, permission, fallback, children }) {
8
- const { auth } = await getTulip({ config });
9
- const { user } = await getSession({ auth });
10
- const { success, error } = await auth.api.userHasPermission({ body: {
11
- userId: user.id,
12
- permission
13
- } });
14
- if (error) {
15
- console.error(error);
16
- return /* @__PURE__ */ jsx(Fragment, { children: fallback });
17
- }
18
- if (success) return /* @__PURE__ */ jsx(Fragment, { children });
19
- return /* @__PURE__ */ jsx(Fragment, { children: fallback });
20
- }
21
-
22
- //#endregion
23
- export { Allowed };
24
- //# sourceMappingURL=allowed.server.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"allowed.server.js","names":[],"sources":["../../../../src/modules/auth/components/allowed.server.tsx"],"sourcesContent":["import \"server-cli-only\";\n\nimport { type Permission } from \"@/modules/auth/lib/permissions\";\nimport { type TDatabaseSchema } from \"@/modules/config/db/types\";\nimport { TulipConfig } from \"@/modules/config/lib/config.server\";\nimport { getTulip } from \"@/modules/config/lib/resolve.server\";\nimport { JSX } from \"react\";\nimport { getSession } from \"../lib/helpers.server\";\n\ntype AllowedProps<TSchema extends TDatabaseSchema> = {\n config: TulipConfig<TSchema>;\n permission: Permission;\n fallback?: JSX.Element | string;\n children: React.ReactNode;\n};\n\nexport async function Allowed<TSchema extends TDatabaseSchema>({\n config,\n permission,\n fallback,\n children,\n}: AllowedProps<TSchema>) {\n const { auth } = await getTulip({ config });\n const { user } = await getSession({ auth });\n\n const { success, error } = await auth.api.userHasPermission({\n body: {\n userId: user.id,\n permission,\n },\n });\n\n if (error) {\n console.error(error);\n return <>{fallback}</>;\n }\n\n if (success) return <>{children}</>;\n\n return <>{fallback}</>;\n}\n"],"mappings":";;;;;;AAgBA,eAAsB,QAAyC,EAC7D,QACA,YACA,UACA,YACwB;CACxB,MAAM,EAAE,SAAS,MAAM,SAAS,EAAE,QAAQ,CAAC;CAC3C,MAAM,EAAE,SAAS,MAAM,WAAW,EAAE,MAAM,CAAC;CAE3C,MAAM,EAAE,SAAS,UAAU,MAAM,KAAK,IAAI,kBAAkB,EAC1D,MAAM;EACJ,QAAQ,KAAK;EACb;EACD,EACF,CAAC;AAEF,KAAI,OAAO;AACT,UAAQ,MAAM,MAAM;AACpB,SAAO,0CAAG,WAAY;;AAGxB,KAAI,QAAS,QAAO,gCAAG,WAAY;AAEnC,QAAO,0CAAG,WAAY"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"guard.js","names":[],"sources":["../../../../src/modules/auth/components/guard.tsx"],"sourcesContent":["\"use client\";\n\nimport { redirect } from \"next/navigation\";\nimport { PropsWithChildren } from \"react\";\nimport { useSession } from \"../hooks/use-session\";\n\nexport function AuthGuard({ children }: PropsWithChildren) {\n const session = useSession();\n if (!session.data) redirect(\"/auth/login\");\n\n return <>{children}</>;\n}\n"],"mappings":";;;;;;;;AAMA,SAAgB,UAAU,EAAE,YAA+B;AAEzD,KAAI,CADY,YAAY,CACf,KAAM,UAAS,cAAc;AAE1C,QAAO,gCAAG,WAAY"}
@@ -1,41 +0,0 @@
1
- import "server-cli-only";
2
-
3
- import { type Permission } from "@/modules/auth/lib/permissions";
4
- import { type TDatabaseSchema } from "@/modules/config/db/types";
5
- import { TulipConfig } from "@/modules/config/lib/config.server";
6
- import { getTulip } from "@/modules/config/lib/resolve.server";
7
- import { JSX } from "react";
8
- import { getSession } from "../lib/helpers.server";
9
-
10
- type AllowedProps<TSchema extends TDatabaseSchema> = {
11
- config: TulipConfig<TSchema>;
12
- permission: Permission;
13
- fallback?: JSX.Element | string;
14
- children: React.ReactNode;
15
- };
16
-
17
- export async function Allowed<TSchema extends TDatabaseSchema>({
18
- config,
19
- permission,
20
- fallback,
21
- children,
22
- }: AllowedProps<TSchema>) {
23
- const { auth } = await getTulip({ config });
24
- const { user } = await getSession({ auth });
25
-
26
- const { success, error } = await auth.api.userHasPermission({
27
- body: {
28
- userId: user.id,
29
- permission,
30
- },
31
- });
32
-
33
- if (error) {
34
- console.error(error);
35
- return <>{fallback}</>;
36
- }
37
-
38
- if (success) return <>{children}</>;
39
-
40
- return <>{fallback}</>;
41
- }