@lalternative/auth 0.4.0 → 0.4.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.
- package/dist/chunk-73BHM4PZ.js +72 -0
- package/dist/chunk-73BHM4PZ.js.map +1 -0
- package/dist/client.d.ts +15 -0
- package/dist/client.js +13 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +70 -0
- package/dist/index.js +445 -0
- package/dist/index.js.map +1 -0
- package/dist/invitation-DIZAb2BJ.d.ts +82 -0
- package/dist/server.d.ts +13 -0
- package/dist/server.js +132 -0
- package/dist/server.js.map +1 -0
- package/dist/types-DKEKNQkL.d.ts +159 -0
- package/package.json +3 -2
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// src/invitation.ts
|
|
2
|
+
var OUTCOME_BY_STATUS = {
|
|
3
|
+
404: "unknown",
|
|
4
|
+
409: "claimed",
|
|
5
|
+
410: "expired"
|
|
6
|
+
};
|
|
7
|
+
async function claimInvitation({
|
|
8
|
+
endpoint,
|
|
9
|
+
token,
|
|
10
|
+
externalUserId,
|
|
11
|
+
apiKey,
|
|
12
|
+
extra,
|
|
13
|
+
headers,
|
|
14
|
+
timeoutMs = 5e3
|
|
15
|
+
}) {
|
|
16
|
+
try {
|
|
17
|
+
const res = await fetch(endpoint, {
|
|
18
|
+
method: "POST",
|
|
19
|
+
headers: {
|
|
20
|
+
"content-type": "application/json",
|
|
21
|
+
...apiKey ? { authorization: `Bearer ${apiKey}` } : {},
|
|
22
|
+
...headers
|
|
23
|
+
},
|
|
24
|
+
body: JSON.stringify({
|
|
25
|
+
token,
|
|
26
|
+
external_user_id: externalUserId,
|
|
27
|
+
...extra
|
|
28
|
+
}),
|
|
29
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
30
|
+
});
|
|
31
|
+
if (res.ok) return "granted";
|
|
32
|
+
return OUTCOME_BY_STATUS[res.status] ?? "failed";
|
|
33
|
+
} catch {
|
|
34
|
+
return "failed";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function inviteTokenFrom(request, param = "invite") {
|
|
38
|
+
const direct = new URL(request.url).searchParams.get(param);
|
|
39
|
+
if (direct && direct.trim() !== "") return direct;
|
|
40
|
+
const referer = request.headers.get("referer");
|
|
41
|
+
if (!referer) return null;
|
|
42
|
+
try {
|
|
43
|
+
const token = new URL(referer).searchParams.get(param);
|
|
44
|
+
return token && token.trim() !== "" ? token : null;
|
|
45
|
+
} catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
var SIGNUP_COMPLETING = [
|
|
50
|
+
"/sign-up/email",
|
|
51
|
+
"/sign-in/email-otp",
|
|
52
|
+
"/email-otp/verify-email",
|
|
53
|
+
"/callback/"
|
|
54
|
+
];
|
|
55
|
+
function completesSignup(pathname) {
|
|
56
|
+
return SIGNUP_COMPLETING.some((p) => pathname.includes(p));
|
|
57
|
+
}
|
|
58
|
+
function invitationOutcomeCookie(outcome, name = "invite_claim") {
|
|
59
|
+
return `${name}=${outcome}; Path=/; Max-Age=120; SameSite=Lax`;
|
|
60
|
+
}
|
|
61
|
+
function isInvitationFailure(outcome) {
|
|
62
|
+
return outcome === "expired" || outcome === "claimed" || outcome === "unknown";
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export {
|
|
66
|
+
claimInvitation,
|
|
67
|
+
inviteTokenFrom,
|
|
68
|
+
completesSignup,
|
|
69
|
+
invitationOutcomeCookie,
|
|
70
|
+
isInvitationFailure
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=chunk-73BHM4PZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/invitation.ts"],"sourcesContent":["import type { InvitationFailure } from \"./types\"\n\n/**\n * What became of a claim, in terms the invitee can be told.\n *\n * 'expired' and 'claimed' are kept apart from 'unknown' because only they say\n * the offer was real, which is what tells someone that asking for a new link is\n * worth it rather than doubting the address they were invited at. The three\n * failures match InvitationFailure, so an outcome feeds InvitationNotice\n * directly.\n */\nexport type ClaimOutcome = \"granted\" | InvitationFailure | \"failed\"\n\nconst OUTCOME_BY_STATUS: Record<number, ClaimOutcome> = {\n 404: \"unknown\",\n 409: \"claimed\",\n 410: \"expired\",\n}\n\nexport interface ClaimInvitationOptions {\n /** Absolute URL of the endpoint that redeems a token. */\n endpoint: string\n token: string\n /** The account the app just created, which the grant is attached to. */\n externalUserId: string\n /** Sent as the Authorization bearer — typically the app's API key. */\n apiKey?: string\n /** Merged into the request body, for backends wanting more than the token. */\n extra?: Record<string, unknown>\n /** Headers merged last, so a caller can pass a cookie-based credential. */\n headers?: Record<string, string>\n /** Bounds the call so a slow API never stalls the sign-in response. */\n timeoutMs?: number\n}\n\n/**\n * Redeems an invitation token for a user who has just signed in, turning the\n * offer into a grant on their account.\n *\n * Why this belongs on the SERVER, on the auth callback rather than in the page:\n * the invitation link lands on /register?invite=<token>, but the sign-up that\n * follows can complete through any of three flows (password + OTP, OAuth\n * redirect, email verification), and only two of them return to the page that\n * held the token. Claiming where the session is established covers every flow\n * with one code path.\n *\n * Best-effort by design: a sign-in must never fail because an invitation could\n * not be redeemed. A failed claim leaves the invitation unclaimed and the user\n * on their default tier — recoverable by following the link again, since a\n * refused claim consumes nothing.\n */\nexport async function claimInvitation({\n endpoint,\n token,\n externalUserId,\n apiKey,\n extra,\n headers,\n timeoutMs = 5000,\n}: ClaimInvitationOptions): Promise<ClaimOutcome> {\n try {\n const res = await fetch(endpoint, {\n method: \"POST\",\n headers: {\n \"content-type\": \"application/json\",\n ...(apiKey ? { authorization: `Bearer ${apiKey}` } : {}),\n ...headers,\n },\n body: JSON.stringify({\n token,\n external_user_id: externalUserId,\n ...extra,\n }),\n signal: AbortSignal.timeout(timeoutMs),\n })\n\n if (res.ok) return \"granted\"\n return OUTCOME_BY_STATUS[res.status] ?? \"failed\"\n } catch {\n return \"failed\"\n }\n}\n\n/**\n * Extracts the invitation token from an auth request.\n *\n * The token lives on the page the invitee landed on (/register?invite=…), never\n * on the auth endpoints themselves, so it has to be recovered from the request\n * that completes the sign-up. Two sources, because no single one covers every\n * flow: the URL, for the OAuth callback reached through a redirect whose query\n * string the app controls; and the Referer, for the password and OTP flows,\n * which are XHR calls issued BY that page and therefore carry it.\n *\n * Reading it per-request keeps the claim stateless: nothing associates a\n * browser with a pending invitation, and a request with no token claims\n * nothing. A malformed Referer is ignored rather than thrown on — it is\n * attacker-controlled input on a best-effort path.\n */\nexport function inviteTokenFrom(\n request: Request,\n param = \"invite\",\n): string | null {\n const direct = new URL(request.url).searchParams.get(param)\n if (direct && direct.trim() !== \"\") return direct\n\n const referer = request.headers.get(\"referer\")\n if (!referer) return null\n try {\n const token = new URL(referer).searchParams.get(param)\n return token && token.trim() !== \"\" ? token : null\n } catch {\n return null\n }\n}\n\n/**\n * BetterAuth paths that complete a sign-up. Email/password returns the user\n * straight from sign-up/email; the OTP and OAuth flows only produce a usable\n * account once the verification/callback succeeds, so those are the moments\n * worth reacting to.\n */\nconst SIGNUP_COMPLETING = [\n \"/sign-up/email\",\n \"/sign-in/email-otp\",\n \"/email-otp/verify-email\",\n \"/callback/\",\n]\n\n/**\n * Whether this request is the one that just created a usable account — the\n * moment to provision, claim an invitation, or greet someone. Matching on the\n * path rather than on a response body keeps it flow-agnostic: the three\n * sign-up flows return three different shapes.\n */\nexport function completesSignup(pathname: string): boolean {\n return SIGNUP_COMPLETING.some((p) => pathname.includes(p))\n}\n\n/**\n * Carries a failed claim to the next page. The claim happens inside an auth\n * response nobody renders, so its result would otherwise reach only the server\n * log — leaving an invitee on the default tier with no idea their link had\n * lapsed. Short-lived and readable by the page, which reports it and clears it.\n */\nexport function invitationOutcomeCookie(\n outcome: ClaimOutcome,\n name = \"invite_claim\",\n): string {\n return `${name}=${outcome}; Path=/; Max-Age=120; SameSite=Lax`\n}\n\n/**\n * Whether an outcome is one the invitee should be shown a reason for.\n * 'failed' is excluded: it means the call did not complete, so the offer may\n * still be good and telling someone their invitation is invalid would be wrong.\n */\nexport function isInvitationFailure(\n outcome: ClaimOutcome,\n): outcome is InvitationFailure {\n return outcome === \"expired\" || outcome === \"claimed\" || outcome === \"unknown\"\n}\n"],"mappings":";AAaA,IAAM,oBAAkD;AAAA,EACtD,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AACP;AAkCA,eAAsB,gBAAgB;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY;AACd,GAAkD;AAChD,MAAI;AACF,UAAM,MAAM,MAAM,MAAM,UAAU;AAAA,MAChC,QAAQ;AAAA,MACR,SAAS;AAAA,QACP,gBAAgB;AAAA,QAChB,GAAI,SAAS,EAAE,eAAe,UAAU,MAAM,GAAG,IAAI,CAAC;AAAA,QACtD,GAAG;AAAA,MACL;AAAA,MACA,MAAM,KAAK,UAAU;AAAA,QACnB;AAAA,QACA,kBAAkB;AAAA,QAClB,GAAG;AAAA,MACL,CAAC;AAAA,MACD,QAAQ,YAAY,QAAQ,SAAS;AAAA,IACvC,CAAC;AAED,QAAI,IAAI,GAAI,QAAO;AACnB,WAAO,kBAAkB,IAAI,MAAM,KAAK;AAAA,EAC1C,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAiBO,SAAS,gBACd,SACA,QAAQ,UACO;AACf,QAAM,SAAS,IAAI,IAAI,QAAQ,GAAG,EAAE,aAAa,IAAI,KAAK;AAC1D,MAAI,UAAU,OAAO,KAAK,MAAM,GAAI,QAAO;AAE3C,QAAM,UAAU,QAAQ,QAAQ,IAAI,SAAS;AAC7C,MAAI,CAAC,QAAS,QAAO;AACrB,MAAI;AACF,UAAM,QAAQ,IAAI,IAAI,OAAO,EAAE,aAAa,IAAI,KAAK;AACrD,WAAO,SAAS,MAAM,KAAK,MAAM,KAAK,QAAQ;AAAA,EAChD,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAQA,IAAM,oBAAoB;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAQO,SAAS,gBAAgB,UAA2B;AACzD,SAAO,kBAAkB,KAAK,CAAC,MAAM,SAAS,SAAS,CAAC,CAAC;AAC3D;AAQO,SAAS,wBACd,SACA,OAAO,gBACC;AACR,SAAO,GAAG,IAAI,IAAI,OAAO;AAC3B;AAOO,SAAS,oBACd,SAC8B;AAC9B,SAAO,YAAY,aAAa,YAAY,aAAa,YAAY;AACvE;","names":[]}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as better_auth_react from 'better-auth/react';
|
|
2
|
+
import { P as PlatformAuthClientConfig } from './types-DKEKNQkL.js';
|
|
3
|
+
import 'better-auth';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a Better Auth client for React usage.
|
|
7
|
+
* Provides useSession() hook and other React-integrated methods.
|
|
8
|
+
*/
|
|
9
|
+
declare function createPlatformAuthClient(config?: PlatformAuthClientConfig): better_auth_react.ReactAuthClient<{
|
|
10
|
+
baseURL: string;
|
|
11
|
+
plugins: any[];
|
|
12
|
+
}>;
|
|
13
|
+
type PlatformAuthClient = ReturnType<typeof createPlatformAuthClient>;
|
|
14
|
+
|
|
15
|
+
export { type PlatformAuthClient, createPlatformAuthClient };
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/client.ts
|
|
2
|
+
import { createAuthClient } from "better-auth/react";
|
|
3
|
+
import { emailOTPClient, adminClient } from "better-auth/client/plugins";
|
|
4
|
+
function createPlatformAuthClient(config) {
|
|
5
|
+
return createAuthClient({
|
|
6
|
+
baseURL: config?.baseURL ?? (typeof window !== "undefined" ? window.location.origin : "http://localhost:3000"),
|
|
7
|
+
plugins: [emailOTPClient(), adminClient(), ...config?.plugins ?? []]
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
createPlatformAuthClient
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["import { createAuthClient } from \"better-auth/react\"\nimport { emailOTPClient, adminClient } from \"better-auth/client/plugins\"\nimport type { PlatformAuthClientConfig } from \"./types\"\n\n/**\n * Creates a Better Auth client for React usage.\n * Provides useSession() hook and other React-integrated methods.\n */\nexport function createPlatformAuthClient(config?: PlatformAuthClientConfig) {\n return createAuthClient({\n baseURL:\n config?.baseURL ??\n (typeof window !== \"undefined\"\n ? window.location.origin\n : \"http://localhost:3000\"),\n plugins: [emailOTPClient(), adminClient(), ...(config?.plugins ?? [])],\n })\n}\n\nexport type PlatformAuthClient = ReturnType<typeof createPlatformAuthClient>\n"],"mappings":";AAAA,SAAS,wBAAwB;AACjC,SAAS,gBAAgB,mBAAmB;AAOrC,SAAS,yBAAyB,QAAmC;AAC1E,SAAO,iBAAiB;AAAA,IACtB,SACE,QAAQ,YACP,OAAO,WAAW,cACf,OAAO,SAAS,SAChB;AAAA,IACN,SAAS,CAAC,eAAe,GAAG,YAAY,GAAG,GAAI,QAAQ,WAAW,CAAC,CAAE;AAAA,EACvE,CAAC;AACH;","names":[]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { V as VerifyEmailFormProps, F as ForgotPasswordFormProps, R as ResetPasswordFormProps, A as AuthLayoutProps, I as InvitationNoticeProps } from './types-DKEKNQkL.js';
|
|
2
|
+
export { a as InvitationFailure, P as PlatformAuthClientConfig, b as PlatformAuthConfig, c as PlatformAuthMailer, d as PlatformAuthMailerArgs, e as PlatformAuthMailerType, f as PlatformSession, g as PlatformSessionData, h as PlatformUser } from './types-DKEKNQkL.js';
|
|
3
|
+
import * as better_auth_react from 'better-auth/react';
|
|
4
|
+
import * as better_auth from 'better-auth';
|
|
5
|
+
import { PlatformAuthClient } from './client.js';
|
|
6
|
+
import * as react from 'react';
|
|
7
|
+
export { C as ClaimOutcome, i as isInvitationFailure } from './invitation-DIZAb2BJ.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Returns a useSession hook bound to the given auth client.
|
|
11
|
+
* Usage: const { data: session, isPending } = useSession(authClient)
|
|
12
|
+
*/
|
|
13
|
+
declare function useSession(authClient: PlatformAuthClient): {
|
|
14
|
+
data: {
|
|
15
|
+
user: better_auth.StripEmptyObjects<{
|
|
16
|
+
id: string;
|
|
17
|
+
createdAt: Date;
|
|
18
|
+
updatedAt: Date;
|
|
19
|
+
email: string;
|
|
20
|
+
emailVerified: boolean;
|
|
21
|
+
name: string;
|
|
22
|
+
image?: string | null | undefined;
|
|
23
|
+
}>;
|
|
24
|
+
session: better_auth.StripEmptyObjects<{
|
|
25
|
+
id: string;
|
|
26
|
+
createdAt: Date;
|
|
27
|
+
updatedAt: Date;
|
|
28
|
+
userId: string;
|
|
29
|
+
expiresAt: Date;
|
|
30
|
+
token: string;
|
|
31
|
+
ipAddress?: string | null | undefined;
|
|
32
|
+
userAgent?: string | null | undefined;
|
|
33
|
+
}>;
|
|
34
|
+
} | null;
|
|
35
|
+
isPending: boolean;
|
|
36
|
+
isRefetching: boolean;
|
|
37
|
+
error: better_auth_react.BetterFetchError | null;
|
|
38
|
+
refetch: (queryParams?: {
|
|
39
|
+
query?: better_auth.SessionQueryParams;
|
|
40
|
+
} | undefined) => Promise<void>;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Returns a logout function bound to the given auth client.
|
|
44
|
+
* Usage: const logout = useLogout(authClient)
|
|
45
|
+
*/
|
|
46
|
+
declare function useLogout(authClient: PlatformAuthClient): () => Promise<void>;
|
|
47
|
+
|
|
48
|
+
declare function VerifyEmailForm({ email, onSuccess, authClient, }: VerifyEmailFormProps): react.JSX.Element;
|
|
49
|
+
|
|
50
|
+
declare function ForgotPasswordForm({ onSuccess, loginUrl, authClient, }: ForgotPasswordFormProps): react.JSX.Element;
|
|
51
|
+
|
|
52
|
+
declare function ResetPasswordForm({ email, onSuccess, loginUrl, authClient, }: ResetPasswordFormProps): react.JSX.Element;
|
|
53
|
+
|
|
54
|
+
declare function AuthLayout({ logo, title, subtitle, children, footer, }: AuthLayoutProps): react.JSX.Element;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* What an invitee sees when their link does not work.
|
|
58
|
+
*
|
|
59
|
+
* It names the reason instead of merging the cases into one message: "expired"
|
|
60
|
+
* tells someone their link was real and that asking for another one is worth
|
|
61
|
+
* it, which "invalid" does not. Short TTLs make that distinction routine.
|
|
62
|
+
*
|
|
63
|
+
* The only way forward offered is a mailto, deliberately. A self-service
|
|
64
|
+
* "request a new invitation" form would mean a public endpoint accepting dead
|
|
65
|
+
* tokens, a queue to moderate, and a way to probe which tokens once existed —
|
|
66
|
+
* for a flow where the operator already knows the person by name.
|
|
67
|
+
*/
|
|
68
|
+
declare function InvitationNotice({ reason, supportEmail, title, action, }: InvitationNoticeProps): react.JSX.Element;
|
|
69
|
+
|
|
70
|
+
export { AuthLayout, AuthLayoutProps, ForgotPasswordForm, ForgotPasswordFormProps, InvitationNotice, InvitationNoticeProps, ResetPasswordForm, ResetPasswordFormProps, VerifyEmailForm, VerifyEmailFormProps, useLogout, useSession };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isInvitationFailure
|
|
3
|
+
} from "./chunk-73BHM4PZ.js";
|
|
4
|
+
|
|
5
|
+
// src/hooks/use-session.ts
|
|
6
|
+
function useSession(authClient) {
|
|
7
|
+
return authClient.useSession();
|
|
8
|
+
}
|
|
9
|
+
function useLogout(authClient) {
|
|
10
|
+
const signOut = async () => {
|
|
11
|
+
await authClient.signOut();
|
|
12
|
+
};
|
|
13
|
+
return signOut;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// src/components/verify-email-form.tsx
|
|
17
|
+
import { useState } from "react";
|
|
18
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
19
|
+
function VerifyEmailForm({
|
|
20
|
+
email,
|
|
21
|
+
onSuccess,
|
|
22
|
+
authClient
|
|
23
|
+
}) {
|
|
24
|
+
const [otp, setOtp] = useState("");
|
|
25
|
+
const [isVerifying, setIsVerifying] = useState(false);
|
|
26
|
+
const [isResending, setIsResending] = useState(false);
|
|
27
|
+
const [resendMessage, setResendMessage] = useState();
|
|
28
|
+
const [error, setError] = useState();
|
|
29
|
+
const handleVerify = async (e) => {
|
|
30
|
+
e.preventDefault();
|
|
31
|
+
if (!otp.trim() || otp.length < 6) {
|
|
32
|
+
setError("Please enter the 6-digit code");
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
setError(void 0);
|
|
36
|
+
setIsVerifying(true);
|
|
37
|
+
try {
|
|
38
|
+
const res = await authClient.emailOtp.verifyEmail({ email, otp });
|
|
39
|
+
console.log("[verify-email] response:", JSON.stringify(res?.data), "error:", JSON.stringify(res?.error));
|
|
40
|
+
if (res?.error) {
|
|
41
|
+
setError(res.error.message ?? "Invalid code. Please try again.");
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
onSuccess?.();
|
|
45
|
+
} catch (err) {
|
|
46
|
+
setError(err instanceof Error ? err.message : "Invalid code. Please try again.");
|
|
47
|
+
} finally {
|
|
48
|
+
setIsVerifying(false);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const handleResend = async () => {
|
|
52
|
+
if (!email) {
|
|
53
|
+
setError("Email address is not available. Please register again.");
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
setError(void 0);
|
|
57
|
+
setResendMessage(void 0);
|
|
58
|
+
setIsResending(true);
|
|
59
|
+
try {
|
|
60
|
+
await authClient.emailOtp.sendVerificationOtp({
|
|
61
|
+
email,
|
|
62
|
+
type: "email-verification"
|
|
63
|
+
});
|
|
64
|
+
setResendMessage("A new code has been sent to your inbox.");
|
|
65
|
+
} catch (err) {
|
|
66
|
+
setError(err instanceof Error ? err.message : "Failed to resend code.");
|
|
67
|
+
} finally {
|
|
68
|
+
setIsResending(false);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-8", children: [
|
|
72
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
73
|
+
/* @__PURE__ */ jsx("h1", { className: "text-2xl font-bold tracking-tight", children: "Verify your email" }),
|
|
74
|
+
/* @__PURE__ */ jsx("p", { className: "mt-1 text-sm text-muted-foreground", children: email ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
75
|
+
"Enter the 6-digit code sent to",
|
|
76
|
+
" ",
|
|
77
|
+
/* @__PURE__ */ jsx("span", { className: "font-medium text-foreground", children: email })
|
|
78
|
+
] }) : "Enter the 6-digit code sent to your email" })
|
|
79
|
+
] }),
|
|
80
|
+
error && /* @__PURE__ */ jsx("div", { className: "rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-xs text-destructive", children: error }),
|
|
81
|
+
resendMessage && /* @__PURE__ */ jsx("div", { className: "rounded-lg border border-green-200 bg-green-50 px-3 py-2 text-xs text-green-700", children: resendMessage }),
|
|
82
|
+
/* @__PURE__ */ jsxs("form", { onSubmit: handleVerify, className: "space-y-4", noValidate: true, children: [
|
|
83
|
+
/* @__PURE__ */ jsx(
|
|
84
|
+
"input",
|
|
85
|
+
{
|
|
86
|
+
type: "text",
|
|
87
|
+
inputMode: "numeric",
|
|
88
|
+
pattern: "[0-9]*",
|
|
89
|
+
maxLength: 6,
|
|
90
|
+
value: otp,
|
|
91
|
+
onChange: (e) => setOtp(e.target.value.replace(/\D/g, "")),
|
|
92
|
+
placeholder: "000000",
|
|
93
|
+
required: true,
|
|
94
|
+
disabled: isVerifying,
|
|
95
|
+
autoComplete: "one-time-code",
|
|
96
|
+
className: "flex h-12 w-full rounded-md border border-input bg-background px-3 py-2 text-center text-lg tracking-[0.4em] font-mono ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50 disabled:cursor-not-allowed"
|
|
97
|
+
}
|
|
98
|
+
),
|
|
99
|
+
/* @__PURE__ */ jsx(
|
|
100
|
+
"button",
|
|
101
|
+
{
|
|
102
|
+
type: "submit",
|
|
103
|
+
disabled: isVerifying || otp.length < 6,
|
|
104
|
+
className: "inline-flex h-11 w-full items-center justify-center rounded-md bg-primary px-4 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:pointer-events-none disabled:opacity-50",
|
|
105
|
+
children: isVerifying ? "Verifying..." : "Verify email"
|
|
106
|
+
}
|
|
107
|
+
),
|
|
108
|
+
/* @__PURE__ */ jsx(
|
|
109
|
+
"button",
|
|
110
|
+
{
|
|
111
|
+
type: "button",
|
|
112
|
+
onClick: handleResend,
|
|
113
|
+
disabled: isResending,
|
|
114
|
+
className: "inline-flex h-11 w-full items-center justify-center rounded-md border border-input bg-background px-4 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground disabled:pointer-events-none disabled:opacity-50",
|
|
115
|
+
children: isResending ? "Sending..." : "Resend code"
|
|
116
|
+
}
|
|
117
|
+
)
|
|
118
|
+
] }),
|
|
119
|
+
/* @__PURE__ */ jsxs("p", { className: "text-center text-sm text-muted-foreground", children: [
|
|
120
|
+
"Already verified?",
|
|
121
|
+
" ",
|
|
122
|
+
/* @__PURE__ */ jsx(
|
|
123
|
+
"a",
|
|
124
|
+
{
|
|
125
|
+
href: "/login",
|
|
126
|
+
className: "font-medium text-foreground underline underline-offset-4 hover:text-foreground/80",
|
|
127
|
+
children: "Sign in"
|
|
128
|
+
}
|
|
129
|
+
)
|
|
130
|
+
] })
|
|
131
|
+
] });
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/components/forgot-password-form.tsx
|
|
135
|
+
import { useState as useState2 } from "react";
|
|
136
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
137
|
+
function ForgotPasswordForm({
|
|
138
|
+
onSuccess,
|
|
139
|
+
loginUrl = "/login",
|
|
140
|
+
authClient
|
|
141
|
+
}) {
|
|
142
|
+
const [email, setEmail] = useState2("");
|
|
143
|
+
const [error, setError] = useState2();
|
|
144
|
+
const [isPending, setIsPending] = useState2(false);
|
|
145
|
+
const handleSubmit = async (e) => {
|
|
146
|
+
e.preventDefault();
|
|
147
|
+
if (!email.trim()) {
|
|
148
|
+
setError("Please enter your email address");
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
setError(void 0);
|
|
152
|
+
setIsPending(true);
|
|
153
|
+
try {
|
|
154
|
+
const res = await authClient.emailOtp.sendVerificationOtp({
|
|
155
|
+
email,
|
|
156
|
+
type: "forget-password"
|
|
157
|
+
});
|
|
158
|
+
if (res?.error) {
|
|
159
|
+
setError(res.error.message ?? "Failed to send reset code");
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
onSuccess?.(email);
|
|
163
|
+
} catch (err) {
|
|
164
|
+
setError(err instanceof Error ? err.message : "Failed to send reset code");
|
|
165
|
+
} finally {
|
|
166
|
+
setIsPending(false);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
return /* @__PURE__ */ jsxs2("div", { className: "space-y-8", children: [
|
|
170
|
+
/* @__PURE__ */ jsxs2("div", { children: [
|
|
171
|
+
/* @__PURE__ */ jsx2("h1", { className: "text-2xl font-bold tracking-tight", children: "Forgot your password?" }),
|
|
172
|
+
/* @__PURE__ */ jsx2("p", { className: "mt-1 text-sm text-muted-foreground", children: "Enter your email address and we'll send you a code to reset your password." })
|
|
173
|
+
] }),
|
|
174
|
+
error && /* @__PURE__ */ jsx2("div", { className: "rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-xs text-destructive", children: error }),
|
|
175
|
+
/* @__PURE__ */ jsxs2("form", { onSubmit: handleSubmit, className: "space-y-4", noValidate: true, children: [
|
|
176
|
+
/* @__PURE__ */ jsx2(
|
|
177
|
+
"input",
|
|
178
|
+
{
|
|
179
|
+
type: "email",
|
|
180
|
+
value: email,
|
|
181
|
+
onChange: (e) => setEmail(e.target.value),
|
|
182
|
+
placeholder: "Email address",
|
|
183
|
+
required: true,
|
|
184
|
+
disabled: isPending,
|
|
185
|
+
autoComplete: "email",
|
|
186
|
+
className: "flex h-11 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50 disabled:cursor-not-allowed"
|
|
187
|
+
}
|
|
188
|
+
),
|
|
189
|
+
/* @__PURE__ */ jsx2(
|
|
190
|
+
"button",
|
|
191
|
+
{
|
|
192
|
+
type: "submit",
|
|
193
|
+
disabled: isPending || !email.trim(),
|
|
194
|
+
className: "inline-flex h-11 w-full items-center justify-center rounded-md bg-primary px-4 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:pointer-events-none disabled:opacity-50",
|
|
195
|
+
children: isPending ? "Sending..." : "Send reset code"
|
|
196
|
+
}
|
|
197
|
+
)
|
|
198
|
+
] }),
|
|
199
|
+
/* @__PURE__ */ jsxs2("p", { className: "text-center text-sm text-muted-foreground", children: [
|
|
200
|
+
"Remember your password?",
|
|
201
|
+
" ",
|
|
202
|
+
/* @__PURE__ */ jsx2(
|
|
203
|
+
"a",
|
|
204
|
+
{
|
|
205
|
+
href: loginUrl,
|
|
206
|
+
className: "font-medium text-foreground underline underline-offset-4 hover:text-foreground/80",
|
|
207
|
+
children: "Sign in"
|
|
208
|
+
}
|
|
209
|
+
)
|
|
210
|
+
] })
|
|
211
|
+
] });
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// src/components/reset-password-form.tsx
|
|
215
|
+
import { useState as useState3 } from "react";
|
|
216
|
+
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
217
|
+
function ResetPasswordForm({
|
|
218
|
+
email,
|
|
219
|
+
onSuccess,
|
|
220
|
+
loginUrl = "/login",
|
|
221
|
+
authClient
|
|
222
|
+
}) {
|
|
223
|
+
const [otp, setOtp] = useState3("");
|
|
224
|
+
const [password, setPassword] = useState3("");
|
|
225
|
+
const [confirmPassword, setConfirmPassword] = useState3("");
|
|
226
|
+
const [error, setError] = useState3();
|
|
227
|
+
const [isResetting, setIsResetting] = useState3(false);
|
|
228
|
+
const [isResending, setIsResending] = useState3(false);
|
|
229
|
+
const [resendMessage, setResendMessage] = useState3();
|
|
230
|
+
const handleSubmit = async (e) => {
|
|
231
|
+
e.preventDefault();
|
|
232
|
+
if (!otp.trim() || otp.length < 6) {
|
|
233
|
+
setError("Please enter the 6-digit code");
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
if (password.length < 8) {
|
|
237
|
+
setError("Password must be at least 8 characters");
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
if (password !== confirmPassword) {
|
|
241
|
+
setError("Passwords do not match");
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
setError(void 0);
|
|
245
|
+
setIsResetting(true);
|
|
246
|
+
try {
|
|
247
|
+
const res = await fetch("/api/auth/email-otp/reset-password", {
|
|
248
|
+
method: "POST",
|
|
249
|
+
headers: { "Content-Type": "application/json" },
|
|
250
|
+
body: JSON.stringify({ email, otp, password })
|
|
251
|
+
});
|
|
252
|
+
if (!res.ok) {
|
|
253
|
+
const body = await res.json().catch(() => null);
|
|
254
|
+
setError(body?.message ?? "Failed to reset password");
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
onSuccess?.();
|
|
258
|
+
} catch (err) {
|
|
259
|
+
setError(
|
|
260
|
+
err instanceof Error ? err.message : "Failed to reset password"
|
|
261
|
+
);
|
|
262
|
+
} finally {
|
|
263
|
+
setIsResetting(false);
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
const handleResend = async () => {
|
|
267
|
+
setError(void 0);
|
|
268
|
+
setResendMessage(void 0);
|
|
269
|
+
setIsResending(true);
|
|
270
|
+
try {
|
|
271
|
+
await authClient.emailOtp.sendVerificationOtp({
|
|
272
|
+
email,
|
|
273
|
+
type: "forget-password"
|
|
274
|
+
});
|
|
275
|
+
setResendMessage("A new code has been sent to your inbox.");
|
|
276
|
+
} catch (err) {
|
|
277
|
+
setError(err instanceof Error ? err.message : "Failed to resend code.");
|
|
278
|
+
} finally {
|
|
279
|
+
setIsResending(false);
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
return /* @__PURE__ */ jsxs3("div", { className: "space-y-8", children: [
|
|
283
|
+
/* @__PURE__ */ jsxs3("div", { children: [
|
|
284
|
+
/* @__PURE__ */ jsx3("h1", { className: "text-2xl font-bold tracking-tight", children: "Reset your password" }),
|
|
285
|
+
/* @__PURE__ */ jsxs3("p", { className: "mt-1 text-sm text-muted-foreground", children: [
|
|
286
|
+
"Enter the 6-digit code sent to",
|
|
287
|
+
" ",
|
|
288
|
+
/* @__PURE__ */ jsx3("span", { className: "font-medium text-foreground", children: email }),
|
|
289
|
+
" and your new password."
|
|
290
|
+
] })
|
|
291
|
+
] }),
|
|
292
|
+
error && /* @__PURE__ */ jsx3("div", { className: "rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-xs text-destructive", children: error }),
|
|
293
|
+
resendMessage && /* @__PURE__ */ jsx3("div", { className: "rounded-lg border border-green-200 bg-green-50 px-3 py-2 text-xs text-green-700", children: resendMessage }),
|
|
294
|
+
/* @__PURE__ */ jsxs3("form", { onSubmit: handleSubmit, className: "space-y-4", noValidate: true, children: [
|
|
295
|
+
/* @__PURE__ */ jsx3(
|
|
296
|
+
"input",
|
|
297
|
+
{
|
|
298
|
+
type: "text",
|
|
299
|
+
inputMode: "numeric",
|
|
300
|
+
pattern: "[0-9]*",
|
|
301
|
+
maxLength: 6,
|
|
302
|
+
value: otp,
|
|
303
|
+
onChange: (e) => setOtp(e.target.value.replace(/\D/g, "")),
|
|
304
|
+
placeholder: "000000",
|
|
305
|
+
required: true,
|
|
306
|
+
disabled: isResetting,
|
|
307
|
+
autoComplete: "one-time-code",
|
|
308
|
+
className: "flex h-12 w-full rounded-md border border-input bg-background px-3 py-2 text-center text-lg tracking-[0.4em] font-mono ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50 disabled:cursor-not-allowed"
|
|
309
|
+
}
|
|
310
|
+
),
|
|
311
|
+
/* @__PURE__ */ jsx3(
|
|
312
|
+
"input",
|
|
313
|
+
{
|
|
314
|
+
type: "password",
|
|
315
|
+
value: password,
|
|
316
|
+
onChange: (e) => setPassword(e.target.value),
|
|
317
|
+
placeholder: "New password",
|
|
318
|
+
required: true,
|
|
319
|
+
disabled: isResetting,
|
|
320
|
+
autoComplete: "new-password",
|
|
321
|
+
className: "flex h-11 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50 disabled:cursor-not-allowed"
|
|
322
|
+
}
|
|
323
|
+
),
|
|
324
|
+
/* @__PURE__ */ jsx3(
|
|
325
|
+
"input",
|
|
326
|
+
{
|
|
327
|
+
type: "password",
|
|
328
|
+
value: confirmPassword,
|
|
329
|
+
onChange: (e) => setConfirmPassword(e.target.value),
|
|
330
|
+
placeholder: "Confirm new password",
|
|
331
|
+
required: true,
|
|
332
|
+
disabled: isResetting,
|
|
333
|
+
autoComplete: "new-password",
|
|
334
|
+
className: "flex h-11 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50 disabled:cursor-not-allowed"
|
|
335
|
+
}
|
|
336
|
+
),
|
|
337
|
+
/* @__PURE__ */ jsx3(
|
|
338
|
+
"button",
|
|
339
|
+
{
|
|
340
|
+
type: "submit",
|
|
341
|
+
disabled: isResetting || otp.length < 6 || !password,
|
|
342
|
+
className: "inline-flex h-11 w-full items-center justify-center rounded-md bg-primary px-4 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:pointer-events-none disabled:opacity-50",
|
|
343
|
+
children: isResetting ? "Resetting..." : "Reset password"
|
|
344
|
+
}
|
|
345
|
+
),
|
|
346
|
+
/* @__PURE__ */ jsx3(
|
|
347
|
+
"button",
|
|
348
|
+
{
|
|
349
|
+
type: "button",
|
|
350
|
+
onClick: handleResend,
|
|
351
|
+
disabled: isResending,
|
|
352
|
+
className: "inline-flex h-11 w-full items-center justify-center rounded-md border border-input bg-background px-4 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground disabled:pointer-events-none disabled:opacity-50",
|
|
353
|
+
children: isResending ? "Sending..." : "Resend code"
|
|
354
|
+
}
|
|
355
|
+
)
|
|
356
|
+
] }),
|
|
357
|
+
/* @__PURE__ */ jsxs3("p", { className: "text-center text-sm text-muted-foreground", children: [
|
|
358
|
+
"Remember your password?",
|
|
359
|
+
" ",
|
|
360
|
+
/* @__PURE__ */ jsx3(
|
|
361
|
+
"a",
|
|
362
|
+
{
|
|
363
|
+
href: loginUrl,
|
|
364
|
+
className: "font-medium text-foreground underline underline-offset-4 hover:text-foreground/80",
|
|
365
|
+
children: "Sign in"
|
|
366
|
+
}
|
|
367
|
+
)
|
|
368
|
+
] })
|
|
369
|
+
] });
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// src/components/auth-layout.tsx
|
|
373
|
+
import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
374
|
+
function AuthLayout({
|
|
375
|
+
logo,
|
|
376
|
+
title,
|
|
377
|
+
subtitle,
|
|
378
|
+
children,
|
|
379
|
+
footer
|
|
380
|
+
}) {
|
|
381
|
+
return /* @__PURE__ */ jsx4("div", { className: "flex min-h-screen items-center justify-center bg-background", children: /* @__PURE__ */ jsxs4("div", { className: "w-full max-w-md", children: [
|
|
382
|
+
/* @__PURE__ */ jsxs4("div", { className: "mb-10 text-center", children: [
|
|
383
|
+
logo && /* @__PURE__ */ jsx4("div", { className: "mb-6 flex justify-center", children: logo }),
|
|
384
|
+
/* @__PURE__ */ jsx4("h1", { className: "text-[32px] font-light tracking-tight", children: title }),
|
|
385
|
+
subtitle && /* @__PURE__ */ jsx4("p", { className: "mt-2 text-sm text-muted-foreground", children: subtitle })
|
|
386
|
+
] }),
|
|
387
|
+
/* @__PURE__ */ jsx4("div", { className: "rounded-xl border bg-card p-8 shadow-sm", children }),
|
|
388
|
+
footer && /* @__PURE__ */ jsx4("div", { className: "mt-6 text-center text-xs text-muted-foreground", children: footer })
|
|
389
|
+
] }) });
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// src/components/invitation-notice.tsx
|
|
393
|
+
import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
394
|
+
function defaultSupportEmail() {
|
|
395
|
+
if (typeof window === "undefined") return void 0;
|
|
396
|
+
const host = window.location.hostname;
|
|
397
|
+
if (!host || host === "localhost" || /^[\d.]+$/.test(host)) return void 0;
|
|
398
|
+
const apex = host.split(".").slice(-2).join(".");
|
|
399
|
+
return `contact@${apex}`;
|
|
400
|
+
}
|
|
401
|
+
var REASON_MESSAGE = {
|
|
402
|
+
expired: "Cette invitation a expir\xE9.",
|
|
403
|
+
claimed: "Cette invitation a d\xE9j\xE0 \xE9t\xE9 utilis\xE9e.",
|
|
404
|
+
unknown: "Ce lien d'invitation n'est pas valide."
|
|
405
|
+
};
|
|
406
|
+
function InvitationNotice({
|
|
407
|
+
reason = "unknown",
|
|
408
|
+
supportEmail,
|
|
409
|
+
title = "Invitation indisponible",
|
|
410
|
+
action
|
|
411
|
+
}) {
|
|
412
|
+
const contact = supportEmail ?? defaultSupportEmail();
|
|
413
|
+
return /* @__PURE__ */ jsxs5("div", { className: "space-y-8", children: [
|
|
414
|
+
/* @__PURE__ */ jsxs5("div", { children: [
|
|
415
|
+
/* @__PURE__ */ jsx5("h1", { className: "text-2xl font-bold tracking-tight", children: title }),
|
|
416
|
+
/* @__PURE__ */ jsx5("p", { className: "mt-1 text-sm text-muted-foreground", children: REASON_MESSAGE[reason] ?? REASON_MESSAGE.unknown })
|
|
417
|
+
] }),
|
|
418
|
+
contact ? /* @__PURE__ */ jsxs5("p", { className: "text-sm text-muted-foreground", children: [
|
|
419
|
+
"\xC9crivez-nous \xE0",
|
|
420
|
+
" ",
|
|
421
|
+
/* @__PURE__ */ jsx5(
|
|
422
|
+
"a",
|
|
423
|
+
{
|
|
424
|
+
href: `mailto:${contact}`,
|
|
425
|
+
className: "font-medium text-foreground underline underline-offset-4 hover:text-foreground/80",
|
|
426
|
+
children: contact
|
|
427
|
+
}
|
|
428
|
+
),
|
|
429
|
+
" ",
|
|
430
|
+
"pour en recevoir une nouvelle."
|
|
431
|
+
] }) : null,
|
|
432
|
+
action
|
|
433
|
+
] });
|
|
434
|
+
}
|
|
435
|
+
export {
|
|
436
|
+
AuthLayout,
|
|
437
|
+
ForgotPasswordForm,
|
|
438
|
+
InvitationNotice,
|
|
439
|
+
ResetPasswordForm,
|
|
440
|
+
VerifyEmailForm,
|
|
441
|
+
isInvitationFailure,
|
|
442
|
+
useLogout,
|
|
443
|
+
useSession
|
|
444
|
+
};
|
|
445
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-session.ts","../src/components/verify-email-form.tsx","../src/components/forgot-password-form.tsx","../src/components/reset-password-form.tsx","../src/components/auth-layout.tsx","../src/components/invitation-notice.tsx"],"sourcesContent":["import type { PlatformAuthClient } from \"../client\"\n\n/**\n * Returns a useSession hook bound to the given auth client.\n * Usage: const { data: session, isPending } = useSession(authClient)\n */\nexport function useSession(authClient: PlatformAuthClient) {\n return authClient.useSession()\n}\n\n/**\n * Returns a logout function bound to the given auth client.\n * Usage: const logout = useLogout(authClient)\n */\nexport function useLogout(authClient: PlatformAuthClient) {\n const signOut = async () => {\n await authClient.signOut()\n }\n return signOut\n}\n","import { useState, type FormEvent } from \"react\"\nimport type { VerifyEmailFormProps } from \"../types\"\n\nexport function VerifyEmailForm({\n email,\n onSuccess,\n authClient,\n}: VerifyEmailFormProps) {\n const [otp, setOtp] = useState(\"\")\n const [isVerifying, setIsVerifying] = useState(false)\n const [isResending, setIsResending] = useState(false)\n const [resendMessage, setResendMessage] = useState<string | undefined>()\n const [error, setError] = useState<string | undefined>()\n\n const handleVerify = async (e: FormEvent) => {\n e.preventDefault()\n if (!otp.trim() || otp.length < 6) {\n setError(\"Please enter the 6-digit code\")\n return\n }\n setError(undefined)\n setIsVerifying(true)\n try {\n const res = await authClient.emailOtp.verifyEmail({ email, otp })\n console.log(\"[verify-email] response:\", JSON.stringify(res?.data), \"error:\", JSON.stringify(res?.error))\n if (res?.error) {\n setError(res.error.message ?? \"Invalid code. Please try again.\")\n return\n }\n onSuccess?.()\n } catch (err) {\n setError(err instanceof Error ? err.message : \"Invalid code. Please try again.\")\n } finally {\n setIsVerifying(false)\n }\n }\n\n const handleResend = async () => {\n if (!email) {\n setError(\"Email address is not available. Please register again.\")\n return\n }\n setError(undefined)\n setResendMessage(undefined)\n setIsResending(true)\n try {\n await authClient.emailOtp.sendVerificationOtp({\n email,\n type: \"email-verification\",\n })\n setResendMessage(\"A new code has been sent to your inbox.\")\n } catch (err) {\n setError(err instanceof Error ? err.message : \"Failed to resend code.\")\n } finally {\n setIsResending(false)\n }\n }\n\n return (\n <div className=\"space-y-8\">\n <div>\n <h1 className=\"text-2xl font-bold tracking-tight\">\n Verify your email\n </h1>\n <p className=\"mt-1 text-sm text-muted-foreground\">\n {email ? (\n <>\n Enter the 6-digit code sent to{\" \"}\n <span className=\"font-medium text-foreground\">{email}</span>\n </>\n ) : (\n \"Enter the 6-digit code sent to your email\"\n )}\n </p>\n </div>\n\n {error && (\n <div className=\"rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-xs text-destructive\">\n {error}\n </div>\n )}\n\n {resendMessage && (\n <div className=\"rounded-lg border border-green-200 bg-green-50 px-3 py-2 text-xs text-green-700\">\n {resendMessage}\n </div>\n )}\n\n <form onSubmit={handleVerify} className=\"space-y-4\" noValidate>\n <input\n type=\"text\"\n inputMode=\"numeric\"\n pattern=\"[0-9]*\"\n maxLength={6}\n value={otp}\n onChange={(e) => setOtp(e.target.value.replace(/\\D/g, \"\"))}\n placeholder=\"000000\"\n required\n disabled={isVerifying}\n autoComplete=\"one-time-code\"\n className=\"flex h-12 w-full rounded-md border border-input bg-background px-3 py-2 text-center text-lg tracking-[0.4em] font-mono ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50 disabled:cursor-not-allowed\"\n />\n\n <button\n type=\"submit\"\n disabled={isVerifying || otp.length < 6}\n className=\"inline-flex h-11 w-full items-center justify-center rounded-md bg-primary px-4 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:pointer-events-none disabled:opacity-50\"\n >\n {isVerifying ? \"Verifying...\" : \"Verify email\"}\n </button>\n\n <button\n type=\"button\"\n onClick={handleResend}\n disabled={isResending}\n className=\"inline-flex h-11 w-full items-center justify-center rounded-md border border-input bg-background px-4 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground disabled:pointer-events-none disabled:opacity-50\"\n >\n {isResending ? \"Sending...\" : \"Resend code\"}\n </button>\n </form>\n\n <p className=\"text-center text-sm text-muted-foreground\">\n Already verified?{\" \"}\n <a\n href=\"/login\"\n className=\"font-medium text-foreground underline underline-offset-4 hover:text-foreground/80\"\n >\n Sign in\n </a>\n </p>\n </div>\n )\n}\n","import { useState, type FormEvent } from \"react\"\nimport type { ForgotPasswordFormProps } from \"../types\"\n\nexport function ForgotPasswordForm({\n onSuccess,\n loginUrl = \"/login\",\n authClient,\n}: ForgotPasswordFormProps) {\n const [email, setEmail] = useState(\"\")\n const [error, setError] = useState<string | undefined>()\n const [isPending, setIsPending] = useState(false)\n\n const handleSubmit = async (e: FormEvent) => {\n e.preventDefault()\n if (!email.trim()) {\n setError(\"Please enter your email address\")\n return\n }\n setError(undefined)\n setIsPending(true)\n try {\n const res = await authClient.emailOtp.sendVerificationOtp({\n email,\n type: \"forget-password\",\n })\n if (res?.error) {\n setError(res.error.message ?? \"Failed to send reset code\")\n return\n }\n onSuccess?.(email)\n } catch (err) {\n setError(err instanceof Error ? err.message : \"Failed to send reset code\")\n } finally {\n setIsPending(false)\n }\n }\n\n return (\n <div className=\"space-y-8\">\n <div>\n <h1 className=\"text-2xl font-bold tracking-tight\">\n Forgot your password?\n </h1>\n <p className=\"mt-1 text-sm text-muted-foreground\">\n Enter your email address and we'll send you a code to reset your\n password.\n </p>\n </div>\n\n {error && (\n <div className=\"rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-xs text-destructive\">\n {error}\n </div>\n )}\n\n <form onSubmit={handleSubmit} className=\"space-y-4\" noValidate>\n <input\n type=\"email\"\n value={email}\n onChange={(e) => setEmail(e.target.value)}\n placeholder=\"Email address\"\n required\n disabled={isPending}\n autoComplete=\"email\"\n className=\"flex h-11 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50 disabled:cursor-not-allowed\"\n />\n\n <button\n type=\"submit\"\n disabled={isPending || !email.trim()}\n className=\"inline-flex h-11 w-full items-center justify-center rounded-md bg-primary px-4 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:pointer-events-none disabled:opacity-50\"\n >\n {isPending ? \"Sending...\" : \"Send reset code\"}\n </button>\n </form>\n\n <p className=\"text-center text-sm text-muted-foreground\">\n Remember your password?{\" \"}\n <a\n href={loginUrl}\n className=\"font-medium text-foreground underline underline-offset-4 hover:text-foreground/80\"\n >\n Sign in\n </a>\n </p>\n </div>\n )\n}\n","import { useState, type FormEvent } from \"react\"\nimport type { ResetPasswordFormProps } from \"../types\"\n\nexport function ResetPasswordForm({\n email,\n onSuccess,\n loginUrl = \"/login\",\n authClient,\n}: ResetPasswordFormProps) {\n const [otp, setOtp] = useState(\"\")\n const [password, setPassword] = useState(\"\")\n const [confirmPassword, setConfirmPassword] = useState(\"\")\n const [error, setError] = useState<string | undefined>()\n const [isResetting, setIsResetting] = useState(false)\n const [isResending, setIsResending] = useState(false)\n const [resendMessage, setResendMessage] = useState<string | undefined>()\n\n const handleSubmit = async (e: FormEvent) => {\n e.preventDefault()\n if (!otp.trim() || otp.length < 6) {\n setError(\"Please enter the 6-digit code\")\n return\n }\n if (password.length < 8) {\n setError(\"Password must be at least 8 characters\")\n return\n }\n if (password !== confirmPassword) {\n setError(\"Passwords do not match\")\n return\n }\n setError(undefined)\n setIsResetting(true)\n try {\n const res = await fetch(\"/api/auth/email-otp/reset-password\", {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ email, otp, password }),\n })\n if (!res.ok) {\n const body = await res.json().catch(() => null)\n setError(body?.message ?? \"Failed to reset password\")\n return\n }\n onSuccess?.()\n } catch (err) {\n setError(\n err instanceof Error ? err.message : \"Failed to reset password\",\n )\n } finally {\n setIsResetting(false)\n }\n }\n\n const handleResend = async () => {\n setError(undefined)\n setResendMessage(undefined)\n setIsResending(true)\n try {\n await authClient.emailOtp.sendVerificationOtp({\n email,\n type: \"forget-password\",\n })\n setResendMessage(\"A new code has been sent to your inbox.\")\n } catch (err) {\n setError(err instanceof Error ? err.message : \"Failed to resend code.\")\n } finally {\n setIsResending(false)\n }\n }\n\n return (\n <div className=\"space-y-8\">\n <div>\n <h1 className=\"text-2xl font-bold tracking-tight\">\n Reset your password\n </h1>\n <p className=\"mt-1 text-sm text-muted-foreground\">\n Enter the 6-digit code sent to{\" \"}\n <span className=\"font-medium text-foreground\">{email}</span> and your\n new password.\n </p>\n </div>\n\n {error && (\n <div className=\"rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-xs text-destructive\">\n {error}\n </div>\n )}\n\n {resendMessage && (\n <div className=\"rounded-lg border border-green-200 bg-green-50 px-3 py-2 text-xs text-green-700\">\n {resendMessage}\n </div>\n )}\n\n <form onSubmit={handleSubmit} className=\"space-y-4\" noValidate>\n <input\n type=\"text\"\n inputMode=\"numeric\"\n pattern=\"[0-9]*\"\n maxLength={6}\n value={otp}\n onChange={(e) => setOtp(e.target.value.replace(/\\D/g, \"\"))}\n placeholder=\"000000\"\n required\n disabled={isResetting}\n autoComplete=\"one-time-code\"\n className=\"flex h-12 w-full rounded-md border border-input bg-background px-3 py-2 text-center text-lg tracking-[0.4em] font-mono ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50 disabled:cursor-not-allowed\"\n />\n\n <input\n type=\"password\"\n value={password}\n onChange={(e) => setPassword(e.target.value)}\n placeholder=\"New password\"\n required\n disabled={isResetting}\n autoComplete=\"new-password\"\n className=\"flex h-11 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50 disabled:cursor-not-allowed\"\n />\n\n <input\n type=\"password\"\n value={confirmPassword}\n onChange={(e) => setConfirmPassword(e.target.value)}\n placeholder=\"Confirm new password\"\n required\n disabled={isResetting}\n autoComplete=\"new-password\"\n className=\"flex h-11 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50 disabled:cursor-not-allowed\"\n />\n\n <button\n type=\"submit\"\n disabled={isResetting || otp.length < 6 || !password}\n className=\"inline-flex h-11 w-full items-center justify-center rounded-md bg-primary px-4 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:pointer-events-none disabled:opacity-50\"\n >\n {isResetting ? \"Resetting...\" : \"Reset password\"}\n </button>\n\n <button\n type=\"button\"\n onClick={handleResend}\n disabled={isResending}\n className=\"inline-flex h-11 w-full items-center justify-center rounded-md border border-input bg-background px-4 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground disabled:pointer-events-none disabled:opacity-50\"\n >\n {isResending ? \"Sending...\" : \"Resend code\"}\n </button>\n </form>\n\n <p className=\"text-center text-sm text-muted-foreground\">\n Remember your password?{\" \"}\n <a\n href={loginUrl}\n className=\"font-medium text-foreground underline underline-offset-4 hover:text-foreground/80\"\n >\n Sign in\n </a>\n </p>\n </div>\n )\n}\n","import type { AuthLayoutProps } from \"../types\"\n\nexport function AuthLayout({\n logo,\n title,\n subtitle,\n children,\n footer,\n}: AuthLayoutProps) {\n return (\n <div className=\"flex min-h-screen items-center justify-center bg-background\">\n <div className=\"w-full max-w-md\">\n <div className=\"mb-10 text-center\">\n {logo && <div className=\"mb-6 flex justify-center\">{logo}</div>}\n <h1 className=\"text-[32px] font-light tracking-tight\">{title}</h1>\n {subtitle && (\n <p className=\"mt-2 text-sm text-muted-foreground\">{subtitle}</p>\n )}\n </div>\n\n <div className=\"rounded-xl border bg-card p-8 shadow-sm\">\n {children}\n </div>\n\n {footer && (\n <div className=\"mt-6 text-center text-xs text-muted-foreground\">\n {footer}\n </div>\n )}\n </div>\n </div>\n )\n}\n","import type { InvitationNoticeProps } from \"../types\"\n\n/**\n * Every app is reachable at contact@ its own apex domain, so the address is\n * derived rather than configured. Sub-domains are stripped because the app is\n * routinely served from app./admin. while the mailbox lives on the apex;\n * multi-part public suffixes (.co.uk) would need a real suffix list and no app\n * using this is on one.\n */\nfunction defaultSupportEmail(): string | undefined {\n if (typeof window === \"undefined\") return undefined\n const host = window.location.hostname\n if (!host || host === \"localhost\" || /^[\\d.]+$/.test(host)) return undefined\n const apex = host.split(\".\").slice(-2).join(\".\")\n return `contact@${apex}`\n}\n\nconst REASON_MESSAGE: Record<string, string> = {\n expired: \"Cette invitation a expiré.\",\n claimed: \"Cette invitation a déjà été utilisée.\",\n unknown: \"Ce lien d'invitation n'est pas valide.\",\n}\n\n/**\n * What an invitee sees when their link does not work.\n *\n * It names the reason instead of merging the cases into one message: \"expired\"\n * tells someone their link was real and that asking for another one is worth\n * it, which \"invalid\" does not. Short TTLs make that distinction routine.\n *\n * The only way forward offered is a mailto, deliberately. A self-service\n * \"request a new invitation\" form would mean a public endpoint accepting dead\n * tokens, a queue to moderate, and a way to probe which tokens once existed —\n * for a flow where the operator already knows the person by name.\n */\nexport function InvitationNotice({\n reason = \"unknown\",\n supportEmail,\n title = \"Invitation indisponible\",\n action,\n}: InvitationNoticeProps) {\n const contact = supportEmail ?? defaultSupportEmail()\n\n return (\n <div className=\"space-y-8\">\n <div>\n <h1 className=\"text-2xl font-bold tracking-tight\">{title}</h1>\n <p className=\"mt-1 text-sm text-muted-foreground\">\n {REASON_MESSAGE[reason] ?? REASON_MESSAGE.unknown}\n </p>\n </div>\n\n {contact ? (\n <p className=\"text-sm text-muted-foreground\">\n Écrivez-nous à{\" \"}\n <a\n href={`mailto:${contact}`}\n className=\"font-medium text-foreground underline underline-offset-4 hover:text-foreground/80\"\n >\n {contact}\n </a>{\" \"}\n pour en recevoir une nouvelle.\n </p>\n ) : null}\n\n {action}\n </div>\n )\n}\n"],"mappings":";;;;;AAMO,SAAS,WAAW,YAAgC;AACzD,SAAO,WAAW,WAAW;AAC/B;AAMO,SAAS,UAAU,YAAgC;AACxD,QAAM,UAAU,YAAY;AAC1B,UAAM,WAAW,QAAQ;AAAA,EAC3B;AACA,SAAO;AACT;;;ACnBA,SAAS,gBAAgC;AA6DjC,SAKI,UALJ,KAKI,YALJ;AA1DD,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AACF,GAAyB;AACvB,QAAM,CAAC,KAAK,MAAM,IAAI,SAAS,EAAE;AACjC,QAAM,CAAC,aAAa,cAAc,IAAI,SAAS,KAAK;AACpD,QAAM,CAAC,aAAa,cAAc,IAAI,SAAS,KAAK;AACpD,QAAM,CAAC,eAAe,gBAAgB,IAAI,SAA6B;AACvE,QAAM,CAAC,OAAO,QAAQ,IAAI,SAA6B;AAEvD,QAAM,eAAe,OAAO,MAAiB;AAC3C,MAAE,eAAe;AACjB,QAAI,CAAC,IAAI,KAAK,KAAK,IAAI,SAAS,GAAG;AACjC,eAAS,+BAA+B;AACxC;AAAA,IACF;AACA,aAAS,MAAS;AAClB,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KEKNQkL.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* What became of a claim, in terms the invitee can be told.
|
|
5
|
+
*
|
|
6
|
+
* 'expired' and 'claimed' are kept apart from 'unknown' because only they say
|
|
7
|
+
* the offer was real, which is what tells someone that asking for a new link is
|
|
8
|
+
* worth it rather than doubting the address they were invited at. The three
|
|
9
|
+
* failures match InvitationFailure, so an outcome feeds InvitationNotice
|
|
10
|
+
* directly.
|
|
11
|
+
*/
|
|
12
|
+
type ClaimOutcome = "granted" | InvitationFailure | "failed";
|
|
13
|
+
interface ClaimInvitationOptions {
|
|
14
|
+
/** Absolute URL of the endpoint that redeems a token. */
|
|
15
|
+
endpoint: string;
|
|
16
|
+
token: string;
|
|
17
|
+
/** The account the app just created, which the grant is attached to. */
|
|
18
|
+
externalUserId: string;
|
|
19
|
+
/** Sent as the Authorization bearer — typically the app's API key. */
|
|
20
|
+
apiKey?: string;
|
|
21
|
+
/** Merged into the request body, for backends wanting more than the token. */
|
|
22
|
+
extra?: Record<string, unknown>;
|
|
23
|
+
/** Headers merged last, so a caller can pass a cookie-based credential. */
|
|
24
|
+
headers?: Record<string, string>;
|
|
25
|
+
/** Bounds the call so a slow API never stalls the sign-in response. */
|
|
26
|
+
timeoutMs?: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Redeems an invitation token for a user who has just signed in, turning the
|
|
30
|
+
* offer into a grant on their account.
|
|
31
|
+
*
|
|
32
|
+
* Why this belongs on the SERVER, on the auth callback rather than in the page:
|
|
33
|
+
* the invitation link lands on /register?invite=<token>, but the sign-up that
|
|
34
|
+
* follows can complete through any of three flows (password + OTP, OAuth
|
|
35
|
+
* redirect, email verification), and only two of them return to the page that
|
|
36
|
+
* held the token. Claiming where the session is established covers every flow
|
|
37
|
+
* with one code path.
|
|
38
|
+
*
|
|
39
|
+
* Best-effort by design: a sign-in must never fail because an invitation could
|
|
40
|
+
* not be redeemed. A failed claim leaves the invitation unclaimed and the user
|
|
41
|
+
* on their default tier — recoverable by following the link again, since a
|
|
42
|
+
* refused claim consumes nothing.
|
|
43
|
+
*/
|
|
44
|
+
declare function claimInvitation({ endpoint, token, externalUserId, apiKey, extra, headers, timeoutMs, }: ClaimInvitationOptions): Promise<ClaimOutcome>;
|
|
45
|
+
/**
|
|
46
|
+
* Extracts the invitation token from an auth request.
|
|
47
|
+
*
|
|
48
|
+
* The token lives on the page the invitee landed on (/register?invite=…), never
|
|
49
|
+
* on the auth endpoints themselves, so it has to be recovered from the request
|
|
50
|
+
* that completes the sign-up. Two sources, because no single one covers every
|
|
51
|
+
* flow: the URL, for the OAuth callback reached through a redirect whose query
|
|
52
|
+
* string the app controls; and the Referer, for the password and OTP flows,
|
|
53
|
+
* which are XHR calls issued BY that page and therefore carry it.
|
|
54
|
+
*
|
|
55
|
+
* Reading it per-request keeps the claim stateless: nothing associates a
|
|
56
|
+
* browser with a pending invitation, and a request with no token claims
|
|
57
|
+
* nothing. A malformed Referer is ignored rather than thrown on — it is
|
|
58
|
+
* attacker-controlled input on a best-effort path.
|
|
59
|
+
*/
|
|
60
|
+
declare function inviteTokenFrom(request: Request, param?: string): string | null;
|
|
61
|
+
/**
|
|
62
|
+
* Whether this request is the one that just created a usable account — the
|
|
63
|
+
* moment to provision, claim an invitation, or greet someone. Matching on the
|
|
64
|
+
* path rather than on a response body keeps it flow-agnostic: the three
|
|
65
|
+
* sign-up flows return three different shapes.
|
|
66
|
+
*/
|
|
67
|
+
declare function completesSignup(pathname: string): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Carries a failed claim to the next page. The claim happens inside an auth
|
|
70
|
+
* response nobody renders, so its result would otherwise reach only the server
|
|
71
|
+
* log — leaving an invitee on the default tier with no idea their link had
|
|
72
|
+
* lapsed. Short-lived and readable by the page, which reports it and clears it.
|
|
73
|
+
*/
|
|
74
|
+
declare function invitationOutcomeCookie(outcome: ClaimOutcome, name?: string): string;
|
|
75
|
+
/**
|
|
76
|
+
* Whether an outcome is one the invitee should be shown a reason for.
|
|
77
|
+
* 'failed' is excluded: it means the call did not complete, so the offer may
|
|
78
|
+
* still be good and telling someone their invitation is invalid would be wrong.
|
|
79
|
+
*/
|
|
80
|
+
declare function isInvitationFailure(outcome: ClaimOutcome): outcome is InvitationFailure;
|
|
81
|
+
|
|
82
|
+
export { type ClaimOutcome as C, type ClaimInvitationOptions as a, completesSignup as b, claimInvitation as c, invitationOutcomeCookie as d, inviteTokenFrom as e, isInvitationFailure as i };
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Auth, BetterAuthOptions } from 'better-auth';
|
|
2
|
+
import { b as PlatformAuthConfig } from './types-DKEKNQkL.js';
|
|
3
|
+
export { f as PlatformSession, g as PlatformSessionData, h as PlatformUser } from './types-DKEKNQkL.js';
|
|
4
|
+
export { a as ClaimInvitationOptions, C as ClaimOutcome, c as claimInvitation, b as completesSignup, d as invitationOutcomeCookie, e as inviteTokenFrom, i as isInvitationFailure } from './invitation-DIZAb2BJ.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Creates a Better Auth instance with platform defaults.
|
|
8
|
+
* Each app calls this with its own config (DB, secret, providers, plugins).
|
|
9
|
+
*/
|
|
10
|
+
declare function createPlatformAuth(config: PlatformAuthConfig): Auth<BetterAuthOptions>;
|
|
11
|
+
type PlatformAuth = ReturnType<typeof createPlatformAuth>;
|
|
12
|
+
|
|
13
|
+
export { type PlatformAuth, createPlatformAuth };
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import {
|
|
2
|
+
claimInvitation,
|
|
3
|
+
completesSignup,
|
|
4
|
+
invitationOutcomeCookie,
|
|
5
|
+
inviteTokenFrom,
|
|
6
|
+
isInvitationFailure
|
|
7
|
+
} from "./chunk-73BHM4PZ.js";
|
|
8
|
+
|
|
9
|
+
// src/server.ts
|
|
10
|
+
import { betterAuth, APIError } from "better-auth";
|
|
11
|
+
import { emailOTP, admin } from "better-auth/plugins";
|
|
12
|
+
var DEFAULT_EMAIL_SUBJECTS = {
|
|
13
|
+
"email-verification": "Verify your account",
|
|
14
|
+
"forget-password": "Reset your password",
|
|
15
|
+
"sign-in": "Your sign-in code"
|
|
16
|
+
};
|
|
17
|
+
function defaultRenderOtpEmail(otp) {
|
|
18
|
+
return `
|
|
19
|
+
<div style="font-family:sans-serif;max-width:480px;margin:0 auto;padding:32px">
|
|
20
|
+
<h2 style="font-size:20px;font-weight:600;margin-bottom:16px">Your verification code</h2>
|
|
21
|
+
<p style="color:#555;margin-bottom:24px">Use the code below to continue. It expires in 5 minutes.</p>
|
|
22
|
+
<div style="background:#f5f5f5;border-radius:8px;padding:24px;text-align:center;letter-spacing:8px;font-size:32px;font-weight:700">
|
|
23
|
+
${otp}
|
|
24
|
+
</div>
|
|
25
|
+
<p style="color:#999;font-size:12px;margin-top:24px">If you didn't request this, you can safely ignore this email.</p>
|
|
26
|
+
</div>
|
|
27
|
+
`;
|
|
28
|
+
}
|
|
29
|
+
function createPlatformAuth(config) {
|
|
30
|
+
const {
|
|
31
|
+
database,
|
|
32
|
+
baseURL,
|
|
33
|
+
secret,
|
|
34
|
+
appName,
|
|
35
|
+
mailer,
|
|
36
|
+
google,
|
|
37
|
+
github,
|
|
38
|
+
plugins = [],
|
|
39
|
+
betaMode = false,
|
|
40
|
+
isInvited,
|
|
41
|
+
emailSubjects,
|
|
42
|
+
renderOtpEmail
|
|
43
|
+
} = config;
|
|
44
|
+
const subjects = { ...DEFAULT_EMAIL_SUBJECTS, ...emailSubjects };
|
|
45
|
+
const renderEmail = renderOtpEmail ?? defaultRenderOtpEmail;
|
|
46
|
+
return betterAuth({
|
|
47
|
+
database,
|
|
48
|
+
baseURL,
|
|
49
|
+
secret,
|
|
50
|
+
emailAndPassword: {
|
|
51
|
+
enabled: true,
|
|
52
|
+
requireEmailVerification: true
|
|
53
|
+
},
|
|
54
|
+
// Never auto-merge a social identity into an existing account by matching
|
|
55
|
+
// email. Better Auth links by default (email-verified providers are trusted),
|
|
56
|
+
// so signing in with Google/GitHub on an email already registered would fold
|
|
57
|
+
// that identity into the existing account. We keep each sign-in method its
|
|
58
|
+
// own account: a social login on a taken email is refused, not linked.
|
|
59
|
+
account: {
|
|
60
|
+
accountLinking: {
|
|
61
|
+
enabled: false
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
hooks: {
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
66
|
+
before: async (ctx) => {
|
|
67
|
+
if (!betaMode) return;
|
|
68
|
+
if (ctx.path !== "/sign-up/email") return;
|
|
69
|
+
const body = ctx.body;
|
|
70
|
+
const email = body?.email;
|
|
71
|
+
const inviteToken = body?.inviteToken;
|
|
72
|
+
if (email && inviteToken && isInvited) {
|
|
73
|
+
const ok = await isInvited(email, inviteToken);
|
|
74
|
+
if (ok) return;
|
|
75
|
+
}
|
|
76
|
+
throw new APIError("FORBIDDEN", {
|
|
77
|
+
message: "Registration is invite-only during the private beta."
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
plugins: [
|
|
82
|
+
emailOTP({
|
|
83
|
+
async sendVerificationOTP({ email, otp, type }) {
|
|
84
|
+
const subject = subjects[type] ? `${subjects[type]} - ${appName}` : `Your ${appName} code`;
|
|
85
|
+
const html = renderEmail(otp, type);
|
|
86
|
+
if (mailer) {
|
|
87
|
+
await mailer({
|
|
88
|
+
to: email,
|
|
89
|
+
subject,
|
|
90
|
+
html,
|
|
91
|
+
type,
|
|
92
|
+
otp
|
|
93
|
+
});
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
console.warn(
|
|
97
|
+
`[EMAIL] No mailer configured \u2014 logging OTP to stdout for ${email} (${type}): ${otp}`
|
|
98
|
+
);
|
|
99
|
+
},
|
|
100
|
+
otpLength: 6,
|
|
101
|
+
expiresIn: 300,
|
|
102
|
+
overrideDefaultEmailVerification: true
|
|
103
|
+
}),
|
|
104
|
+
admin(),
|
|
105
|
+
...plugins
|
|
106
|
+
// app-specific plugins (e.g. tanstackStartCookies)
|
|
107
|
+
],
|
|
108
|
+
socialProviders: {
|
|
109
|
+
...google ? {
|
|
110
|
+
google: {
|
|
111
|
+
clientId: google.clientId,
|
|
112
|
+
clientSecret: google.clientSecret
|
|
113
|
+
}
|
|
114
|
+
} : {},
|
|
115
|
+
...github ? {
|
|
116
|
+
github: {
|
|
117
|
+
clientId: github.clientId,
|
|
118
|
+
clientSecret: github.clientSecret
|
|
119
|
+
}
|
|
120
|
+
} : {}
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
export {
|
|
125
|
+
claimInvitation,
|
|
126
|
+
completesSignup,
|
|
127
|
+
createPlatformAuth,
|
|
128
|
+
invitationOutcomeCookie,
|
|
129
|
+
inviteTokenFrom,
|
|
130
|
+
isInvitationFailure
|
|
131
|
+
};
|
|
132
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +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 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 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 invitationOutcomeCookie,\n inviteTokenFrom,\n isInvitationFailure,\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,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AAEJ,QAAM,WAAW,EAAE,GAAG,wBAAwB,GAAG,cAAc;AAC/D,QA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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":[]}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { BetterAuthOptions } from 'better-auth';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Session user shape exposed by the platform auth instance.
|
|
5
|
+
*
|
|
6
|
+
* The instance returned by {@link createPlatformAuth} is widened to the base
|
|
7
|
+
* `Auth` type so the published `.d.ts` stays portable (inferring the full
|
|
8
|
+
* plugin-augmented type triggers TS2742). That widening hides the fields the
|
|
9
|
+
* email-otp/admin plugins add at runtime — notably `role` from `admin()`.
|
|
10
|
+
*
|
|
11
|
+
* This is the hand-maintained contract for what `api.getSession()` actually
|
|
12
|
+
* returns. Consumers cast the session to {@link PlatformSession} to read these
|
|
13
|
+
* fields with types. Keep it in sync with the enabled plugins.
|
|
14
|
+
*/
|
|
15
|
+
interface PlatformUser {
|
|
16
|
+
id: string;
|
|
17
|
+
email: string;
|
|
18
|
+
emailVerified: boolean;
|
|
19
|
+
name: string;
|
|
20
|
+
image?: string | null;
|
|
21
|
+
createdAt: Date;
|
|
22
|
+
updatedAt: Date;
|
|
23
|
+
/** From the admin() plugin. Absent until a role is assigned. */
|
|
24
|
+
role?: string | null;
|
|
25
|
+
/** From the admin() plugin. */
|
|
26
|
+
banned?: boolean | null;
|
|
27
|
+
}
|
|
28
|
+
interface PlatformSessionData {
|
|
29
|
+
id: string;
|
|
30
|
+
userId: string;
|
|
31
|
+
expiresAt: Date;
|
|
32
|
+
token: string;
|
|
33
|
+
createdAt: Date;
|
|
34
|
+
updatedAt: Date;
|
|
35
|
+
ipAddress?: string | null;
|
|
36
|
+
userAgent?: string | null;
|
|
37
|
+
}
|
|
38
|
+
/** Return shape of `auth.api.getSession()` for platform apps. */
|
|
39
|
+
interface PlatformSession {
|
|
40
|
+
user: PlatformUser;
|
|
41
|
+
session: PlatformSessionData;
|
|
42
|
+
}
|
|
43
|
+
type PlatformAuthMailerType = "email-verification" | "forget-password" | "sign-in" | "change-email";
|
|
44
|
+
interface PlatformAuthMailerArgs {
|
|
45
|
+
/** Recipient address */
|
|
46
|
+
to: string;
|
|
47
|
+
/** Pre-rendered subject line */
|
|
48
|
+
subject: string;
|
|
49
|
+
/** Pre-rendered HTML body */
|
|
50
|
+
html: string;
|
|
51
|
+
/** Better Auth verification kind */
|
|
52
|
+
type: PlatformAuthMailerType;
|
|
53
|
+
/** The OTP value, in case the consumer wants to render its own template */
|
|
54
|
+
otp: string;
|
|
55
|
+
}
|
|
56
|
+
type PlatformAuthMailer = (args: PlatformAuthMailerArgs) => Promise<void>;
|
|
57
|
+
interface PlatformAuthConfig {
|
|
58
|
+
/** PostgreSQL connection pool or connection string */
|
|
59
|
+
database: BetterAuthOptions["database"];
|
|
60
|
+
/** Base URL for Better Auth callbacks (e.g. http://localhost:3001) */
|
|
61
|
+
baseURL: string;
|
|
62
|
+
/** Secret for signing sessions */
|
|
63
|
+
secret: string;
|
|
64
|
+
/** Application name (used in emails) */
|
|
65
|
+
appName: string;
|
|
66
|
+
/**
|
|
67
|
+
* Transactional mailer. Receives the fully-rendered subject and HTML body
|
|
68
|
+
* and is responsible for pushing the message onto the wire (e.g. via the
|
|
69
|
+
* @digstack/spore-sdk, SES, postfix, …). When omitted, OTPs are logged to
|
|
70
|
+
* stdout — useful in dev/test, useless in production.
|
|
71
|
+
*/
|
|
72
|
+
mailer?: PlatformAuthMailer;
|
|
73
|
+
/** Google OAuth config (omit to disable) */
|
|
74
|
+
google?: {
|
|
75
|
+
clientId: string;
|
|
76
|
+
clientSecret: string;
|
|
77
|
+
};
|
|
78
|
+
/** GitHub OAuth config (omit to disable) */
|
|
79
|
+
github?: {
|
|
80
|
+
clientId: string;
|
|
81
|
+
clientSecret: string;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Override the OTP email subject line per verification type. Merged over
|
|
85
|
+
* the platform defaults — provide only the keys you want to change. The
|
|
86
|
+
* resulting subject is suffixed with ` - ${appName}` like the defaults.
|
|
87
|
+
*/
|
|
88
|
+
emailSubjects?: Partial<Record<PlatformAuthMailerType, string>>;
|
|
89
|
+
/**
|
|
90
|
+
* Override the OTP email HTML renderer. Receives the OTP code and the
|
|
91
|
+
* verification type, returns the HTML body. When omitted, the platform's
|
|
92
|
+
* default branded template is used.
|
|
93
|
+
*/
|
|
94
|
+
renderOtpEmail?: (otp: string, type: PlatformAuthMailerType) => string;
|
|
95
|
+
/** Additional Better Auth plugins to append */
|
|
96
|
+
plugins?: BetterAuthOptions["plugins"];
|
|
97
|
+
/** Enable private beta mode (blocks public registration) */
|
|
98
|
+
betaMode?: boolean;
|
|
99
|
+
/** Check if an email+token pair has been invited (required when betaMode is true) */
|
|
100
|
+
isInvited?: (email: string, inviteToken: string) => Promise<boolean>;
|
|
101
|
+
}
|
|
102
|
+
interface PlatformAuthClientConfig {
|
|
103
|
+
/** Base URL override (defaults to window.location.origin in browser) */
|
|
104
|
+
baseURL?: string;
|
|
105
|
+
/** Additional client plugins */
|
|
106
|
+
plugins?: any[];
|
|
107
|
+
}
|
|
108
|
+
interface VerifyEmailFormProps {
|
|
109
|
+
/** Email to verify */
|
|
110
|
+
email: string;
|
|
111
|
+
/** Callback on successful verification */
|
|
112
|
+
onSuccess?: () => void;
|
|
113
|
+
/** URL to navigate to on success */
|
|
114
|
+
successUrl?: string;
|
|
115
|
+
/** Auth client instance */
|
|
116
|
+
authClient: any;
|
|
117
|
+
}
|
|
118
|
+
/** Why an invitation link did not work, as far as the invitee needs to know. */
|
|
119
|
+
type InvitationFailure = "expired" | "claimed" | "unknown";
|
|
120
|
+
interface InvitationNoticeProps {
|
|
121
|
+
reason?: InvitationFailure;
|
|
122
|
+
/** Defaults to contact@ the apex domain the app is served from. */
|
|
123
|
+
supportEmail?: string;
|
|
124
|
+
title?: string;
|
|
125
|
+
/** Rendered under the contact line — typically a link back to the site. */
|
|
126
|
+
action?: React.ReactNode;
|
|
127
|
+
}
|
|
128
|
+
interface ForgotPasswordFormProps {
|
|
129
|
+
/** Callback on successful OTP send, receives the email */
|
|
130
|
+
onSuccess?: (email: string) => void;
|
|
131
|
+
/** Link to login page */
|
|
132
|
+
loginUrl?: string;
|
|
133
|
+
/** Auth client instance */
|
|
134
|
+
authClient: any;
|
|
135
|
+
}
|
|
136
|
+
interface ResetPasswordFormProps {
|
|
137
|
+
/** Email address to reset password for */
|
|
138
|
+
email: string;
|
|
139
|
+
/** Callback on successful password reset */
|
|
140
|
+
onSuccess?: () => void;
|
|
141
|
+
/** Link to login page */
|
|
142
|
+
loginUrl?: string;
|
|
143
|
+
/** Auth client instance */
|
|
144
|
+
authClient: any;
|
|
145
|
+
}
|
|
146
|
+
interface AuthLayoutProps {
|
|
147
|
+
/** Logo element to display at the top */
|
|
148
|
+
logo?: React.ReactNode;
|
|
149
|
+
/** Page title */
|
|
150
|
+
title: string;
|
|
151
|
+
/** Subtitle below the title */
|
|
152
|
+
subtitle?: string;
|
|
153
|
+
/** Content to render inside the card */
|
|
154
|
+
children: React.ReactNode;
|
|
155
|
+
/** Footer content below the card (e.g. legal links) */
|
|
156
|
+
footer?: React.ReactNode;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export type { AuthLayoutProps as A, ForgotPasswordFormProps as F, InvitationNoticeProps as I, PlatformAuthClientConfig as P, ResetPasswordFormProps as R, VerifyEmailFormProps as V, InvitationFailure as a, PlatformAuthConfig as b, PlatformAuthMailer as c, PlatformAuthMailerArgs as d, PlatformAuthMailerType as e, PlatformSession as f, PlatformSessionData as g, PlatformUser as h };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lalternative/auth",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.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",
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"scripts": {
|
|
26
26
|
"build": "tsup",
|
|
27
27
|
"dev": "tsup --watch",
|
|
28
|
-
"typecheck": "tsc --noEmit"
|
|
28
|
+
"typecheck": "tsc --noEmit",
|
|
29
|
+
"prepublishOnly": "pnpm build"
|
|
29
30
|
},
|
|
30
31
|
"peerDependencies": {
|
|
31
32
|
"better-auth": ">=1.4.0",
|