@lalternative/auth 0.9.4 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -3
- package/dist/client.d.ts +9 -3
- package/dist/client.js +11 -2
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +46 -4
- package/dist/index.js +203 -46
- package/dist/index.js.map +1 -1
- package/dist/{invitation-Y9l1o_pm.d.ts → invitation-DcALM_sl.d.ts} +1 -1
- package/dist/server.d.ts +3 -3
- package/dist/server.js +64 -14
- package/dist/server.js.map +1 -1
- package/dist/{types-q-GAhurn.d.ts → types-BbTfkT5F.d.ts} +95 -14
- package/package.json +1 -1
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["import { betterAuth, APIError, type Auth, type BetterAuthOptions } from \"better-auth\"\nimport { emailOTP, admin } from \"better-auth/plugins\"\nimport type { PlatformAuthConfig, PlatformAuthMailerType } from \"./types\"\n\nconst DEFAULT_EMAIL_SUBJECTS: Record<string, string> = {\n \"email-verification\": \"Verify your account\",\n \"forget-password\": \"Reset your password\",\n \"sign-in\": \"Your sign-in code\",\n}\n\nfunction defaultRenderOtpEmail(otp: string): string {\n return `\n <div style=\"font-family:sans-serif;max-width:480px;margin:0 auto;padding:32px\">\n <h2 style=\"font-size:20px;font-weight:600;margin-bottom:16px\">Your verification code</h2>\n <p style=\"color:#555;margin-bottom:24px\">Use the code below to continue. It expires in 5 minutes.</p>\n <div style=\"background:#f5f5f5;border-radius:8px;padding:24px;text-align:center;letter-spacing:8px;font-size:32px;font-weight:700\">\n ${otp}\n </div>\n <p style=\"color:#999;font-size:12px;margin-top:24px\">If you didn't request this, you can safely ignore this email.</p>\n </div>\n `\n}\n\n/**\n * Creates a Better Auth instance with platform defaults.\n * Each app calls this with its own config (DB, secret, providers, plugins).\n */\nexport function createPlatformAuth(\n config: PlatformAuthConfig,\n): Auth<BetterAuthOptions> {\n const {\n database,\n baseURL,\n secret,\n appName,\n mailer,\n google,\n github,\n plugins = [],\n databaseHooks,\n betaMode = false,\n isInvited,\n emailSubjects,\n renderOtpEmail,\n } = config\n\n const subjects = { ...DEFAULT_EMAIL_SUBJECTS, ...emailSubjects }\n const renderEmail = renderOtpEmail ?? defaultRenderOtpEmail\n\n // The concrete instance type (with email-otp/admin plugins) is widened to\n // the base Auth type so the published .d.ts stays portable (inferring the\n // full plugin type triggers TS2742 — it can't be named without a zod ref).\n // The admin() plugin's user.role field is re-exposed via module augmentation\n // below, so consumers (e.g. transcript-web me.ts) still see session.user.role.\n return betterAuth({\n database,\n baseURL,\n secret,\n emailAndPassword: {\n enabled: true,\n requireEmailVerification: true,\n },\n // Never auto-merge a social identity into an existing account by matching\n // email. Better Auth links by default (email-verified providers are trusted),\n // so signing in with Google/GitHub on an email already registered would fold\n // that identity into the existing account. We keep each sign-in method its\n // own account: a social login on a taken email is refused, not linked.\n account: {\n accountLinking: {\n enabled: false,\n },\n },\n // Passed through as given. The platform defines none of its own today, so\n // there is nothing to merge; should it ever add one, this becomes a merge\n // rather than a hand-off, or an app silently switches a platform hook off.\n ...(databaseHooks ? { databaseHooks } : {}),\n hooks: {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n before: async (ctx: any) => {\n if (!betaMode) return\n if (ctx.path !== \"/sign-up/email\") return\n const body = ctx.body as { email?: string; inviteToken?: string } | undefined\n const email = body?.email\n const inviteToken = body?.inviteToken\n if (email && inviteToken && isInvited) {\n const ok = await isInvited(email, inviteToken)\n if (ok) return\n }\n throw new APIError(\"FORBIDDEN\", {\n message: \"Registration is invite-only during the private beta.\",\n })\n },\n },\n plugins: [\n emailOTP({\n async sendVerificationOTP({ email, otp, type }) {\n const subject = subjects[type]\n ? `${subjects[type]} - ${appName}`\n : `Your ${appName} code`\n const html = renderEmail(otp, type as PlatformAuthMailerType)\n\n if (mailer) {\n await mailer({\n to: email,\n subject,\n html,\n type: type as PlatformAuthMailerType,\n otp,\n })\n return\n }\n\n console.warn(\n `[EMAIL] No mailer configured — logging OTP to stdout for ${email} (${type}): ${otp}`,\n )\n },\n otpLength: 6,\n expiresIn: 300,\n overrideDefaultEmailVerification: true,\n }),\n admin(),\n ...plugins, // app-specific plugins (e.g. tanstackStartCookies)\n ],\n socialProviders: {\n ...(google\n ? {\n google: {\n clientId: google.clientId,\n clientSecret: google.clientSecret,\n },\n }\n : {}),\n ...(github\n ? {\n github: {\n clientId: github.clientId,\n clientSecret: github.clientSecret,\n },\n }\n : {}),\n },\n }) as unknown as Auth<BetterAuthOptions>\n}\n\nexport type PlatformAuth = ReturnType<typeof createPlatformAuth>\n\n// Re-export the session contract from /server so consumers that import the\n// auth factory can type api.getSession() without a second import path.\nexport type {\n PlatformUser,\n PlatformSession,\n PlatformSessionData,\n} from \"./types\"\n\n// Invitation claiming runs on the auth callback, where the session is\n// established — the one place every sign-up flow passes through.\nexport {\n claimInvitation,\n completesSignup,\n holdInviteTokenCookie,\n invitationOutcomeCookie,\n inviteTokenFrom,\n isInvitationFailure,\n pinInviteToken,\n releaseInviteTokenCookie,\n} from \"./invitation\"\nexport type { ClaimOutcome, ClaimInvitationOptions } from \"./invitation\"\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,YAAY,gBAAmD;AACxE,SAAS,UAAU,aAAa;AAGhC,IAAM,yBAAiD;AAAA,EACrD,sBAAsB;AAAA,EACtB,mBAAmB;AAAA,EACnB,WAAW;AACb;AAEA,SAAS,sBAAsB,KAAqB;AAClD,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA,oBAKW,GAAG;AAAA;AAAA;AAAA;AAAA;AAKvB;AAMO,SAAS,mBACd,QACyB;AACzB,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU,CAAC;AAAA,IACX;AAAA,IACA,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,EACF,IA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AAAA,QACX,kCAAkC;AAAA,MACpC,CAAC;AAAA,MACD,MAAM;AAAA,MACN,GAAG;AAAA;AAAA,IACL;AAAA,IACA,iBAAiB;AAAA,MACf,GAAI,SACA;AAAA,QACE,QAAQ;AAAA,UACN,UAAU,OAAO;AAAA,UACjB,cAAc,OAAO;AAAA,QACvB;AAAA,MACF,IACA,CAAC;AAAA,MACL,GAAI,SACA;AAAA,QACE,QAAQ;AAAA,UACN,UAAU,OAAO;AAAA,UACjB,cAAc,OAAO;AAAA,QACvB;AAAA,MACF,IACA,CAAC;AAAA,IACP;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/server.ts","../src/google-defaults.ts"],"sourcesContent":["import { betterAuth, APIError, type Auth, type BetterAuthOptions } from \"better-auth\"\nimport { emailOTP, admin, magicLink } from \"better-auth/plugins\"\nimport type { PlatformAuthConfig, PlatformAuthMailerType } from \"./types\"\nimport { withGoogleDefaults } from \"./google-defaults\"\n\nconst DEFAULT_EMAIL_SUBJECTS: Record<string, string> = {\n \"email-verification\": \"Verify your account\",\n \"forget-password\": \"Reset your password\",\n \"sign-in\": \"Your sign-in code\",\n}\n\nfunction defaultRenderOtpEmail(otp: string): string {\n return `\n <div style=\"font-family:sans-serif;max-width:480px;margin:0 auto;padding:32px\">\n <h2 style=\"font-size:20px;font-weight:600;margin-bottom:16px\">Your verification code</h2>\n <p style=\"color:#555;margin-bottom:24px\">Use the code below to continue. It expires in 5 minutes.</p>\n <div style=\"background:#f5f5f5;border-radius:8px;padding:24px;text-align:center;letter-spacing:8px;font-size:32px;font-weight:700\">\n ${otp}\n </div>\n <p style=\"color:#999;font-size:12px;margin-top:24px\">If you didn't request this, you can safely ignore this email.</p>\n </div>\n `\n}\n\nfunction defaultRenderMagicLinkEmail(url: string): string {\n return `\n <div style=\"font-family:sans-serif;max-width:480px;margin:0 auto;padding:32px\">\n <h2 style=\"font-size:20px;font-weight:600;margin-bottom:16px\">Your sign-in link</h2>\n <p style=\"color:#555;margin-bottom:24px\">Click the button below to sign in. The link expires in 5 minutes and works once.</p>\n <a href=\"${url}\" style=\"display:inline-block;background:#111;color:#fff;text-decoration:none;border-radius:8px;padding:14px 28px;font-weight:600\">Sign in</a>\n <p style=\"color:#999;font-size:12px;margin-top:24px;word-break:break-all\">Or paste this address into your browser:<br>${url}</p>\n <p style=\"color:#999;font-size:12px;margin-top:16px\">If you didn't request this, you can safely ignore this email.</p>\n </div>\n `\n}\n\n/**\n * Creates a Better Auth instance with platform defaults.\n * Each app calls this with its own config (DB, secret, providers, plugins).\n */\nexport function createPlatformAuth(\n config: PlatformAuthConfig,\n): Auth<BetterAuthOptions> {\n const {\n database,\n baseURL,\n secret,\n appName,\n mailer,\n google,\n github,\n plugins = [],\n databaseHooks,\n betaMode = false,\n isInvited,\n emailSubjects,\n renderOtpEmail,\n magicLink: magicLinkConfig,\n } = config\n\n const subjects = { ...DEFAULT_EMAIL_SUBJECTS, ...emailSubjects }\n const renderEmail = renderOtpEmail ?? defaultRenderOtpEmail\n\n // The concrete instance type (with email-otp/admin plugins) is widened to\n // the base Auth type so the published .d.ts stays portable (inferring the\n // full plugin type triggers TS2742 — it can't be named without a zod ref).\n // The admin() plugin's user.role field is re-exposed via module augmentation\n // below, so consumers (e.g. transcript-web me.ts) still see session.user.role.\n return betterAuth({\n database,\n baseURL,\n secret,\n emailAndPassword: {\n enabled: true,\n requireEmailVerification: true,\n },\n // Never auto-merge a social identity into an existing account by matching\n // email. Better Auth links by default (email-verified providers are trusted),\n // so signing in with Google/GitHub on an email already registered would fold\n // that identity into the existing account. We keep each sign-in method its\n // own account: a social login on a taken email is refused, not linked.\n account: {\n accountLinking: {\n enabled: false,\n },\n },\n // Passed through as given. The platform defines none of its own today, so\n // there is nothing to merge; should it ever add one, this becomes a merge\n // rather than a hand-off, or an app silently switches a platform hook off.\n ...(databaseHooks ? { databaseHooks } : {}),\n hooks: {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n before: async (ctx: any) => {\n if (!betaMode) return\n if (ctx.path !== \"/sign-up/email\") return\n const body = ctx.body as { email?: string; inviteToken?: string } | undefined\n const email = body?.email\n const inviteToken = body?.inviteToken\n if (email && inviteToken && isInvited) {\n const ok = await isInvited(email, inviteToken)\n if (ok) return\n }\n throw new APIError(\"FORBIDDEN\", {\n message: \"Registration is invite-only during the private beta.\",\n })\n },\n },\n plugins: [\n emailOTP({\n async sendVerificationOTP({ email, otp, type }) {\n const subject = subjects[type]\n ? `${subjects[type]} - ${appName}`\n : `Your ${appName} code`\n const html = renderEmail(otp, type as PlatformAuthMailerType)\n\n if (mailer) {\n await mailer({\n to: email,\n subject,\n html,\n type: type as PlatformAuthMailerType,\n otp,\n })\n return\n }\n\n console.warn(\n `[EMAIL] No mailer configured — logging OTP to stdout for ${email} (${type}): ${otp}`,\n )\n },\n otpLength: 6,\n expiresIn: 300,\n overrideDefaultEmailVerification: true,\n }),\n ...(magicLinkConfig\n ? [\n magicLink({\n expiresIn: magicLinkConfig.expiresIn ?? 300,\n // A magic link that signs up walks past both gates the platform\n // puts on the front door: requireEmailVerification, and the\n // invite-only hook, which only guards /sign-up/email.\n disableSignUp: !magicLinkConfig.allowSignUp,\n async sendMagicLink({ email, url }) {\n const subject =\n magicLinkConfig.subject ?? `Your sign-in link - ${appName}`\n const html = (\n magicLinkConfig.render ?? defaultRenderMagicLinkEmail\n )(url, email)\n\n if (mailer) {\n await mailer({\n to: email,\n subject,\n html,\n type: \"magic-link\",\n url,\n })\n return\n }\n\n console.warn(\n `[EMAIL] No mailer configured — logging magic link to stdout for ${email}: ${url}`,\n )\n },\n }),\n ]\n : []),\n admin(),\n ...plugins, // app-specific plugins (e.g. tanstackStartCookies)\n ],\n socialProviders: {\n // Spread as given rather than rebuilt field by field: anything Better\n // Auth accepts belongs to the app, and a config silently dropped on the\n // way through is how an app ends up writing a plugin to put it back.\n //\n // The two defaults below are the platform's, not Google's: without\n // accessType 'offline' Google never mints a refresh token, and without\n // 'consent' it stops minting one for an account that already consented.\n // A NULL refreshToken means deleting an account can revoke the access\n // token but cannot remove the app from myaccount.google.com/permissions,\n // so the grant outlives the account it belonged to.\n ...(google ? { google: withGoogleDefaults(google) } : {}),\n ...(github ? { github } : {}),\n },\n }) as unknown as Auth<BetterAuthOptions>\n}\n\nexport type PlatformAuth = ReturnType<typeof createPlatformAuth>\n\n// Re-export the session contract from /server so consumers that import the\n// auth factory can type api.getSession() without a second import path.\nexport type {\n PlatformUser,\n PlatformSession,\n PlatformSessionData,\n} from \"./types\"\n\n// Invitation claiming runs on the auth callback, where the session is\n// established — the one place every sign-up flow passes through.\nexport {\n claimInvitation,\n completesSignup,\n holdInviteTokenCookie,\n invitationOutcomeCookie,\n inviteTokenFrom,\n isInvitationFailure,\n pinInviteToken,\n releaseInviteTokenCookie,\n} from \"./invitation\"\nexport type { ClaimOutcome, ClaimInvitationOptions } from \"./invitation\"\n","import type { PlatformAuthConfig } from \"./types\"\n\n/**\n * Applies the platform's Google defaults without touching what the app set.\n *\n * Better Auth also accepts a function returning the options, which cannot be\n * amended without calling it — such a config is passed straight through and\n * owns its own defaults.\n */\nexport function withGoogleDefaults(\n google: NonNullable<PlatformAuthConfig[\"google\"]>,\n): NonNullable<PlatformAuthConfig[\"google\"]> {\n if (typeof google === \"function\") return google\n return {\n ...google,\n accessType: google.accessType ?? \"offline\",\n prompt: google.prompt ?? \"select_account consent\",\n }\n}\n\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,YAAY,gBAAmD;AACxE,SAAS,UAAU,OAAO,iBAAiB;;;ACQpC,SAAS,mBACd,QAC2C;AAC3C,MAAI,OAAO,WAAW,WAAY,QAAO;AACzC,SAAO;AAAA,IACL,GAAG;AAAA,IACH,YAAY,OAAO,cAAc;AAAA,IACjC,QAAQ,OAAO,UAAU;AAAA,EAC3B;AACF;;;ADbA,IAAM,yBAAiD;AAAA,EACrD,sBAAsB;AAAA,EACtB,mBAAmB;AAAA,EACnB,WAAW;AACb;AAEA,SAAS,sBAAsB,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SAAS,EAAE,OAAO,IAAI,CAAC;AAAA,IAC7B;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BetterAuthOptions } from 'better-auth';
|
|
2
2
|
|
|
3
|
+
type SocialProviderOptions = NonNullable<BetterAuthOptions["socialProviders"]>;
|
|
3
4
|
/**
|
|
4
5
|
* Session user shape exposed by the platform auth instance.
|
|
5
6
|
*
|
|
@@ -40,7 +41,7 @@ interface PlatformSession {
|
|
|
40
41
|
user: PlatformUser;
|
|
41
42
|
session: PlatformSessionData;
|
|
42
43
|
}
|
|
43
|
-
type PlatformAuthMailerType = "email-verification" | "forget-password" | "sign-in" | "change-email";
|
|
44
|
+
type PlatformAuthMailerType = "email-verification" | "forget-password" | "sign-in" | "change-email" | "magic-link";
|
|
44
45
|
interface PlatformAuthMailerArgs {
|
|
45
46
|
/** Recipient address */
|
|
46
47
|
to: string;
|
|
@@ -50,10 +51,37 @@ interface PlatformAuthMailerArgs {
|
|
|
50
51
|
html: string;
|
|
51
52
|
/** Better Auth verification kind */
|
|
52
53
|
type: PlatformAuthMailerType;
|
|
53
|
-
/**
|
|
54
|
-
|
|
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;
|
|
55
64
|
}
|
|
56
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
|
+
}
|
|
57
85
|
interface PlatformAuthConfig {
|
|
58
86
|
/** PostgreSQL connection pool or connection string */
|
|
59
87
|
database: BetterAuthOptions["database"];
|
|
@@ -70,16 +98,16 @@ interface PlatformAuthConfig {
|
|
|
70
98
|
* stdout — useful in dev/test, useless in production.
|
|
71
99
|
*/
|
|
72
100
|
mailer?: PlatformAuthMailer;
|
|
73
|
-
/**
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
101
|
+
/**
|
|
102
|
+
* Google OAuth config (omit to disable).
|
|
103
|
+
*
|
|
104
|
+
* Passed to Better Auth as given, so anything it accepts works here —
|
|
105
|
+
* `scope`, `mapProfileToUser`, `redirectURI`. The platform sets `prompt` and
|
|
106
|
+
* `accessType` first; pass either to override it.
|
|
107
|
+
*/
|
|
108
|
+
google?: SocialProviderOptions["google"];
|
|
109
|
+
/** GitHub OAuth config (omit to disable). Passed to Better Auth as given. */
|
|
110
|
+
github?: SocialProviderOptions["github"];
|
|
83
111
|
/**
|
|
84
112
|
* Override the OTP email subject line per verification type. Merged over
|
|
85
113
|
* the platform defaults — provide only the keys you want to change. The
|
|
@@ -92,6 +120,12 @@ interface PlatformAuthConfig {
|
|
|
92
120
|
* default branded template is used.
|
|
93
121
|
*/
|
|
94
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;
|
|
95
129
|
/**
|
|
96
130
|
* Better Auth database hooks, passed through unchanged.
|
|
97
131
|
*
|
|
@@ -270,6 +304,21 @@ interface AuthClientSurface {
|
|
|
270
304
|
}): Promise<AuthClientResult>;
|
|
271
305
|
};
|
|
272
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
|
+
}
|
|
273
322
|
interface AuthThemeProps {
|
|
274
323
|
/** Replaces the submit button's `bg-primary text-primary-foreground` */
|
|
275
324
|
submitClassName?: string;
|
|
@@ -394,6 +443,38 @@ interface ForgotPasswordFormProps extends AuthThemeProps, AuthNavProps {
|
|
|
394
443
|
/** Auth client instance, e.g. from createPlatformAuthClient */
|
|
395
444
|
authClient: AuthClientSurface;
|
|
396
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
|
+
/** Copy overrides; anything omitted keeps the French default */
|
|
474
|
+
labels?: MagicLinkFormLabels;
|
|
475
|
+
/** Auth client instance, e.g. from createPlatformAuthClient */
|
|
476
|
+
authClient: MagicLinkClientSurface;
|
|
477
|
+
}
|
|
397
478
|
interface ResetPasswordFormLabels {
|
|
398
479
|
title?: string;
|
|
399
480
|
subtitle?: string;
|
|
@@ -449,4 +530,4 @@ interface AuthLayoutProps extends AuthHeadingProps {
|
|
|
449
530
|
footer?: React.ReactNode;
|
|
450
531
|
}
|
|
451
532
|
|
|
452
|
-
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,
|
|
533
|
+
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 };
|