@lalternative/auth 0.9.5 → 0.10.1

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.
@@ -41,7 +41,7 @@ interface PlatformSession {
41
41
  user: PlatformUser;
42
42
  session: PlatformSessionData;
43
43
  }
44
- type PlatformAuthMailerType = "email-verification" | "forget-password" | "sign-in" | "change-email";
44
+ type PlatformAuthMailerType = "email-verification" | "forget-password" | "sign-in" | "change-email" | "magic-link";
45
45
  interface PlatformAuthMailerArgs {
46
46
  /** Recipient address */
47
47
  to: string;
@@ -51,10 +51,37 @@ interface PlatformAuthMailerArgs {
51
51
  html: string;
52
52
  /** Better Auth verification kind */
53
53
  type: PlatformAuthMailerType;
54
- /** The OTP value, in case the consumer wants to render its own template */
55
- otp: string;
54
+ /**
55
+ * The OTP value, in case the consumer wants to render its own template.
56
+ * Absent on `magic-link`, which carries a URL rather than a code.
57
+ */
58
+ otp?: string;
59
+ /**
60
+ * The sign-in URL, on `magic-link` only. Already signed and pointed at the
61
+ * app's callback — send it as given.
62
+ */
63
+ url?: string;
56
64
  }
57
65
  type PlatformAuthMailer = (args: PlatformAuthMailerArgs) => Promise<void>;
66
+ interface MagicLinkConfig {
67
+ /** Seconds until the emailed link stops working. Defaults to 300 (5 min). */
68
+ expiresIn?: number;
69
+ /**
70
+ * Whether an unknown address may create an account by following the link.
71
+ * Off by default, and deliberately so: `createPlatformAuth` requires a
72
+ * verified email and can be put behind an invite-only beta, both of which a
73
+ * self-signing-up magic link would walk straight past. Turn it on only for
74
+ * an app whose sign-up is open anyway.
75
+ */
76
+ allowSignUp?: boolean;
77
+ /** Subject line. Defaults to `Your sign-in link - ${appName}`. */
78
+ subject?: string;
79
+ /**
80
+ * Override the email HTML renderer. Receives the signed sign-in URL and the
81
+ * recipient. When omitted, the platform's default template is used.
82
+ */
83
+ render?: (url: string, email: string) => string;
84
+ }
58
85
  interface PlatformAuthConfig {
59
86
  /** PostgreSQL connection pool or connection string */
60
87
  database: BetterAuthOptions["database"];
@@ -93,6 +120,12 @@ interface PlatformAuthConfig {
93
120
  * default branded template is used.
94
121
  */
95
122
  renderOtpEmail?: (otp: string, type: PlatformAuthMailerType) => string;
123
+ /**
124
+ * Passwordless sign-in by emailed link. Omit to leave it off — the endpoint
125
+ * is only mounted when this is given, so an app that does not render the
126
+ * form does not expose the route either.
127
+ */
128
+ magicLink?: MagicLinkConfig;
96
129
  /**
97
130
  * Better Auth database hooks, passed through unchanged.
98
131
  *
@@ -271,6 +304,21 @@ interface AuthClientSurface {
271
304
  }): Promise<AuthClientResult>;
272
305
  };
273
306
  }
307
+ /**
308
+ * The magic-link half of the client surface, kept apart from
309
+ * {@link AuthClientSurface}: the plugin is opt-in server-side, so only the
310
+ * screens that offer the flow require a client carrying it.
311
+ */
312
+ interface MagicLinkClientSurface {
313
+ signIn: {
314
+ magicLink(input: {
315
+ email: string;
316
+ callbackURL?: string;
317
+ newUserCallbackURL?: string;
318
+ errorCallbackURL?: string;
319
+ }): Promise<AuthClientResult>;
320
+ };
321
+ }
274
322
  interface AuthThemeProps {
275
323
  /** Replaces the submit button's `bg-primary text-primary-foreground` */
276
324
  submitClassName?: string;
@@ -395,6 +443,48 @@ interface ForgotPasswordFormProps extends AuthThemeProps, AuthNavProps {
395
443
  /** Auth client instance, e.g. from createPlatformAuthClient */
396
444
  authClient: AuthClientSurface;
397
445
  }
446
+ interface MagicLinkFormLabels {
447
+ title?: string;
448
+ subtitle?: string;
449
+ emailPlaceholder?: string;
450
+ submit?: string;
451
+ submitPending?: string;
452
+ sent?: string;
453
+ resend?: string;
454
+ usePassword?: string;
455
+ login?: string;
456
+ emailRequired?: string;
457
+ sendFailed?: string;
458
+ }
459
+ interface MagicLinkFormProps extends AuthThemeProps, AuthNavProps, AuthInviteProps {
460
+ /** Callback once the link is on its way, receives the address it went to */
461
+ onSuccess?: (email: string) => void;
462
+ /** Error raised outside the form, rendered in the same banner */
463
+ error?: string;
464
+ /** Link to the password sign-in page */
465
+ loginUrl?: string;
466
+ /** Where Better Auth sends the browser once the link is followed */
467
+ callbackUrl?: string;
468
+ /**
469
+ * Where an existing account lands, when a first-time visitor should land
470
+ * elsewhere — an onboarding step, say. Defaults to `callbackUrl`.
471
+ */
472
+ newUserCallbackUrl?: string;
473
+ /**
474
+ * Where a link that did NOT work sends the browser, with `?error=` on it.
475
+ *
476
+ * Defaults to the page this form is on, which is the one place asking for
477
+ * another link is possible. Better Auth would otherwise fall back to
478
+ * `callbackUrl` — typically a signed-in destination, where an auth guard
479
+ * bounces the visitor and drops the error on the way, leaving an expired
480
+ * link looking like nothing happened at all.
481
+ */
482
+ errorCallbackUrl?: string;
483
+ /** Copy overrides; anything omitted keeps the French default */
484
+ labels?: MagicLinkFormLabels;
485
+ /** Auth client instance, e.g. from createPlatformAuthClient */
486
+ authClient: MagicLinkClientSurface;
487
+ }
398
488
  interface ResetPasswordFormLabels {
399
489
  title?: string;
400
490
  subtitle?: string;
@@ -450,4 +540,4 @@ interface AuthLayoutProps extends AuthHeadingProps {
450
540
  footer?: React.ReactNode;
451
541
  }
452
542
 
453
- export type { AuthLayoutProps as A, ForgotPasswordFormProps as F, InvitationNoticeProps as I, LoginFormProps as L, PlatformAuthClientConfig as P, RegisterFormProps as R, VerifyEmailFormProps as V, ResetPasswordFormProps as a, AuthClientResult as b, LinkComponent as c, AuthClientSurface as d, AuthInviteProps as e, AuthNavProps as f, AuthThemeProps as g, InvitationFailure as h, LoginFormLabels as i, PlatformAuthConfig as j, PlatformAuthMailer as k, PlatformAuthMailerArgs as l, PlatformAuthMailerType as m, PlatformSession as n, PlatformSessionData as o, PlatformUser as p, RegisterFormLabels as q };
543
+ export type { AuthLayoutProps as A, ForgotPasswordFormProps as F, InvitationNoticeProps as I, LoginFormProps as L, MagicLinkFormProps as M, PlatformAuthClientConfig as P, RegisterFormProps as R, VerifyEmailFormProps as V, ResetPasswordFormProps as a, AuthClientResult as b, LinkComponent as c, AuthClientSurface as d, AuthInviteProps as e, AuthNavProps as f, AuthThemeProps as g, InvitationFailure as h, LoginFormLabels as i, MagicLinkClientSurface as j, MagicLinkConfig as k, MagicLinkFormLabels as l, PlatformAuthConfig as m, PlatformAuthMailer as n, PlatformAuthMailerArgs as o, PlatformAuthMailerType as p, PlatformSession as q, PlatformSessionData as r, PlatformUser as s, RegisterFormLabels as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lalternative/auth",
3
- "version": "0.9.5",
3
+ "version": "0.10.1",
4
4
  "description": "Shared Better Auth wrapper for L'Alternative apps (server + React client + auth UI)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -22,6 +22,14 @@
22
22
  "files": [
23
23
  "dist"
24
24
  ],
25
+ "scripts": {
26
+ "build": "tsup",
27
+ "dev": "tsup --watch",
28
+ "typecheck": "tsc --noEmit",
29
+ "prepublishOnly": "pnpm build",
30
+ "test": "node --experimental-strip-types --test \"src/**/*.test.ts\"",
31
+ "playground": "vite --config playground/vite.config.ts"
32
+ },
25
33
  "peerDependencies": {
26
34
  "better-auth": ">=1.4.0",
27
35
  "react": ">=18.0.0",
@@ -49,12 +57,5 @@
49
57
  "type": "git",
50
58
  "url": "https://github.com/lalternative/packages.git",
51
59
  "directory": "auth"
52
- },
53
- "scripts": {
54
- "build": "tsup",
55
- "dev": "tsup --watch",
56
- "typecheck": "tsc --noEmit",
57
- "test": "node --experimental-strip-types --test \"src/**/*.test.ts\"",
58
- "playground": "vite --config playground/vite.config.ts"
59
60
  }
60
- }
61
+ }