@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,33 @@
1
+ // The hook through which auth hands a password reset link to the app, which delivers it (a mail,
2
+ // e.g. through `mailingResetSender()` of `@softure-ai/auth/mailing`). Auth never sends anything itself.
3
+ import type { Locale } from "@softure-ai/core";
4
+ import type { AuthUser } from "./contract.js";
5
+
6
+ export interface PasswordResetDetails {
7
+ /** When the link stops working. */
8
+ readonly expiresAt: Date;
9
+ /** The app's locale, for the copy of the message. */
10
+ readonly locale: Locale;
11
+ }
12
+
13
+ /**
14
+ * Delivers a reset link to `user`. The link is built on `appOrigin` (never on the request's Host);
15
+ * a multi-host app keeps its path and query and swaps the origin. It runs after the response is
16
+ * sent, so a slow or failing sender never shows on the request page. A thrown error is logged
17
+ * without the link.
18
+ */
19
+ export type PasswordResetSender = (link: string, user: AuthUser, details: PasswordResetDetails) => Promise<void>;
20
+
21
+ /**
22
+ * A development sender that prints the link to the server console. It refuses to run in
23
+ * production, where a reset link in the logs would be a live credential in the logs.
24
+ */
25
+ export const consolePasswordResetSender: PasswordResetSender = (link, user, details) => {
26
+ if (process.env.NODE_ENV === "production") {
27
+ return Promise.reject(
28
+ new Error("@softure-ai/auth: consolePasswordResetSender is for development only; pass a real sender to auth({ passwordReset: { send } })"),
29
+ );
30
+ }
31
+ console.info(`@softure-ai/auth: password reset link for ${user.email}, valid until ${details.expiresAt.toISOString()}: ${link}`);
32
+ return Promise.resolve();
33
+ };
@@ -0,0 +1,85 @@
1
+ // The route guard for the app's `proxy.ts` (roadmap ID-3, unknown 1). It uses only Web `Request`
2
+ // and `Response`, imports nothing from Next and no React, so it chains with other proxy pieces:
3
+ // `return channels.carry(request, guard(request)) ?? channels.tag(request) ?? NextResponse.next()`
4
+ // (the channel piece of @softure-ai/analytics/proxy).
5
+ //
6
+ // It checks that the session cookie is present, nothing more: an optimistic check that keeps
7
+ // anonymous visitors off private pages without a database round trip in the proxy. Pages and
8
+ // actions still call `requireUser`, which reads the session row. An app that is private by default
9
+ // protects "/" and lists its public paths in `exclude`; auth's own public pages are never guarded.
10
+ import type { SoftureConfig } from "@softure-ai/core";
11
+ import { getAuthOptions, getAuthRoutes } from "../server/options.js";
12
+ import { getSessionCookie, readSessionToken } from "../session-cookie.js";
13
+
14
+ export interface AuthGuardOptions {
15
+ /** Path prefixes that need a session; each matches whole segments (`/account` → `/account/…`). */
16
+ readonly protect: readonly string[];
17
+ /**
18
+ * Path prefixes that never need one, checked before `protect` (e.g. `protect: ["/"]` with the
19
+ * public pages here). `"/"` here is the home page only. The change-password route stays guarded.
20
+ */
21
+ readonly exclude?: readonly string[];
22
+ }
23
+
24
+ /** Mounted at a fixed path by the module (manifest `mount`); it answers `{ user: null }` without a session. */
25
+ const SESSION_ROUTE = "/api/auth/session";
26
+
27
+ export type AuthGuard = (request: Request) => Response | null;
28
+
29
+ /** A guard that redirects to the login page (with `?next=`) for protected paths without a session cookie. */
30
+ export function createAuthGuard(config: SoftureConfig, options: AuthGuardOptions): AuthGuard {
31
+ const routes = getAuthRoutes(config);
32
+ const cookieNames = [getSessionCookie(config).name, getAuthOptions(config).legacySession?.cookieName].filter((name) => name !== undefined);
33
+ const prefixes = options.protect.map((prefix) => normalizePrefix(prefix, "protected"));
34
+ const changePassword = normalizePrefix(routes.changePassword, "protected");
35
+ // Auth's own public pages: guarding them would send a visitor from the login page to itself.
36
+ const publicPaths = [routes.login, routes.register, routes.forgotPassword, routes.resetPassword, SESSION_ROUTE].map((path) =>
37
+ normalizePrefix(path, "excluded"),
38
+ );
39
+ const excluded = (options.exclude ?? []).map((prefix) => normalizePrefix(prefix, "excluded"));
40
+
41
+ const isGuarded = (path: string): boolean => {
42
+ if (isUnder(path, changePassword)) return true;
43
+ if ([...publicPaths, ...excluded].some((prefix) => isExcludedBy(path, prefix))) return false;
44
+ return prefixes.some((prefix) => isUnder(path, prefix));
45
+ };
46
+
47
+ return (request) => {
48
+ const url = new URL(request.url);
49
+ // Compared decoded and lowercased, so `/%61ccount` or `/ACCOUNT` (which a case-insensitive
50
+ // front proxy may route to /account) is guarded too. Undecodable paths are guarded.
51
+ const path = decodePath(url.pathname);
52
+ if (path !== null && !isGuarded(path)) return null;
53
+ const cookieHeader = request.headers.get("cookie");
54
+ if (cookieNames.some((name) => readSessionToken(cookieHeader, name) !== null)) return null;
55
+ // Built on appOrigin: behind a proxy the request URL may carry an internal host.
56
+ const login = new URL(routes.login, config.appOrigin);
57
+ login.searchParams.set("next", `${url.pathname}${url.search}`);
58
+ return Response.redirect(login, 307);
59
+ };
60
+ }
61
+
62
+ function normalizePrefix(prefix: string, kind: "protected" | "excluded"): string {
63
+ if (!prefix.startsWith("/")) {
64
+ throw new Error(`createAuthGuard: ${kind} path "${prefix}" must start with /`);
65
+ }
66
+ const trimmed = prefix.length > 1 && prefix.endsWith("/") ? prefix.slice(0, -1) : prefix;
67
+ return trimmed.toLowerCase();
68
+ }
69
+
70
+ function decodePath(pathname: string): string | null {
71
+ try {
72
+ return decodeURIComponent(pathname).toLowerCase();
73
+ } catch {
74
+ return null;
75
+ }
76
+ }
77
+
78
+ /** An exclusion of "/" is the home page: excluding every path would switch the guard off. */
79
+ function isExcludedBy(pathname: string, prefix: string): boolean {
80
+ return prefix === "/" ? pathname === "/" : isUnder(pathname, prefix);
81
+ }
82
+
83
+ function isUnder(pathname: string, prefix: string): boolean {
84
+ return prefix === "/" || pathname === prefix || pathname.startsWith(`${prefix}/`);
85
+ }
@@ -0,0 +1,24 @@
1
+ // Where auth redirects, from an action or from a page's render. The app's `rewriteRedirect` option
2
+ // may change auth's path (e.g. analytics' `tagRedirect` keeps the channel tag), but its result must
3
+ // still be a path on this app, and a rewrite that fails never blocks the redirect: auth's own path
4
+ // is used instead.
5
+ import { errorLogLabel, type SoftureConfig } from "@softure-ai/core";
6
+ import type { RewriteRedirectContext } from "./options.js";
7
+ import { toSafeNextPath } from "./safe-next-path.js";
8
+ import { getAuthOptions } from "./server/options.js";
9
+
10
+ /**
11
+ * `path` as the app's `rewriteRedirect` returns it, or `path` itself without one or on failure.
12
+ * A page passes its own `searchParams`; an action passes none.
13
+ */
14
+ export async function resolveRedirectTarget(config: SoftureConfig, path: string, searchParams?: URLSearchParams): Promise<string> {
15
+ const { rewriteRedirect } = getAuthOptions(config);
16
+ if (rewriteRedirect === undefined) return path;
17
+ const ctx: RewriteRedirectContext = searchParams === undefined ? { config } : { config, searchParams };
18
+ try {
19
+ return toSafeNextPath(await rewriteRedirect(path, ctx), path);
20
+ } catch (error) {
21
+ console.error(`@softure-ai/auth: rewriting the redirect to ${path} failed: ${errorLogLabel(error)}`);
22
+ return path;
23
+ }
24
+ }
package/src/roles.ts ADDED
@@ -0,0 +1,7 @@
1
+ // Role names shared by the options, the server functions and the migration's CHECK constraint.
2
+
3
+ /** The role every app has: admin-only surfaces ask for it. */
4
+ export const ADMIN_ROLE = "admin";
5
+
6
+ /** What a role name looks like; `migrations/0002_create_user_roles.sql` enforces the same shape. */
7
+ export const ROLE_NAME_PATTERN = /^[a-z][a-z0-9_-]{0,31}$/;
@@ -0,0 +1,21 @@
1
+ // Where to go after login. `next` comes from the query string, so anyone can craft it: only a path
2
+ // on this app is accepted, never another origin (`//evil.example`, `/\evil.example`, `https://…`).
3
+ const BASE = "http://softure.invalid";
4
+ /** Room for an OAuth authorize URL (state, PKCE challenge, resource, scope) under common URL limits. */
5
+ export const MAX_NEXT_PATH_LENGTH = 8192;
6
+
7
+ /** `candidate` when it is a same-origin path, else `fallback`. A path over the cap is logged by length. */
8
+ export function toSafeNextPath(candidate: unknown, fallback: string): string {
9
+ if (typeof candidate !== "string") return fallback;
10
+ if (candidate.length > MAX_NEXT_PATH_LENGTH) {
11
+ // The length only: the path may carry tokens.
12
+ console.warn(`@softure-ai/auth: a next path of ${String(candidate.length)} characters is over the ${String(MAX_NEXT_PATH_LENGTH)} limit; using the fallback`);
13
+ return fallback;
14
+ }
15
+ if (!candidate.startsWith("/") || candidate.startsWith("//") || candidate.startsWith("/\\")) return fallback;
16
+ // eslint-disable-next-line no-control-regex -- control characters are exactly what is refused
17
+ if (/[\u0000-\u001f\u007f\\]/.test(candidate)) return fallback;
18
+ const url = new URL(candidate, BASE);
19
+ if (url.origin !== BASE) return fallback;
20
+ return `${url.pathname}${url.search}${url.hash}`;
21
+ }
package/src/schema.ts ADDED
@@ -0,0 +1,45 @@
1
+ // Drizzle view of the module's tables (migrations/0001_create_users_and_sessions.sql,
2
+ // 0002_create_user_roles.sql, 0003_create_password_resets.sql and the users.created_at index of
3
+ // 0004_index_users_created_at.sql). The migrations are the source of truth; this file only types
4
+ // the queries. App tables may reference `users.id`.
5
+ import { pgSchema, primaryKey, text, timestamp, uuid } from "drizzle-orm/pg-core";
6
+
7
+ export const authSchema = pgSchema("auth");
8
+
9
+ export const users = authSchema.table("users", {
10
+ id: uuid("id").primaryKey().defaultRandom(),
11
+ email: text("email").notNull().unique("users_email_key"),
12
+ passwordHash: text("password_hash").notNull(),
13
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
14
+ passwordChangedAt: timestamp("password_changed_at", { withTimezone: true }).notNull(),
15
+ });
16
+
17
+ export const sessions = authSchema.table("sessions", {
18
+ tokenHash: text("token_hash").primaryKey(),
19
+ userId: uuid("user_id")
20
+ .notNull()
21
+ .references(() => users.id, { onDelete: "cascade" }),
22
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
23
+ expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
24
+ });
25
+
26
+ export const userRoles = authSchema.table(
27
+ "user_roles",
28
+ {
29
+ userId: uuid("user_id")
30
+ .notNull()
31
+ .references(() => users.id, { onDelete: "cascade" }),
32
+ role: text("role").notNull(),
33
+ grantedAt: timestamp("granted_at", { withTimezone: true }).notNull(),
34
+ },
35
+ (table) => [primaryKey({ columns: [table.userId, table.role] })],
36
+ );
37
+
38
+ export const passwordResets = authSchema.table("password_resets", {
39
+ userId: uuid("user_id")
40
+ .primaryKey()
41
+ .references(() => users.id, { onDelete: "cascade" }),
42
+ tokenHash: text("token_hash").notNull().unique("password_resets_token_hash_key"),
43
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
44
+ expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
45
+ });
@@ -0,0 +1,8 @@
1
+ // `@softure-ai/auth/scripts`: ops scripts that grant and revoke roles and set a temporary password
2
+ // (see the README, "Roles" and "Account recovery").
3
+ export { createGrantRoleScript, createRevokeRoleScript, type RoleScriptArgs, type RoleScriptOptions } from "./role-scripts.js";
4
+ export {
5
+ createSetTemporaryPasswordScript,
6
+ type TemporaryPasswordScriptArgs,
7
+ type TemporaryPasswordScriptOptions,
8
+ } from "./temporary-password.js";
@@ -0,0 +1,98 @@
1
+ // The operator's way to grant and revoke roles: safe ops scripts (`@softure-ai/ops/scripts`), dry
2
+ // run by default, `--commit` writes. The app bundles them like its migrate step and runs them with
3
+ // its database URL. Reports carry the user id and roles, never the email.
4
+ import { ok, systemClock, type Clock, type SoftureConfig } from "@softure-ai/core";
5
+ import type { Queryable } from "@softure-ai/db";
6
+ import { defineOpsScript, refuseOpsScript, type OpsScript } from "@softure-ai/ops/scripts";
7
+ import { eq } from "drizzle-orm";
8
+ import { z } from "zod";
9
+ import { ADMIN_ROLE } from "../roles.js";
10
+ import { users } from "../schema.js";
11
+ import { getDeclaredRoles, findUserRoles, grantRole, isConfiguredAdmin, isDeclaredRole, revokeRole } from "../server/roles.js";
12
+ import type { AuthContext } from "../server/sessions.js";
13
+ import { normalizeEmail } from "../server/validation.js";
14
+
15
+ export interface RoleScriptArgs {
16
+ readonly email: string;
17
+ readonly role: string;
18
+ }
19
+
20
+ export interface RoleScriptOptions {
21
+ /** The time stored as `granted_at`; the system clock by default. */
22
+ readonly clock?: Clock;
23
+ }
24
+
25
+ const roleScriptArgs = z.strictObject({
26
+ email: z.string().min(1, "--email=<account email> is required"),
27
+ role: z.string().min(1, "--role=<role> is required"),
28
+ });
29
+
30
+ const USAGE = ["--email=<account email>", "--role=<declared role, e.g. admin>"];
31
+
32
+ interface Account {
33
+ readonly id: string;
34
+ readonly email: string;
35
+ }
36
+
37
+ async function findAccount(db: Queryable, email: string): Promise<Account | undefined> {
38
+ const [row] = await db.select({ id: users.id, email: users.email }).from(users).where(eq(users.email, normalizeEmail(email))).limit(1);
39
+ return row;
40
+ }
41
+
42
+ async function describeRoles(ctx: AuthContext, account: Account): Promise<{ userId: string; roles: string[] }> {
43
+ return { userId: account.id, roles: [...(await findUserRoles(ctx, account))].sort() };
44
+ }
45
+
46
+ function describeDeclared(config: SoftureConfig): string {
47
+ return [...getDeclaredRoles(config)].join(", ");
48
+ }
49
+
50
+ /** `grant-role --email=… --role=…`: stores a declared role for one account. */
51
+ export function createGrantRoleScript(config: SoftureConfig, options: RoleScriptOptions = {}): OpsScript<RoleScriptArgs> {
52
+ const clock = options.clock ?? systemClock;
53
+ return defineOpsScript({
54
+ name: "grant-role",
55
+ description: "Grants a declared role to the account with the given email.",
56
+ usage: USAGE,
57
+ args: roleScriptArgs,
58
+ run: async (tx, args) => {
59
+ const ctx: AuthContext = { db: tx, clock, config };
60
+ if (!isDeclaredRole(config, args.role)) {
61
+ return refuseOpsScript(`role "${args.role}" is not declared (declared: ${describeDeclared(config)})`);
62
+ }
63
+ const account = await findAccount(tx, args.email);
64
+ if (account === undefined) return refuseOpsScript("no account has this email");
65
+ const before = await describeRoles(ctx, account);
66
+ const granted = await grantRole(ctx, { userId: account.id, role: args.role });
67
+ if (!granted.ok) return refuseOpsScript(`the account already has role "${args.role}"`);
68
+ return ok({ before, after: await describeRoles(ctx, account) });
69
+ },
70
+ });
71
+ }
72
+
73
+ /** `revoke-role --email=… --role=…`: deletes a stored role of one account. */
74
+ export function createRevokeRoleScript(config: SoftureConfig, options: RoleScriptOptions = {}): OpsScript<RoleScriptArgs> {
75
+ const clock = options.clock ?? systemClock;
76
+ return defineOpsScript({
77
+ name: "revoke-role",
78
+ description: "Revokes a stored role from the account with the given email.",
79
+ usage: USAGE,
80
+ args: roleScriptArgs,
81
+ run: async (tx, args) => {
82
+ const ctx: AuthContext = { db: tx, clock, config };
83
+ const account = await findAccount(tx, args.email);
84
+ if (account === undefined) return refuseOpsScript("no account has this email");
85
+ const before = await describeRoles(ctx, account);
86
+ const revoked = await revokeRole(ctx, { userId: account.id, role: args.role });
87
+ if (!revoked.ok) {
88
+ const isFromConfig = args.role === ADMIN_ROLE && isConfiguredAdmin(config, account);
89
+ return refuseOpsScript(
90
+ isFromConfig
91
+ ? "admin comes from auth({ adminEmails }) in softure.config.ts; remove the email there"
92
+ : `the account has no stored role "${args.role}"`,
93
+ );
94
+ }
95
+ return ok({ before, after: await describeRoles(ctx, account) });
96
+ },
97
+ });
98
+ }
@@ -0,0 +1,62 @@
1
+ // The operator's account recovery: a safe ops script (`@softure-ai/ops/scripts`), dry run by
2
+ // default, `--commit` writes. It sets a random password, ends every session of the account and its
3
+ // pending reset link, and prints the password once for the operator to hand over through a channel
4
+ // that proves the owner (a reply to the account's own address). Reports carry the user id, never the email.
5
+ import { randomBytes } from "node:crypto";
6
+ import { ok, systemClock, type Clock, type SoftureConfig } from "@softure-ai/core";
7
+ import { defineOpsScript, refuseOpsScript, type OpsScript } from "@softure-ai/ops/scripts";
8
+ import { eq } from "drizzle-orm";
9
+ import { z } from "zod";
10
+ import { passwordResets, sessions, users } from "../schema.js";
11
+ import { getAuthOptions } from "../server/options.js";
12
+ import { hashPassword } from "../server/password.js";
13
+ import { revokeUserSessions, type AuthContext } from "../server/sessions.js";
14
+ import { normalizeEmail } from "../server/validation.js";
15
+
16
+ /** Long enough to be out of guessing range in any rate limit window. */
17
+ const MIN_TEMPORARY_LENGTH = 20;
18
+
19
+ export interface TemporaryPasswordScriptArgs {
20
+ readonly email: string;
21
+ }
22
+
23
+ export interface TemporaryPasswordScriptOptions {
24
+ /** The time stored as `password_changed_at`; the system clock by default. */
25
+ readonly clock?: Clock;
26
+ }
27
+
28
+ const scriptArgs = z.strictObject({ email: z.string().min(1, "--email=<account email> is required") });
29
+
30
+ /** A random password of `length` base64url characters. */
31
+ function createTemporaryPassword(length: number): string {
32
+ return randomBytes(Math.ceil((length * 3) / 4)).toString("base64url").slice(0, length);
33
+ }
34
+
35
+ /** `set-temporary-password --email=…`: a new random password, every session and reset link ended. */
36
+ export function createSetTemporaryPasswordScript(
37
+ config: SoftureConfig,
38
+ options: TemporaryPasswordScriptOptions = {},
39
+ ): OpsScript<TemporaryPasswordScriptArgs> {
40
+ const clock = options.clock ?? systemClock;
41
+ return defineOpsScript({
42
+ name: "set-temporary-password",
43
+ description: "Sets a random password for the account with the given email and ends its sessions and reset link.",
44
+ usage: ["--email=<account email>"],
45
+ args: scriptArgs,
46
+ run: async (tx, args) => {
47
+ const ctx: AuthContext = { db: tx, clock, config };
48
+ const [account] = await tx.select({ id: users.id }).from(users).where(eq(users.email, normalizeEmail(args.email))).limit(1);
49
+ if (account === undefined) return refuseOpsScript("no account has this email");
50
+ const before = { userId: account.id, sessions: (await tx.select().from(sessions).where(eq(sessions.userId, account.id))).length };
51
+
52
+ const authOptions = getAuthOptions(config);
53
+ const temporaryPassword = createTemporaryPassword(Math.max(authOptions.password.minLength, MIN_TEMPORARY_LENGTH));
54
+ const passwordHash = await hashPassword(temporaryPassword, authOptions.password.scrypt);
55
+ await tx.update(users).set({ passwordHash, passwordChangedAt: clock.now() }).where(eq(users.id, account.id));
56
+ await revokeUserSessions(ctx, account.id);
57
+ await tx.delete(passwordResets).where(eq(passwordResets.userId, account.id));
58
+ const remaining = (await tx.select().from(sessions).where(eq(sessions.userId, account.id))).length;
59
+ return ok({ before, after: { userId: account.id, sessions: remaining, temporaryPassword } });
60
+ },
61
+ });
62
+ }
@@ -0,0 +1,64 @@
1
+ // Password change for a signed-in user. The new password must differ from the current one. The new hash, the end of every other session of the user
2
+ // and of a pending reset link happen in one transaction; the session that made the change stays signed in.
3
+ import { err, ok, type Err, type Ok } from "@softure-ai/core";
4
+ import type { RateLimitRejection } from "@softure-ai/security";
5
+ import { consumeRateLimit } from "@softure-ai/security/server";
6
+ import { and, eq, ne } from "drizzle-orm";
7
+ import { passwordResets, sessions, users } from "../schema.js";
8
+ import { getAuthOptions } from "./options.js";
9
+ import { hashPassword, verifyPassword } from "./password.js";
10
+ import { assertAuthBuckets, BUCKETS, userSubjectKey } from "./rate-limits.js";
11
+ import { findSessionUser, type AuthContext } from "./sessions.js";
12
+ import { hashSessionToken } from "./session-token.js";
13
+ import { checkNewPassword } from "./validation.js";
14
+
15
+ export interface ChangePasswordInput {
16
+ /** The token of the session making the change; it stays valid. */
17
+ readonly sessionToken: string;
18
+ readonly currentPassword: string;
19
+ readonly newPassword: string;
20
+ }
21
+
22
+ export type ChangePasswordErrorCode =
23
+ | "auth.unauthenticated"
24
+ | "auth.current_password_invalid"
25
+ | "auth.password_unchanged"
26
+ | "auth.password_too_short"
27
+ | "auth.password_too_long";
28
+
29
+ export type ChangePasswordResult = Ok<undefined> | Err<ChangePasswordErrorCode> | RateLimitRejection;
30
+
31
+ /** Changes the password of the session's user and ends their other sessions. Database errors propagate. */
32
+ export async function changePassword(ctx: AuthContext, input: ChangePasswordInput): Promise<ChangePasswordResult> {
33
+ const options = getAuthOptions(ctx.config);
34
+ assertAuthBuckets(ctx.config);
35
+ const user = await findSessionUser(ctx, input.sessionToken);
36
+ if (user === null) return err("auth.unauthenticated");
37
+
38
+ const limit = await consumeRateLimit(ctx, { bucket: BUCKETS.changePassword, key: userSubjectKey(user.id) });
39
+ if (!limit.ok) return limit;
40
+
41
+ const policy = checkNewPassword(input.newPassword, options.password.minLength);
42
+ if (!policy.ok) return policy;
43
+
44
+ const [stored] = await ctx.db.select({ passwordHash: users.passwordHash }).from(users).where(eq(users.id, user.id)).limit(1);
45
+ if (stored === undefined) return err("auth.unauthenticated");
46
+ if (!(await verifyPassword(input.currentPassword, stored.passwordHash))) return err("auth.current_password_invalid");
47
+ // Compared in NFC, as the hash is: another Unicode form of the same password is the same password.
48
+ if (input.newPassword.normalize("NFC") === input.currentPassword.normalize("NFC")) return err("auth.password_unchanged");
49
+
50
+ const passwordHash = await hashPassword(input.newPassword, options.password.scrypt);
51
+ return ctx.db.transaction(async (tx): Promise<ChangePasswordResult> => {
52
+ // Conditional on the hash just verified: two parallel changes cannot both win.
53
+ const updated = await tx
54
+ .update(users)
55
+ .set({ passwordHash, passwordChangedAt: ctx.clock.now() })
56
+ .where(and(eq(users.id, user.id), eq(users.passwordHash, stored.passwordHash)))
57
+ .returning();
58
+ if (updated.length === 0) return err("auth.current_password_invalid");
59
+ await tx.delete(sessions).where(and(eq(sessions.userId, user.id), ne(sessions.tokenHash, hashSessionToken(input.sessionToken))));
60
+ // A reset link requested before the change must not outlive it.
61
+ await tx.delete(passwordResets).where(eq(passwordResets.userId, user.id));
62
+ return ok();
63
+ });
64
+ }
@@ -0,0 +1,16 @@
1
+ // auth's readiness probe for `GET /api/health` of `@softure-ai/ops` (core's `defineModule({ health })`):
2
+ // auth can serve only when all of its tables exist and answer, i.e. after `softure migrate`. It
3
+ // reads no rows, so it stays cheap and runs as the row-limited app role.
4
+ import { ok, type HealthCheck } from "@softure-ai/core";
5
+ import type { Queryable } from "@softure-ai/db";
6
+ import { sql } from "drizzle-orm";
7
+
8
+ export const checkAuthTables: HealthCheck = async (context) => {
9
+ // Core types `db` as unknown; the health route passes the @softure-ai/db handle.
10
+ const db = context.db as Queryable;
11
+ await db.execute(sql`select 1 from auth.users limit 0`);
12
+ await db.execute(sql`select 1 from auth.sessions limit 0`);
13
+ await db.execute(sql`select 1 from auth.user_roles limit 0`);
14
+ await db.execute(sql`select 1 from auth.password_resets limit 0`);
15
+ return ok();
16
+ };
@@ -0,0 +1,46 @@
1
+ // Server-only API of @softure-ai/auth. Every function receives the module context
2
+ // (`{ db, clock, config }`) and never reads request scope; tokens and client keys come in as values.
3
+ export { changePassword, type ChangePasswordErrorCode, type ChangePasswordInput, type ChangePasswordResult } from "./change-password.js";
4
+ export { loginUser, type LoginInput, type LoginResult } from "./login.js";
5
+ export { getAuthOptions, getAuthRoutes, type AuthRoutes } from "./options.js";
6
+ export { hashPassword, matchPassword, MAX_PASSWORD_LENGTH, needsRehash, verifyPassword, type PasswordMatch } from "./password.js";
7
+ export {
8
+ deliverPasswordReset,
9
+ findPasswordResetUser,
10
+ getPasswordResetLink,
11
+ isPasswordResetEnabled,
12
+ issuePasswordReset,
13
+ prunePasswordResets,
14
+ requestPasswordReset,
15
+ resetPassword,
16
+ RESET_TOKEN_PARAM,
17
+ type PasswordResetRequestInput,
18
+ type PasswordResetRequestResult,
19
+ type ResetPasswordErrorCode,
20
+ type ResetPasswordInput,
21
+ type ResetPasswordResult,
22
+ } from "./password-reset.js";
23
+ export {
24
+ assertDeclaredRole,
25
+ findUserRoles,
26
+ getDeclaredRoles,
27
+ grantRole,
28
+ isConfiguredAdmin,
29
+ isDeclaredRole,
30
+ revokeRole,
31
+ type RoleChange,
32
+ type RoleErrorCode,
33
+ } from "./roles.js";
34
+ export { authPrivacyContributor, deleteAuthUserData, exportAuthUserData, type AuthUserData } from "./privacy.js";
35
+ export { isCurrentPassword } from "./reauthenticate.js";
36
+ export { registerUser, type RegisterErrorCode, type RegisterInput, type RegisterResult } from "./register.js";
37
+ export {
38
+ createSession,
39
+ findSessionUser,
40
+ logoutSession,
41
+ pruneSessions,
42
+ revokeUserSessions,
43
+ type AuthContext,
44
+ type RevokeUserSessionsOptions,
45
+ } from "./sessions.js";
46
+ export { isRegistrationClosed } from "./switches.js";
@@ -0,0 +1,61 @@
1
+ // Login. Both buckets are counted before anything else: `login` per client address stops a flood,
2
+ // `login-account` per email stops a distributed attack on one account. An unknown email takes as
3
+ // long as a wrong password (a dummy verification) and fails with the same code.
4
+ import { err, ok, type Err, type Ok } from "@softure-ai/core";
5
+ import type { RateLimitRejection } from "@softure-ai/security";
6
+ import { consumeRateLimit, resetRateLimit } from "@softure-ai/security/server";
7
+ import { and, eq } from "drizzle-orm";
8
+ import type { SignedIn } from "../contract.js";
9
+ import { users } from "../schema.js";
10
+ import { getAuthOptions } from "./options.js";
11
+ import { hashPassword, matchPassword, MAX_PASSWORD_LENGTH, needsRehash, verifyDummyPassword } from "./password.js";
12
+ import { assertAuthBuckets, BUCKETS, emailSubjectKey } from "./rate-limits.js";
13
+ import { createSession, deleteExpiredSessions, type AuthContext } from "./sessions.js";
14
+ import { getPasswordLength, normalizeEmail } from "./validation.js";
15
+
16
+ export interface LoginInput {
17
+ readonly email: string;
18
+ readonly password: string;
19
+ /** The client's rate limit key (`identifyClient`). */
20
+ readonly clientKey: string;
21
+ }
22
+
23
+ export type LoginResult = Ok<SignedIn> | Err<"auth.invalid_credentials"> | RateLimitRejection;
24
+
25
+ /** Checks the credentials and opens a session. Database errors propagate. */
26
+ export async function loginUser(ctx: AuthContext, input: LoginInput): Promise<LoginResult> {
27
+ const options = getAuthOptions(ctx.config);
28
+ assertAuthBuckets(ctx.config);
29
+ const byClient = await consumeRateLimit(ctx, { bucket: BUCKETS.login, key: input.clientKey });
30
+ if (!byClient.ok) return byClient;
31
+
32
+ const email = normalizeEmail(input.email);
33
+ if (email === "" || input.password === "" || getPasswordLength(input.password) > MAX_PASSWORD_LENGTH) {
34
+ return err("auth.invalid_credentials");
35
+ }
36
+ const accountKey = emailSubjectKey(email);
37
+ const byAccount = await consumeRateLimit(ctx, { bucket: BUCKETS.loginAccount, key: accountKey });
38
+ if (!byAccount.ok) return byAccount;
39
+
40
+ const [user] = await ctx.db.select().from(users).where(eq(users.email, email)).limit(1);
41
+ if (user === undefined) {
42
+ await verifyDummyPassword(input.password, options.password.scrypt);
43
+ return err("auth.invalid_credentials");
44
+ }
45
+ const match = await matchPassword(input.password, user.passwordHash);
46
+ if (match === "mismatch") return err("auth.invalid_credentials");
47
+
48
+ await resetRateLimit(ctx, { bucket: BUCKETS.loginAccount, key: accountKey });
49
+ await deleteExpiredSessions(ctx, user.id);
50
+ // A legacy match (raw, non-NFC input) is rehashed too, so the stored hash is of the NFC form.
51
+ if (match === "legacy" || needsRehash(user.passwordHash, options.password.scrypt)) {
52
+ const passwordHash = await hashPassword(input.password, options.password.scrypt);
53
+ // Conditional: a password changed meanwhile is not overwritten with the old one.
54
+ await ctx.db
55
+ .update(users)
56
+ .set({ passwordHash })
57
+ .where(and(eq(users.id, user.id), eq(users.passwordHash, user.passwordHash)));
58
+ }
59
+ const session = await createSession(ctx, user.id);
60
+ return ok({ user: { id: user.id, email: user.email, createdAt: user.createdAt }, session });
61
+ }
@@ -0,0 +1,64 @@
1
+ // The auth options of the running app, read from the configuration in the module context.
2
+ import { getModule, type SoftureConfig } from "@softure-ai/core";
3
+ import type { AuthOptions } from "../options.js";
4
+
5
+ const MODULE_ID = "auth";
6
+
7
+ /** The enabled auth module. Throws when the app did not enable it: calling its functions then is a bug. */
8
+ export function getAuthModule(config: SoftureConfig) {
9
+ const module = getModule(config, MODULE_ID);
10
+ if (module === undefined) {
11
+ throw new Error("@softure-ai/auth: the module is not enabled; add auth({ ... }) to modules in softure.config.ts");
12
+ }
13
+ return module;
14
+ }
15
+
16
+ export function getAuthOptions(config: SoftureConfig): AuthOptions {
17
+ // The module factory parsed these options with authOptionsSchema.
18
+ return getAuthModule(config).options as AuthOptions;
19
+ }
20
+
21
+ const anchoredPatterns = new WeakMap<RegExp, RegExp>();
22
+
23
+ /** `legacySession.tokenPattern` anchored to the whole token, or undefined without a legacy session. */
24
+ export function getLegacyTokenPattern(config: SoftureConfig): RegExp | undefined {
25
+ const pattern = getAuthOptions(config).legacySession?.tokenPattern;
26
+ if (pattern === undefined) return undefined;
27
+ let anchored = anchoredPatterns.get(pattern);
28
+ if (anchored === undefined) {
29
+ // The schema refused the g and y flags, so `test` keeps no state between calls.
30
+ anchored = new RegExp(`^(?:${pattern.source})$`, pattern.flags);
31
+ anchoredPatterns.set(pattern, anchored);
32
+ }
33
+ return anchored;
34
+ }
35
+
36
+ /** The module's routes with the app's overrides applied. */
37
+ export function getAuthRoutes(config: SoftureConfig): AuthRoutes {
38
+ const routes = getAuthModule(config).routes;
39
+ const read = (name: keyof AuthRoutes): string => {
40
+ const path = routes[name];
41
+ // The manifest declares every route, so a missing one means a broken module definition.
42
+ if (path === undefined) throw new Error(`@softure-ai/auth: route "${name}" is missing from the module manifest`);
43
+ return path;
44
+ };
45
+ return {
46
+ login: read("login"),
47
+ register: read("register"),
48
+ changePassword: read("changePassword"),
49
+ forgotPassword: read("forgotPassword"),
50
+ resetPassword: read("resetPassword"),
51
+ afterLogin: read("afterLogin"),
52
+ afterLogout: read("afterLogout"),
53
+ };
54
+ }
55
+
56
+ export interface AuthRoutes {
57
+ readonly login: string;
58
+ readonly register: string;
59
+ readonly changePassword: string;
60
+ readonly forgotPassword: string;
61
+ readonly resetPassword: string;
62
+ readonly afterLogin: string;
63
+ readonly afterLogout: string;
64
+ }