@softure-ai/auth 0.0.0-stage → 0.1.7

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 (255) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/LICENSE +21 -0
  3. package/README.md +490 -2
  4. package/dist/contract.d.ts +46 -0
  5. package/dist/contract.d.ts.map +1 -0
  6. package/dist/contract.js +2 -0
  7. package/dist/contract.js.map +1 -0
  8. package/dist/index.d.ts +194 -0
  9. package/dist/index.d.ts.map +1 -0
  10. package/dist/index.js +84 -0
  11. package/dist/index.js.map +1 -0
  12. package/dist/mailing/index.d.ts +2 -0
  13. package/dist/mailing/index.d.ts.map +1 -0
  14. package/dist/mailing/index.js +4 -0
  15. package/dist/mailing/index.js.map +1 -0
  16. package/dist/mailing/reset-mail.d.ts +27 -0
  17. package/dist/mailing/reset-mail.d.ts.map +1 -0
  18. package/dist/mailing/reset-mail.js +55 -0
  19. package/dist/mailing/reset-mail.js.map +1 -0
  20. package/dist/messages/en.d.ts +98 -0
  21. package/dist/messages/en.d.ts.map +1 -0
  22. package/dist/messages/en.js +93 -0
  23. package/dist/messages/en.js.map +1 -0
  24. package/dist/messages/index.d.ts +201 -0
  25. package/dist/messages/index.d.ts.map +1 -0
  26. package/dist/messages/index.js +11 -0
  27. package/dist/messages/index.js.map +1 -0
  28. package/dist/messages/pl.d.ts +3 -0
  29. package/dist/messages/pl.d.ts.map +1 -0
  30. package/dist/messages/pl.js +92 -0
  31. package/dist/messages/pl.js.map +1 -0
  32. package/dist/next/actions.d.ts +19 -0
  33. package/dist/next/actions.d.ts.map +1 -0
  34. package/dist/next/actions.js +231 -0
  35. package/dist/next/actions.js.map +1 -0
  36. package/dist/next/context.d.ts +4 -0
  37. package/dist/next/context.d.ts.map +1 -0
  38. package/dist/next/context.js +13 -0
  39. package/dist/next/context.js.map +1 -0
  40. package/dist/next/current-user.d.ts +34 -0
  41. package/dist/next/current-user.d.ts.map +1 -0
  42. package/dist/next/current-user.js +77 -0
  43. package/dist/next/current-user.js.map +1 -0
  44. package/dist/next/index.d.ts +8 -0
  45. package/dist/next/index.d.ts.map +1 -0
  46. package/dist/next/index.js +9 -0
  47. package/dist/next/index.js.map +1 -0
  48. package/dist/next/logout-button.d.ts +7 -0
  49. package/dist/next/logout-button.d.ts.map +1 -0
  50. package/dist/next/logout-button.js +12 -0
  51. package/dist/next/logout-button.js.map +1 -0
  52. package/dist/next/messages.d.ts +5 -0
  53. package/dist/next/messages.d.ts.map +1 -0
  54. package/dist/next/messages.js +7 -0
  55. package/dist/next/messages.js.map +1 -0
  56. package/dist/next/pages.d.ts +31 -0
  57. package/dist/next/pages.d.ts.map +1 -0
  58. package/dist/next/pages.js +118 -0
  59. package/dist/next/pages.js.map +1 -0
  60. package/dist/next/params.d.ts +3 -0
  61. package/dist/next/params.d.ts.map +1 -0
  62. package/dist/next/params.js +4 -0
  63. package/dist/next/params.js.map +1 -0
  64. package/dist/next/route.d.ts +3 -0
  65. package/dist/next/route.d.ts.map +1 -0
  66. package/dist/next/route.js +17 -0
  67. package/dist/next/route.js.map +1 -0
  68. package/dist/next/search-params.d.ts +5 -0
  69. package/dist/next/search-params.d.ts.map +1 -0
  70. package/dist/next/search-params.js +13 -0
  71. package/dist/next/search-params.js.map +1 -0
  72. package/dist/next/session-cookie.d.ts +11 -0
  73. package/dist/next/session-cookie.d.ts.map +1 -0
  74. package/dist/next/session-cookie.js +71 -0
  75. package/dist/next/session-cookie.js.map +1 -0
  76. package/dist/options.d.ts +72 -0
  77. package/dist/options.d.ts.map +1 -0
  78. package/dist/options.js +115 -0
  79. package/dist/options.js.map +1 -0
  80. package/dist/password-reset-sender.d.ts +21 -0
  81. package/dist/password-reset-sender.d.ts.map +1 -0
  82. package/dist/password-reset-sender.js +12 -0
  83. package/dist/password-reset-sender.js.map +1 -0
  84. package/dist/proxy/index.d.ts +14 -0
  85. package/dist/proxy/index.d.ts.map +1 -0
  86. package/dist/proxy/index.js +59 -0
  87. package/dist/proxy/index.js.map +1 -0
  88. package/dist/redirect-target.d.ts +7 -0
  89. package/dist/redirect-target.d.ts.map +1 -0
  90. package/dist/redirect-target.js +25 -0
  91. package/dist/redirect-target.js.map +1 -0
  92. package/dist/roles.d.ts +5 -0
  93. package/dist/roles.d.ts.map +1 -0
  94. package/dist/roles.js +6 -0
  95. package/dist/roles.js.map +1 -0
  96. package/dist/safe-next-path.d.ts +5 -0
  97. package/dist/safe-next-path.d.ts.map +1 -0
  98. package/dist/safe-next-path.js +25 -0
  99. package/dist/safe-next-path.js.map +1 -0
  100. package/dist/schema.d.ts +302 -0
  101. package/dist/schema.d.ts.map +1 -0
  102. package/dist/schema.js +37 -0
  103. package/dist/schema.js.map +1 -0
  104. package/dist/scripts/index.d.ts +3 -0
  105. package/dist/scripts/index.d.ts.map +1 -0
  106. package/dist/scripts/index.js +5 -0
  107. package/dist/scripts/index.js.map +1 -0
  108. package/dist/scripts/role-scripts.d.ts +15 -0
  109. package/dist/scripts/role-scripts.d.ts.map +1 -0
  110. package/dist/scripts/role-scripts.js +76 -0
  111. package/dist/scripts/role-scripts.js.map +1 -0
  112. package/dist/scripts/temporary-password.d.ts +12 -0
  113. package/dist/scripts/temporary-password.d.ts.map +1 -0
  114. package/dist/scripts/temporary-password.js +47 -0
  115. package/dist/scripts/temporary-password.js.map +1 -0
  116. package/dist/server/change-password.d.ts +14 -0
  117. package/dist/server/change-password.d.ts.map +1 -0
  118. package/dist/server/change-password.js +50 -0
  119. package/dist/server/change-password.js.map +1 -0
  120. package/dist/server/health.d.ts +3 -0
  121. package/dist/server/health.d.ts.map +1 -0
  122. package/dist/server/health.js +15 -0
  123. package/dist/server/health.js.map +1 -0
  124. package/dist/server/index.d.ts +12 -0
  125. package/dist/server/index.d.ts.map +1 -0
  126. package/dist/server/index.js +14 -0
  127. package/dist/server/index.js.map +1 -0
  128. package/dist/server/login.d.ts +14 -0
  129. package/dist/server/login.d.ts.map +1 -0
  130. package/dist/server/login.js +50 -0
  131. package/dist/server/login.js.map +1 -0
  132. package/dist/server/options.d.ts +19 -0
  133. package/dist/server/options.d.ts.map +1 -0
  134. package/dist/server/options.js +50 -0
  135. package/dist/server/options.js.map +1 -0
  136. package/dist/server/password-reset.d.ts +54 -0
  137. package/dist/server/password-reset.d.ts.map +1 -0
  138. package/dist/server/password-reset.js +134 -0
  139. package/dist/server/password-reset.js.map +1 -0
  140. package/dist/server/password.d.ts +25 -0
  141. package/dist/server/password.d.ts.map +1 -0
  142. package/dist/server/password.js +93 -0
  143. package/dist/server/password.js.map +1 -0
  144. package/dist/server/privacy.d.ts +33 -0
  145. package/dist/server/privacy.d.ts.map +1 -0
  146. package/dist/server/privacy.js +52 -0
  147. package/dist/server/privacy.js.map +1 -0
  148. package/dist/server/rate-limits.d.ts +22 -0
  149. package/dist/server/rate-limits.d.ts.map +1 -0
  150. package/dist/server/rate-limits.js +45 -0
  151. package/dist/server/rate-limits.js.map +1 -0
  152. package/dist/server/reauthenticate.d.ts +7 -0
  153. package/dist/server/reauthenticate.d.ts.map +1 -0
  154. package/dist/server/reauthenticate.js +16 -0
  155. package/dist/server/reauthenticate.js.map +1 -0
  156. package/dist/server/register.d.ts +23 -0
  157. package/dist/server/register.d.ts.map +1 -0
  158. package/dist/server/register.js +64 -0
  159. package/dist/server/register.js.map +1 -0
  160. package/dist/server/roles.d.ts +25 -0
  161. package/dist/server/roles.d.ts.map +1 -0
  162. package/dist/server/roles.js +56 -0
  163. package/dist/server/roles.js.map +1 -0
  164. package/dist/server/session-token.d.ts +12 -0
  165. package/dist/server/session-token.d.ts.map +1 -0
  166. package/dist/server/session-token.js +22 -0
  167. package/dist/server/session-token.js.map +1 -0
  168. package/dist/server/sessions.d.ts +24 -0
  169. package/dist/server/sessions.d.ts.map +1 -0
  170. package/dist/server/sessions.js +50 -0
  171. package/dist/server/sessions.js.map +1 -0
  172. package/dist/server/switches.d.ts +9 -0
  173. package/dist/server/switches.d.ts.map +1 -0
  174. package/dist/server/switches.js +34 -0
  175. package/dist/server/switches.js.map +1 -0
  176. package/dist/server/validation.d.ts +10 -0
  177. package/dist/server/validation.d.ts.map +1 -0
  178. package/dist/server/validation.js +32 -0
  179. package/dist/server/validation.js.map +1 -0
  180. package/dist/session-cookie.d.ts +14 -0
  181. package/dist/session-cookie.d.ts.map +1 -0
  182. package/dist/session-cookie.js +31 -0
  183. package/dist/session-cookie.js.map +1 -0
  184. package/dist/testing/account.d.ts +17 -0
  185. package/dist/testing/account.d.ts.map +1 -0
  186. package/dist/testing/account.js +31 -0
  187. package/dist/testing/account.js.map +1 -0
  188. package/dist/testing/index.d.ts +2 -0
  189. package/dist/testing/index.d.ts.map +1 -0
  190. package/dist/testing/index.js +4 -0
  191. package/dist/testing/index.js.map +1 -0
  192. package/dist/ui/auth-forms.d.ts +64 -0
  193. package/dist/ui/auth-forms.d.ts.map +1 -0
  194. package/dist/ui/auth-forms.js +67 -0
  195. package/dist/ui/auth-forms.js.map +1 -0
  196. package/dist/ui/index.d.ts +2 -0
  197. package/dist/ui/index.d.ts.map +1 -0
  198. package/dist/ui/index.js +4 -0
  199. package/dist/ui/index.js.map +1 -0
  200. package/migrations/0001_create_users_and_sessions.sql +25 -0
  201. package/migrations/0002_create_user_roles.sql +10 -0
  202. package/migrations/0003_create_password_resets.sql +15 -0
  203. package/migrations/0004_index_users_created_at.sql +5 -0
  204. package/module.json +34 -0
  205. package/package.json +97 -4
  206. package/src/contract.ts +67 -0
  207. package/src/index.ts +100 -0
  208. package/src/mailing/index.ts +3 -0
  209. package/src/mailing/reset-mail.ts +73 -0
  210. package/src/messages/en.ts +92 -0
  211. package/src/messages/index.ts +15 -0
  212. package/src/messages/pl.ts +93 -0
  213. package/src/next/actions.ts +240 -0
  214. package/src/next/context.ts +14 -0
  215. package/src/next/current-user.ts +90 -0
  216. package/src/next/index.ts +33 -0
  217. package/src/next/logout-button.tsx +22 -0
  218. package/src/next/messages.ts +9 -0
  219. package/src/next/next-modules.d.ts +16 -0
  220. package/src/next/pages.tsx +223 -0
  221. package/src/next/params.ts +4 -0
  222. package/src/next/route.ts +17 -0
  223. package/src/next/search-params.ts +14 -0
  224. package/src/next/session-cookie.ts +79 -0
  225. package/src/options.ts +154 -0
  226. package/src/password-reset-sender.ts +33 -0
  227. package/src/proxy/index.ts +85 -0
  228. package/src/redirect-target.ts +24 -0
  229. package/src/roles.ts +7 -0
  230. package/src/safe-next-path.ts +21 -0
  231. package/src/schema.ts +45 -0
  232. package/src/scripts/index.ts +8 -0
  233. package/src/scripts/role-scripts.ts +98 -0
  234. package/src/scripts/temporary-password.ts +62 -0
  235. package/src/server/change-password.ts +64 -0
  236. package/src/server/health.ts +16 -0
  237. package/src/server/index.ts +46 -0
  238. package/src/server/login.ts +61 -0
  239. package/src/server/options.ts +64 -0
  240. package/src/server/password-reset.ts +164 -0
  241. package/src/server/password.ts +108 -0
  242. package/src/server/privacy.ts +70 -0
  243. package/src/server/rate-limits.ts +51 -0
  244. package/src/server/reauthenticate.ts +16 -0
  245. package/src/server/register.ts +87 -0
  246. package/src/server/roles.ts +72 -0
  247. package/src/server/session-token.ts +25 -0
  248. package/src/server/sessions.ts +65 -0
  249. package/src/server/switches.ts +31 -0
  250. package/src/server/validation.ts +37 -0
  251. package/src/session-cookie.ts +47 -0
  252. package/src/testing/account.ts +43 -0
  253. package/src/testing/index.ts +3 -0
  254. package/src/ui/auth-forms.tsx +383 -0
  255. package/src/ui/index.ts +16 -0
@@ -0,0 +1,34 @@
1
+ import { type Err, type Ok } from "@softure-ai/core";
2
+ import type { AuthUser } from "../contract.js";
3
+ import { type PageSearchParams } from "./search-params.js";
4
+ /** The user of the request's session, or null. Database failures propagate to the error page. */
5
+ export declare const getCurrentUser: () => Promise<AuthUser | null>;
6
+ export interface RequireUserOptions {
7
+ /** Where to come back after login; a same-origin path. */
8
+ readonly next?: string;
9
+ /**
10
+ * A page's own search params (awaited), handed to the app's `rewriteRedirect` so the login URL
11
+ * can keep the page's channel tag. Without them the rewrite reads as for an action.
12
+ */
13
+ readonly searchParams?: PageSearchParams | undefined;
14
+ }
15
+ /**
16
+ * The signed-in user; without one, a redirect to the login page (with `next` when given), through
17
+ * the app's `rewriteRedirect`.
18
+ */
19
+ export declare function requireUser(options?: RequireUserOptions): Promise<AuthUser>;
20
+ /** The roles of the request's user; none without a session. */
21
+ export declare const getCurrentUserRoles: () => Promise<ReadonlySet<string>>;
22
+ /**
23
+ * For pages, layouts and route handlers: the signed-in user when they hold `role`; for anyone
24
+ * else, signed in or not, Next's "not found", so the surface does not reveal that it exists.
25
+ */
26
+ export declare function requireRole(role: string): Promise<AuthUser>;
27
+ /**
28
+ * For server actions: the signed-in user when they hold `role`, else `auth.forbidden` (also
29
+ * without a session), for the action to return to its form. Call it before reading any input.
30
+ */
31
+ export declare function authorizeRole(role: string): Promise<Ok<AuthUser> | Err<"auth.forbidden">>;
32
+ /** For UI decisions such as showing a link; never the access check itself. */
33
+ export declare function hasRole(role: string): Promise<boolean>;
34
+ //# sourceMappingURL=current-user.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"current-user.d.ts","sourceRoot":"","sources":["../../src/next/current-user.ts"],"names":[],"mappings":"AAGA,OAAO,EAAW,KAAK,GAAG,EAAE,KAAK,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAI9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAO/C,OAAO,EAAqB,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAG9E,iGAAiG;AACjG,eAAO,MAAM,cAAc,QAAmB,OAAO,CAAC,QAAQ,GAAG,IAAI,CAKnE,CAAC;AAEH,MAAM,WAAW,kBAAkB;IACjC,0DAA0D;IAC1D,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAC;CACtD;AAED;;;GAGG;AACH,wBAAsB,WAAW,CAAC,OAAO,GAAE,kBAAuB,GAAG,OAAO,CAAC,QAAQ,CAAC,CASrF;AAID,+DAA+D;AAC/D,eAAO,MAAM,mBAAmB,QAAmB,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAI5E,CAAC;AAUH;;;GAGG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAIjE;AAED;;;GAGG;AACH,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC,QAAQ,CAAC,GAAG,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAG/F;AAED,8EAA8E;AAC9E,wBAAsB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAE5D"}
@@ -0,0 +1,77 @@
1
+ // The signed-in user and their roles for server components, actions and route handlers. React's
2
+ // `cache` makes each one lookup per request, however many components ask; nothing is cached
3
+ // across requests, so a revoked role is gone on the next one.
4
+ import { err, ok } from "@softure-ai/core";
5
+ import { getSoftureConfig } from "@softure-ai/core/next";
6
+ import { notFound, redirect } from "next/navigation";
7
+ import { cache } from "react";
8
+ import { resolveRedirectTarget } from "../redirect-target.js";
9
+ import { toSafeNextPath } from "../safe-next-path.js";
10
+ import { getAuthRoutes } from "../server/options.js";
11
+ import { assertDeclaredRole, findUserRoles } from "../server/roles.js";
12
+ import { findSessionUser } from "../server/sessions.js";
13
+ import { getAuthContext } from "./context.js";
14
+ import { toUrlSearchParams } from "./search-params.js";
15
+ import { readSessionToken } from "./session-cookie.js";
16
+ /** The user of the request's session, or null. Database failures propagate to the error page. */
17
+ export const getCurrentUser = cache(async () => {
18
+ const config = getSoftureConfig();
19
+ const token = await readSessionToken(config);
20
+ if (token === null)
21
+ return null;
22
+ return findSessionUser(await getAuthContext(config), token);
23
+ });
24
+ /**
25
+ * The signed-in user; without one, a redirect to the login page (with `next` when given), through
26
+ * the app's `rewriteRedirect`.
27
+ */
28
+ export async function requireUser(options = {}) {
29
+ const user = await getCurrentUser();
30
+ if (user !== null)
31
+ return user;
32
+ const config = getSoftureConfig();
33
+ const login = getAuthRoutes(config).login;
34
+ const next = options.next === undefined ? null : toSafeNextPath(options.next, "");
35
+ const path = next === null || next === "" ? login : `${login}?next=${encodeURIComponent(next)}`;
36
+ const searchParams = options.searchParams === undefined ? undefined : toUrlSearchParams(options.searchParams);
37
+ redirect(await resolveRedirectTarget(config, path, searchParams));
38
+ }
39
+ const NO_ROLES = new Set();
40
+ /** The roles of the request's user; none without a session. */
41
+ export const getCurrentUserRoles = cache(async () => {
42
+ const user = await getCurrentUser();
43
+ if (user === null)
44
+ return NO_ROLES;
45
+ return findUserRoles(await getAuthContext(), user);
46
+ });
47
+ /** The signed-in user when they hold `role`, else null. Throws for an undeclared role. */
48
+ async function findUserWithRole(role) {
49
+ assertDeclaredRole(getSoftureConfig(), role);
50
+ const user = await getCurrentUser();
51
+ if (user === null)
52
+ return null;
53
+ return (await getCurrentUserRoles()).has(role) ? user : null;
54
+ }
55
+ /**
56
+ * For pages, layouts and route handlers: the signed-in user when they hold `role`; for anyone
57
+ * else, signed in or not, Next's "not found", so the surface does not reveal that it exists.
58
+ */
59
+ export async function requireRole(role) {
60
+ const user = await findUserWithRole(role);
61
+ if (user === null)
62
+ notFound();
63
+ return user;
64
+ }
65
+ /**
66
+ * For server actions: the signed-in user when they hold `role`, else `auth.forbidden` (also
67
+ * without a session), for the action to return to its form. Call it before reading any input.
68
+ */
69
+ export async function authorizeRole(role) {
70
+ const user = await findUserWithRole(role);
71
+ return user === null ? err("auth.forbidden") : ok(user);
72
+ }
73
+ /** For UI decisions such as showing a link; never the access check itself. */
74
+ export async function hasRole(role) {
75
+ return (await findUserWithRole(role)) !== null;
76
+ }
77
+ //# sourceMappingURL=current-user.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"current-user.js","sourceRoot":"","sources":["../../src/next/current-user.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,4FAA4F;AAC5F,8DAA8D;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AAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;AAC/D,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IAAY;IAC5C,MAAM,IAAI,GAAG,MAAM,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAC1C,IAAI,IAAI,KAAK,IAAI;QAAE,QAAQ,EAAE,CAAC;IAC9B,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,IAAY;IAC9C,MAAM,IAAI,GAAG,MAAM,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAC1C,OAAO,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;AAC1D,CAAC;AAED,8EAA8E;AAC9E,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,IAAY;IACxC,OAAO,CAAC,MAAM,gBAAgB,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC;AACjD,CAAC"}
@@ -0,0 +1,8 @@
1
+ export { changePasswordAction, forgotPasswordAction, loginAction, logoutAction, registerAction, resetPasswordAction, } from "./actions.js";
2
+ export { authorizeRole, getCurrentUser, getCurrentUserRoles, hasRole, requireRole, requireUser, type RequireUserOptions, } from "./current-user.js";
3
+ export { LogoutButton, type LogoutButtonProps } from "./logout-button.js";
4
+ export { getAuthMessages } from "./messages.js";
5
+ export { type AuthPageProps, ChangePasswordPage, createRegisterPage, ForgotPasswordPage, LoginPage, RegisterPage, type RegisterPageOptions, ResetPasswordPage, } from "./pages.js";
6
+ export { getSessionRoute } from "./route.js";
7
+ export type { PageSearchParams } from "./search-params.js";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/next/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,WAAW,EACX,YAAY,EACZ,cAAc,EACd,mBAAmB,GACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,OAAO,EACP,WAAW,EACX,WAAW,EACX,KAAK,kBAAkB,GACxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EACL,KAAK,aAAa,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,SAAS,EACT,YAAY,EACZ,KAAK,mBAAmB,EACxB,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,YAAY,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,9 @@
1
+ // The Next.js adapter of @softure-ai/auth: pages, server actions, the session route and the
2
+ // current-user and role helpers (docs/02-module-standard.md §8). The route guard is `@softure-ai/auth/proxy`.
3
+ export { changePasswordAction, forgotPasswordAction, loginAction, logoutAction, registerAction, resetPasswordAction, } from "./actions.js";
4
+ export { authorizeRole, getCurrentUser, getCurrentUserRoles, hasRole, requireRole, requireUser, } from "./current-user.js";
5
+ export { LogoutButton } from "./logout-button.js";
6
+ export { getAuthMessages } from "./messages.js";
7
+ export { ChangePasswordPage, createRegisterPage, ForgotPasswordPage, LoginPage, RegisterPage, ResetPasswordPage, } from "./pages.js";
8
+ export { getSessionRoute } from "./route.js";
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/next/index.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,8GAA8G;AAC9G,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,WAAW,EACX,YAAY,EACZ,cAAc,EACd,mBAAmB,GACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,OAAO,EACP,WAAW,EACX,WAAW,GAEZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAA0B,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAEL,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,SAAS,EACT,YAAY,EAEZ,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { type ButtonVariant } from "@softure-ai/ui";
2
+ export interface LogoutButtonProps {
3
+ readonly variant?: ButtonVariant;
4
+ readonly className?: string;
5
+ }
6
+ export declare function LogoutButton({ variant, className }: LogoutButtonProps): import("react").JSX.Element;
7
+ //# sourceMappingURL=logout-button.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logout-button.d.ts","sourceRoot":"","sources":["../../src/next/logout-button.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAU,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAI5D,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC;IACjC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,wBAAgB,YAAY,CAAC,EAAE,OAAqB,EAAE,SAAS,EAAE,EAAE,iBAAiB,+BASnF"}
@@ -0,0 +1,12 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ // A logout button for the app's own pages: a plain form posting to `logoutAction`, so it works
3
+ // without JavaScript. Server component.
4
+ import { getSoftureConfig } from "@softure-ai/core/next";
5
+ import { Button } from "@softure-ai/ui";
6
+ import { logoutAction } from "./actions.js";
7
+ import { getAuthMessages } from "./messages.js";
8
+ export function LogoutButton({ variant = "secondary", className }) {
9
+ const messages = getAuthMessages(getSoftureConfig());
10
+ return (_jsx("form", { action: logoutAction, className: className, children: _jsx(Button, { type: "submit", variant: variant, children: messages.logout.submit }) }));
11
+ }
12
+ //# sourceMappingURL=logout-button.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logout-button.js","sourceRoot":"","sources":["../../src/next/logout-button.tsx"],"names":[],"mappings":";AAAA,+FAA+F;AAC/F,wCAAwC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAsB,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAOhD,MAAM,UAAU,YAAY,CAAC,EAAE,OAAO,GAAG,WAAW,EAAE,SAAS,EAAqB;IAClF,MAAM,QAAQ,GAAG,eAAe,CAAC,gBAAgB,EAAE,CAAC,CAAC;IACrD,OAAO,CACL,eAAM,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,YAC9C,KAAC,MAAM,IAAC,IAAI,EAAC,QAAQ,EAAC,OAAO,EAAE,OAAO,YACnC,QAAQ,CAAC,MAAM,CAAC,MAAM,GAChB,GACJ,CACR,CAAC;AACJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { SoftureConfig } from "@softure-ai/core";
2
+ import type { AuthMessages } from "../messages/index.js";
3
+ /** The module's copy in the app's locale, with the app's overrides applied. */
4
+ export declare function getAuthMessages(config: SoftureConfig): AuthMessages;
5
+ //# sourceMappingURL=messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/next/messages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGzD,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,MAAM,EAAE,aAAa,GAAG,YAAY,CAGnE"}
@@ -0,0 +1,7 @@
1
+ import { getAuthModule } from "../server/options.js";
2
+ /** The module's copy in the app's locale, with the app's overrides applied. */
3
+ export function getAuthMessages(config) {
4
+ // The module factory merged the dictionaries; their shape is the module's own.
5
+ return getAuthModule(config).messages[config.locale];
6
+ }
7
+ //# sourceMappingURL=messages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/next/messages.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,+EAA+E;AAC/E,MAAM,UAAU,eAAe,CAAC,MAAqB;IACnD,+EAA+E;IAC/E,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAiB,CAAC;AACvE,CAAC"}
@@ -0,0 +1,31 @@
1
+ import type { ReactNode } from "react";
2
+ type SearchParams = Promise<Record<string, string | string[] | undefined>>;
3
+ export interface AuthPageProps {
4
+ readonly searchParams?: SearchParams;
5
+ }
6
+ export declare function LoginPage({ searchParams }: AuthPageProps): Promise<import("react").JSX.Element>;
7
+ export interface RegisterPageOptions {
8
+ /** The consent statement, e.g. with links to the terms and the privacy policy. */
9
+ readonly consentLabel?: ReactNode;
10
+ /** The app's own inputs, before the consent checkbox (`auth({ registrationFields })` declares their names). */
11
+ readonly extraFields?: ReactNode;
12
+ }
13
+ /**
14
+ * A register page with the app's consent label and extra inputs:
15
+ * `export default createRegisterPage({ consentLabel: <>I accept the <a href="/terms">terms</a></> })`.
16
+ * A declared registration field present in the page's URL (`?z=…`) is carried as a hidden input.
17
+ */
18
+ export declare function createRegisterPage(pageOptions?: RegisterPageOptions): ({ searchParams }: AuthPageProps) => Promise<import("react").JSX.Element>;
19
+ export declare function RegisterPage({ searchParams }: AuthPageProps): Promise<import("react").JSX.Element>;
20
+ export declare function ChangePasswordPage(): Promise<import("react").JSX.Element>;
21
+ /** Asks for a reset link. Not found when the app configured no sender. */
22
+ export declare function ForgotPasswordPage(): import("react").JSX.Element;
23
+ /**
24
+ * The page a reset link opens. It only checks the token (mail scanners open links too); the form
25
+ * submission consumes it. Its referrer policy is `same-origin`: the token in its URL never goes to
26
+ * another site, and the form still sends the Origin header Next checks on server actions
27
+ * (`no-referrer` would turn it into `null`, and Next would refuse the plain HTML form).
28
+ */
29
+ export declare function ResetPasswordPage({ searchParams }: AuthPageProps): Promise<import("react").JSX.Element>;
30
+ export {};
31
+ //# sourceMappingURL=pages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pages.d.ts","sourceRoot":"","sources":["../../src/next/pages.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAcvC,KAAK,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC;AAE3E,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC;CACtC;AAgCD,wBAAsB,SAAS,CAAC,EAAE,YAAY,EAAE,EAAE,aAAa,wCAoB9D;AAED,MAAM,WAAW,mBAAmB;IAClC,kFAAkF;IAClF,QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS,CAAC;IAClC,+GAA+G;IAC/G,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,CAAC;CAClC;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,GAAE,mBAAwB,IACxB,kBAAkB,aAAa,0CAG9E;AAED,wBAAsB,YAAY,CAAC,EAAE,YAAY,EAAE,EAAE,aAAa,wCAEjE;AAmDD,wBAAsB,kBAAkB,yCAevC;AAED,0EAA0E;AAC1E,wBAAgB,kBAAkB,gCAejC;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,EAAE,YAAY,EAAE,EAAE,aAAa,wCAgCtE"}
@@ -0,0 +1,118 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { getSoftureConfig } from "@softure-ai/core/next";
3
+ import { Card } from "@softure-ai/ui";
4
+ import { notFound, redirect } from "next/navigation";
5
+ import { resolveRedirectTarget } from "../redirect-target.js";
6
+ import { toSafeNextPath } from "../safe-next-path.js";
7
+ import { getAuthOptions, getAuthRoutes } from "../server/options.js";
8
+ import { findPasswordResetUser, isPasswordResetEnabled, RESET_TOKEN_PARAM } from "../server/password-reset.js";
9
+ import { isRegistrationClosed } from "../server/switches.js";
10
+ import { ChangePasswordForm, ForgotPasswordForm, LoginForm, RegisterForm, ResetPasswordForm } from "../ui/auth-forms.js";
11
+ import { changePasswordAction, forgotPasswordAction, loginAction, registerAction, resetPasswordAction } from "./actions.js";
12
+ import { getAuthContext } from "./context.js";
13
+ import { getCurrentUser, requireUser } from "./current-user.js";
14
+ import { getAuthMessages } from "./messages.js";
15
+ import { PASSWORD_RESET_DONE_PARAM } from "./params.js";
16
+ import { toUrlSearchParams } from "./search-params.js";
17
+ const LAYOUT_CLASS = "sft:mx-auto sft:box-border sft:w-full sft:sm:max-w-md sft:px-4 sft:py-4";
18
+ const FOOTER_CLASS = "sft:m-0 sft:text-sm sft:text-muted";
19
+ const LINK_CLASS = "sft:font-medium sft:text-accent";
20
+ /** The server keeps 512 characters of a registration field; nothing longer is echoed into the page. */
21
+ const MAX_CARRIED_LENGTH = 512;
22
+ function AuthLayout({ title, lead, children }) {
23
+ return (_jsx("main", { className: LAYOUT_CLASS, children: _jsx(Card, { title: title, subtitle: lead, children: children }) }));
24
+ }
25
+ async function readParam(searchParams, name) {
26
+ const value = (await searchParams)?.[name];
27
+ return Array.isArray(value) ? value[0] : value;
28
+ }
29
+ async function readNext(searchParams, fallback) {
30
+ return toSafeNextPath(await readParam(searchParams, "next"), fallback);
31
+ }
32
+ /** Sends a signed-in visitor on from the login or register page, through the app's redirect rewrite. */
33
+ async function redirectSignedIn(config, next, searchParams) {
34
+ redirect(await resolveRedirectTarget(config, next, toUrlSearchParams(await searchParams)));
35
+ }
36
+ export async function LoginPage({ searchParams }) {
37
+ const config = getSoftureConfig();
38
+ const routes = getAuthRoutes(config);
39
+ const next = await readNext(searchParams, routes.afterLogin);
40
+ if ((await getCurrentUser()) !== null)
41
+ await redirectSignedIn(config, next, searchParams);
42
+ const messages = getAuthMessages(config);
43
+ const isClosed = await isRegistrationClosed(await getAuthContext(config));
44
+ return (_jsx(AuthLayout, { title: messages.login.title, lead: messages.login.lead, children: _jsx(LoginForm, { action: loginAction, messages: messages, locale: config.locale, next: next, registerHref: isClosed ? undefined : routes.register, forgotPasswordHref: isPasswordResetEnabled(config) ? routes.forgotPassword : undefined, notice: (await readParam(searchParams, PASSWORD_RESET_DONE_PARAM)) === "1" ? messages.resetPassword.success : undefined }) }));
45
+ }
46
+ /**
47
+ * A register page with the app's consent label and extra inputs:
48
+ * `export default createRegisterPage({ consentLabel: <>I accept the <a href="/terms">terms</a></> })`.
49
+ * A declared registration field present in the page's URL (`?z=…`) is carried as a hidden input.
50
+ */
51
+ export function createRegisterPage(pageOptions = {}) {
52
+ return async function RegisterPageWithOptions({ searchParams }) {
53
+ return renderRegisterPage(searchParams, pageOptions);
54
+ };
55
+ }
56
+ export async function RegisterPage({ searchParams }) {
57
+ return renderRegisterPage(searchParams, {});
58
+ }
59
+ async function renderRegisterPage(searchParams, pageOptions) {
60
+ const config = getSoftureConfig();
61
+ const routes = getAuthRoutes(config);
62
+ const next = await readNext(searchParams, routes.afterLogin);
63
+ if ((await getCurrentUser()) !== null)
64
+ await redirectSignedIn(config, next, searchParams);
65
+ const messages = getAuthMessages(config);
66
+ if (await isRegistrationClosed(await getAuthContext(config))) {
67
+ return (_jsx(AuthLayout, { title: messages.register.closedTitle, lead: messages.register.closedBody, children: null }));
68
+ }
69
+ const options = getAuthOptions(config);
70
+ const carried = await readCarriedFields(searchParams, options.registrationFields);
71
+ return (_jsx(AuthLayout, { title: messages.register.title, lead: messages.register.lead, children: _jsx(RegisterForm, { action: registerAction, messages: messages, locale: config.locale, next: next, loginHref: routes.login, requireConsent: options.requireConsent, minPasswordLength: options.password.minLength, consentLabel: pageOptions.consentLabel, extraFields: _jsxs(_Fragment, { children: [carried.map(([name, value]) => (_jsx("input", { type: "hidden", name: name, value: value }, name))), pageOptions.extraFields] }) }) }));
72
+ }
73
+ /** The declared registration fields present in the page's URL, carried into the form as hidden inputs. */
74
+ async function readCarriedFields(searchParams, declared) {
75
+ const carried = [];
76
+ for (const name of declared) {
77
+ const value = await readParam(searchParams, name);
78
+ if (value !== undefined && value !== "")
79
+ carried.push([name, value.slice(0, MAX_CARRIED_LENGTH)]);
80
+ }
81
+ return carried;
82
+ }
83
+ export async function ChangePasswordPage() {
84
+ const config = getSoftureConfig();
85
+ const routes = getAuthRoutes(config);
86
+ await requireUser({ next: routes.changePassword });
87
+ const messages = getAuthMessages(config);
88
+ return (_jsx(AuthLayout, { title: messages.changePassword.title, lead: messages.changePassword.lead, children: _jsx(ChangePasswordForm, { action: changePasswordAction, messages: messages, locale: config.locale, minPasswordLength: getAuthOptions(config).password.minLength }) }));
89
+ }
90
+ /** Asks for a reset link. Not found when the app configured no sender. */
91
+ export function ForgotPasswordPage() {
92
+ const config = getSoftureConfig();
93
+ if (!isPasswordResetEnabled(config))
94
+ notFound();
95
+ const messages = getAuthMessages(config);
96
+ return (_jsx(AuthLayout, { title: messages.forgotPassword.title, lead: messages.forgotPassword.lead, children: _jsx(ForgotPasswordForm, { action: forgotPasswordAction, messages: messages, locale: config.locale, ttlMinutes: getAuthOptions(config).passwordReset.ttlMinutes, loginHref: getAuthRoutes(config).login }) }));
97
+ }
98
+ /**
99
+ * The page a reset link opens. It only checks the token (mail scanners open links too); the form
100
+ * submission consumes it. Its referrer policy is `same-origin`: the token in its URL never goes to
101
+ * another site, and the form still sends the Origin header Next checks on server actions
102
+ * (`no-referrer` would turn it into `null`, and Next would refuse the plain HTML form).
103
+ */
104
+ export async function ResetPasswordPage({ searchParams }) {
105
+ const config = getSoftureConfig();
106
+ if (!isPasswordResetEnabled(config))
107
+ notFound();
108
+ const routes = getAuthRoutes(config);
109
+ const messages = getAuthMessages(config);
110
+ const token = (await readParam(searchParams, RESET_TOKEN_PARAM)) ?? "";
111
+ const user = token === "" ? null : await findPasswordResetUser(await getAuthContext(config), token);
112
+ const referrerPolicy = _jsx("meta", { name: "referrer", content: "same-origin" });
113
+ if (user === null) {
114
+ return (_jsxs(AuthLayout, { title: messages.resetPassword.invalidTitle, lead: messages.resetPassword.invalidBody, children: [referrerPolicy, _jsx("p", { className: FOOTER_CLASS, children: _jsx("a", { href: routes.forgotPassword, className: LINK_CLASS, children: messages.resetPassword.requestNew }) })] }));
115
+ }
116
+ return (_jsxs(AuthLayout, { title: messages.resetPassword.title, lead: messages.resetPassword.lead, children: [referrerPolicy, _jsx(ResetPasswordForm, { action: resetPasswordAction, messages: messages, locale: config.locale, token: token, minPasswordLength: getAuthOptions(config).password.minLength })] }));
117
+ }
118
+ //# sourceMappingURL=pages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pages.js","sourceRoot":"","sources":["../../src/next/pages.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAC/G,O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QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,CAAC,MAAM,EACrB,KAAK,EAAE,KAAK,EACZ,iBAAiB,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,SAAS,GAC5D,IACS,CACd,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** Set on the login page after a password reset, so it confirms the change. */
2
+ export declare const PASSWORD_RESET_DONE_PARAM = "reset";
3
+ //# sourceMappingURL=params.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"params.d.ts","sourceRoot":"","sources":["../../src/next/params.ts"],"names":[],"mappings":"AAEA,+EAA+E;AAC/E,eAAO,MAAM,yBAAyB,UAAU,CAAC"}
@@ -0,0 +1,4 @@
1
+ // Query parameters the adapter's pages and actions pass between each other.
2
+ /** Set on the login page after a password reset, so it confirms the change. */
3
+ export const PASSWORD_RESET_DONE_PARAM = "reset";
4
+ //# sourceMappingURL=params.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"params.js","sourceRoot":"","sources":["../../src/next/params.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAE5E,+EAA+E;AAC/E,MAAM,CAAC,MAAM,yBAAyB,GAAG,OAAO,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** `{ user: { id, email } | null }` for the request's session. Never cached. */
2
+ export declare function getSessionRoute(): Promise<Response>;
3
+ //# sourceMappingURL=route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/next/route.ts"],"names":[],"mappings":"AAOA,gFAAgF;AAChF,wBAAsB,eAAe,IAAI,OAAO,CAAC,QAAQ,CAAC,CAQzD"}
@@ -0,0 +1,17 @@
1
+ // Route handlers. Mount with a rename, so later handlers of the module fit next to it:
2
+ // `export { getSessionRoute as GET } from "@softure-ai/auth/next"` in app/api/auth/session/route.ts.
3
+ import { errorLogLabel, safeError } from "@softure-ai/core";
4
+ import { getCurrentUser } from "./current-user.js";
5
+ const NO_STORE = { "cache-control": "no-store" };
6
+ /** `{ user: { id, email } | null }` for the request's session. Never cached. */
7
+ export async function getSessionRoute() {
8
+ try {
9
+ const user = await getCurrentUser();
10
+ return Response.json({ user: user === null ? null : { id: user.id, email: user.email } }, { headers: NO_STORE });
11
+ }
12
+ catch (error) {
13
+ console.error(`@softure-ai/auth: session lookup failed: ${errorLogLabel(error)}`);
14
+ return Response.json({ error: safeError(error).error }, { status: 500, headers: NO_STORE });
15
+ }
16
+ }
17
+ //# sourceMappingURL=route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.js","sourceRoot":"","sources":["../../src/next/route.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,qGAAqG;AACrG,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,MAAM,QAAQ,GAAG,EAAE,eAAe,EAAE,UAAU,EAAE,CAAC;AAEjD,gFAAgF;AAChF,MAAM,CAAC,KAAK,UAAU,eAAe;IACnC,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,cAAc,EAAE,CAAC;QACpC,OAAO,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC;IACnH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,4CAA4C,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAClF,OAAO,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC9F,CAAC;AACH,CAAC"}
@@ -0,0 +1,5 @@
1
+ /** A page's awaited `searchParams`, or any `URLSearchParams`. */
2
+ export type PageSearchParams = URLSearchParams | Readonly<Record<string, string | readonly string[] | undefined>>;
3
+ /** `searchParams` as `URLSearchParams`, every value of a repeated name kept. */
4
+ export declare function toUrlSearchParams(searchParams: PageSearchParams | undefined): URLSearchParams;
5
+ //# sourceMappingURL=search-params.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search-params.d.ts","sourceRoot":"","sources":["../../src/next/search-params.ts"],"names":[],"mappings":"AAEA,iEAAiE;AACjE,MAAM,MAAM,gBAAgB,GAAG,eAAe,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC;AAElH,gFAAgF;AAChF,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,gBAAgB,GAAG,SAAS,GAAG,eAAe,CAO7F"}
@@ -0,0 +1,13 @@
1
+ // A page's search params in the one shape auth's redirect rewrite takes.
2
+ /** `searchParams` as `URLSearchParams`, every value of a repeated name kept. */
3
+ export function toUrlSearchParams(searchParams) {
4
+ if (searchParams instanceof URLSearchParams)
5
+ return searchParams;
6
+ const query = new URLSearchParams();
7
+ for (const [name, value] of Object.entries(searchParams ?? {})) {
8
+ for (const item of typeof value === "string" ? [value] : (value ?? []))
9
+ query.append(name, item);
10
+ }
11
+ return query;
12
+ }
13
+ //# sourceMappingURL=search-params.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search-params.js","sourceRoot":"","sources":["../../src/next/search-params.ts"],"names":[],"mappings":"AAAA,yEAAyE;AAKzE,gFAAgF;AAChF,MAAM,UAAU,iBAAiB,CAAC,YAA0C;IAC1E,IAAI,YAAY,YAAY,eAAe;QAAE,OAAO,YAAY,CAAC;IACjE,MAAM,KAAK,GAAG,IAAI,eAAe,EAAE,CAAC;IACpC,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,IAAI,EAAE,CAAC,EAAE,CAAC;QAC/D,KAAK,MAAM,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;YAAE,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACnG,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { SoftureConfig } from "@softure-ai/core";
2
+ import type { NewSession } from "../contract.js";
3
+ /** The request's session token: the current cookie's, else the legacy session's (`legacySession`). */
4
+ export declare function readSessionToken(config: SoftureConfig): Promise<string | null>;
5
+ /** The legacy session cookie's token, or null (also without `legacySession`). */
6
+ export declare function readLegacySessionToken(config: SoftureConfig): Promise<string | null>;
7
+ /** Only in a server action or a route handler: pages cannot set cookies. */
8
+ export declare function writeSessionCookie(config: SoftureConfig, session: NewSession): Promise<void>;
9
+ /** Removes the cookie with the attributes it was set with, so the browser drops that one. */
10
+ export declare function clearSessionCookie(config: SoftureConfig): Promise<void>;
11
+ //# sourceMappingURL=session-cookie.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-cookie.d.ts","sourceRoot":"","sources":["../../src/next/session-cookie.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAWjD,sGAAsG;AACtG,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAGpF;AAED,iFAAiF;AACjF,wBAAsB,sBAAsB,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAG1F;AAyBD,4EAA4E;AAC5E,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAalG;AAED,6FAA6F;AAC7F,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAY7E"}
@@ -0,0 +1,71 @@
1
+ import { cookies } from "next/headers";
2
+ import { getAuthOptions } from "../server/options.js";
3
+ import { getSessionCookie } from "../session-cookie.js";
4
+ function readCookie(store, name) {
5
+ const value = store.get(name)?.value;
6
+ return value === undefined || value === "" ? null : value;
7
+ }
8
+ /** The request's session token: the current cookie's, else the legacy session's (`legacySession`). */
9
+ export async function readSessionToken(config) {
10
+ const store = await cookies();
11
+ return readCookie(store, getSessionCookie(config).name) ?? (await readLegacySessionToken(config));
12
+ }
13
+ /** The legacy session cookie's token, or null (also without `legacySession`). */
14
+ export async function readLegacySessionToken(config) {
15
+ const name = getAuthOptions(config).legacySession?.cookieName;
16
+ return name === undefined ? null : readCookie(await cookies(), name);
17
+ }
18
+ /**
19
+ * Removes the legacy cookie, if the app declared one: with `Path=/` and the configured domain, the
20
+ * only attributes the module knows. A legacy cookie set on another path or domain stays until it
21
+ * expires; its session row is ended anyway.
22
+ */
23
+ async function clearLegacySessionCookie(config) {
24
+ const name = getAuthOptions(config).legacySession?.cookieName;
25
+ if (name === undefined)
26
+ return;
27
+ const store = await cookies();
28
+ if (store.get(name) === undefined)
29
+ return;
30
+ const cookie = getSessionCookie(config);
31
+ // Browsers refuse a `__Host-` cookie with a Domain or without Secure, the removal included.
32
+ const isHostOnly = name.startsWith("__Host-");
33
+ store.set(name, "", {
34
+ httpOnly: true,
35
+ secure: isHostOnly || cookie.secure,
36
+ sameSite: cookie.sameSite,
37
+ path: "/",
38
+ domain: isHostOnly ? undefined : cookie.domain,
39
+ maxAge: 0,
40
+ });
41
+ }
42
+ /** Only in a server action or a route handler: pages cannot set cookies. */
43
+ export async function writeSessionCookie(config, session) {
44
+ const cookie = getSessionCookie(config);
45
+ const store = await cookies();
46
+ store.set(cookie.name, session.token, {
47
+ httpOnly: cookie.httpOnly,
48
+ secure: cookie.secure,
49
+ sameSite: cookie.sameSite,
50
+ path: cookie.path,
51
+ domain: cookie.domain,
52
+ maxAge: cookie.maxAgeSeconds,
53
+ });
54
+ // A new session replaces the legacy one: the browser keeps one cookie from here on.
55
+ await clearLegacySessionCookie(config);
56
+ }
57
+ /** Removes the cookie with the attributes it was set with, so the browser drops that one. */
58
+ export async function clearSessionCookie(config) {
59
+ const cookie = getSessionCookie(config);
60
+ const store = await cookies();
61
+ store.set(cookie.name, "", {
62
+ httpOnly: cookie.httpOnly,
63
+ secure: cookie.secure,
64
+ sameSite: cookie.sameSite,
65
+ path: cookie.path,
66
+ domain: cookie.domain,
67
+ maxAge: 0,
68
+ });
69
+ await clearLegacySessionCookie(config);
70
+ }
71
+ //# sourceMappingURL=session-cookie.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-cookie.js","sourceRoot":"","sources":["../../src/next/session-cookie.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAIxD,SAAS,UAAU,CAAC,KAAkB,EAAE,IAAY;IAClD,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC;IACrC,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;AAC5D,CAAC;AAED,sGAAsG;AACtG,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,MAAqB;IAC1D,MAAM,KAAK,GAAG,MAAM,OAAO,EAAE,CAAC;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