cloudflare-next-intl 0.8.20 → 0.8.22

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.
@@ -134,7 +134,7 @@ export default async function connectToPostgres(config, resolved) {
134
134
  // expected shape of this event (Hyperdrive/Postgres recycling
135
135
  // the connection, not a query failure): swallow it entirely,
136
136
  // don't report or log it.
137
- if (/connection terminated/i.test(error.message))
137
+ if (/(connection terminated|connection closed)/i.test(error.message))
138
138
  return;
139
139
  void reportError({ errorHandling: config.errorHandling, generate: config.generate }, { error, classOrMethodName: 'db.connectToPostgres.clientError' });
140
140
  });
@@ -44,3 +44,40 @@ export declare function createSignUpAction(locale: string, messages: AuthActionM
44
44
  * <form action={action}>...</form>
45
45
  */
46
46
  export declare function createForgotPasswordAction(locale: string, actionCodeSettings?: AuthActionCodeSettings): (_prevState: AuthFormState, formData: FormData) => Promise<AuthFormState>;
47
+ /**
48
+ * Builds a "send sign-in link" server action for React's `useActionState`
49
+ * form hook, for passwordless email-link sign-in. Same shape as
50
+ * {@link createLoginAction}.
51
+ *
52
+ * `formData` must contain an `email` field.
53
+ *
54
+ * @param locale Used to localize the returned error message.
55
+ * @param actionCodeSettings Required. `actionCodeSettings.url` is the page
56
+ * the emailed link points to (must handle completion via a future
57
+ * `completeSignInWithLink` action); `handleCodeInApp` should be `true`.
58
+ * @returns A form action: `{ success: true, email }` on success (the
59
+ * trimmed email, for the caller to persist as `emailForSignIn` before
60
+ * the user leaves this device/tab), `{ error }` on failure.
61
+ * @example
62
+ * const [state, action] = useActionState(
63
+ * createSendSignInLinkAction(locale, { url: completeUrl, handleCodeInApp: true }),
64
+ * {},
65
+ * );
66
+ * <form action={action}>...</form>
67
+ */
68
+ export declare function createSendSignInLinkAction(locale: string, actionCodeSettings: AuthActionCodeSettings): (_prevState: AuthFormState, formData: FormData) => Promise<AuthFormState>;
69
+ /**
70
+ * Completes a passwordless email-link sign-in. Called directly (not via
71
+ * `useActionState`) from an effect on the link-landing page, once the URL
72
+ * and the user's email (recovered from `localStorage`, or re-entered if
73
+ * the link was opened on a different device) are both known.
74
+ *
75
+ * @param locale Used to localize the returned error message.
76
+ * @param url The full URL the user landed on (`window.location.href`).
77
+ * @param email The email address to complete sign-in for.
78
+ * @returns `{ success: true }` on success, `{ error }` if the URL isn't a
79
+ * valid sign-in link or sign-in otherwise fails.
80
+ * @example
81
+ * const result = await completeSignInWithLink(locale, window.location.href, email);
82
+ */
83
+ export declare function completeSignInWithLink(locale: string, url: string, email: string): Promise<AuthFormState>;
@@ -100,3 +100,68 @@ export function createForgotPasswordAction(locale, actionCodeSettings) {
100
100
  }
101
101
  };
102
102
  }
103
+ /**
104
+ * Builds a "send sign-in link" server action for React's `useActionState`
105
+ * form hook, for passwordless email-link sign-in. Same shape as
106
+ * {@link createLoginAction}.
107
+ *
108
+ * `formData` must contain an `email` field.
109
+ *
110
+ * @param locale Used to localize the returned error message.
111
+ * @param actionCodeSettings Required. `actionCodeSettings.url` is the page
112
+ * the emailed link points to (must handle completion via a future
113
+ * `completeSignInWithLink` action); `handleCodeInApp` should be `true`.
114
+ * @returns A form action: `{ success: true, email }` on success (the
115
+ * trimmed email, for the caller to persist as `emailForSignIn` before
116
+ * the user leaves this device/tab), `{ error }` on failure.
117
+ * @example
118
+ * const [state, action] = useActionState(
119
+ * createSendSignInLinkAction(locale, { url: completeUrl, handleCodeInApp: true }),
120
+ * {},
121
+ * );
122
+ * <form action={action}>...</form>
123
+ */
124
+ export function createSendSignInLinkAction(locale, actionCodeSettings) {
125
+ return async function sendSignInLinkAction(_prevState, formData) {
126
+ requireFirebaseAuthConfig(config.firebaseAuth);
127
+ const { auth } = await getFirebaseAuthClient();
128
+ const { sendSignInLinkToEmail } = await getFirebaseAuthModule();
129
+ const email = (formData.get('email')?.toString() ?? '').trim();
130
+ try {
131
+ await sendSignInLinkToEmail(auth, email, actionCodeSettings);
132
+ return { success: true, email };
133
+ }
134
+ catch (e) {
135
+ return { error: firebaseAuthErrorMessage(locale, e) };
136
+ }
137
+ };
138
+ }
139
+ /**
140
+ * Completes a passwordless email-link sign-in. Called directly (not via
141
+ * `useActionState`) from an effect on the link-landing page, once the URL
142
+ * and the user's email (recovered from `localStorage`, or re-entered if
143
+ * the link was opened on a different device) are both known.
144
+ *
145
+ * @param locale Used to localize the returned error message.
146
+ * @param url The full URL the user landed on (`window.location.href`).
147
+ * @param email The email address to complete sign-in for.
148
+ * @returns `{ success: true }` on success, `{ error }` if the URL isn't a
149
+ * valid sign-in link or sign-in otherwise fails.
150
+ * @example
151
+ * const result = await completeSignInWithLink(locale, window.location.href, email);
152
+ */
153
+ export async function completeSignInWithLink(locale, url, email) {
154
+ requireFirebaseAuthConfig(config.firebaseAuth);
155
+ const { auth } = await getFirebaseAuthClient();
156
+ const { isSignInWithEmailLink, signInWithEmailLink } = await getFirebaseAuthModule();
157
+ if (!isSignInWithEmailLink(auth, url)) {
158
+ return { error: firebaseAuthErrorMessage(locale, { code: 'auth/invalid-action-code' }) };
159
+ }
160
+ try {
161
+ await signInWithEmailLink(auth, email, url);
162
+ return { success: true };
163
+ }
164
+ catch (e) {
165
+ return { error: firebaseAuthErrorMessage(locale, e) };
166
+ }
167
+ }
@@ -2,7 +2,7 @@ export { default as FirebaseAuthClientProvider } from './client/auth_user_provid
2
2
  export { default as FirebaseAuthServerProvider } from './server/auth_user_server_provider';
3
3
  export { default as useFirebaseAuthUserClient } from './client/use_auth_user';
4
4
  export { default as useFirebaseAuthUserServer } from './server/use_auth_user_server';
5
- export { createLoginAction, createSignUpAction, createForgotPasswordAction } from './client/auth_actions';
5
+ export { createLoginAction, createSignUpAction, createForgotPasswordAction, createSendSignInLinkAction, completeSignInWithLink, } from './client/auth_actions';
6
6
  export { default as clearFirebaseAuthSession } from './server/clear_session_action';
7
7
  export { default as updateFirebaseAuthSession, defaultSessionCookieName as firebaseAuthSessionCookieName } from './middleware/update_session';
8
8
  export { getFirebaseAuthClient, getFirebasePerformanceSync } from './client/firebase_client';
@@ -8,7 +8,7 @@ export { default as FirebaseAuthServerProvider } from './server/auth_user_server
8
8
  // DOES resolve correctly per-environment) rather than through this barrel.
9
9
  export { default as useFirebaseAuthUserClient } from './client/use_auth_user';
10
10
  export { default as useFirebaseAuthUserServer } from './server/use_auth_user_server';
11
- export { createLoginAction, createSignUpAction, createForgotPasswordAction } from './client/auth_actions';
11
+ export { createLoginAction, createSignUpAction, createForgotPasswordAction, createSendSignInLinkAction, completeSignInWithLink, } from './client/auth_actions';
12
12
  export { default as clearFirebaseAuthSession } from './server/clear_session_action';
13
13
  export { default as updateFirebaseAuthSession, defaultSessionCookieName as firebaseAuthSessionCookieName } from './middleware/update_session';
14
14
  export { getFirebaseAuthClient, getFirebasePerformanceSync } from './client/firebase_client';
@@ -13,6 +13,7 @@ export interface SerializedAuthUser {
13
13
  export type AuthFormState = {
14
14
  error?: string;
15
15
  success?: boolean;
16
+ email?: string;
16
17
  };
17
18
  /** Overrides for the default English auth error/status messages. */
18
19
  export interface AuthActionMessages {
package/llms.txt CHANGED
@@ -34,7 +34,7 @@ other subpath can be used.
34
34
  - `./firebaseAuthServerProvider` — server-side equivalent provider (not used by the default auto-wiring path — see its doc comment).
35
35
  - `./useFirebaseAuthUser` — `useAuthUser()`; resolves to RSC or client implementation via the `react-server` condition. Client variant throws `"useAuthUser must be used within an AuthUserProvider"` if called outside one.
36
36
  - `./getFirebaseAuthUser` — `getAuthUser()`; unconditional server-only export of the same RSC implementation `useFirebaseAuthUser` resolves to via `react-server`. Use this when you want `await` to be visible from the type itself — TypeScript doesn't evaluate the `react-server` condition, so `useFirebaseAuthUser` always types as its client (sync) signature in editors regardless of call site.
37
- - `./firebaseAuthActions` — `createLoginAction`/`createSignUpAction`/`createForgotPasswordAction`: factories returning React `useActionState`-shaped form actions.
37
+ - `./firebaseAuthActions` — `createLoginAction`/`createSignUpAction`/`createForgotPasswordAction`: factories returning React `useActionState`-shaped form actions. `createSendSignInLinkAction`: same factory shape, for passwordless email-link sign-in — returns `{ success: true, email }` so the caller can persist the trimmed email (e.g. to `localStorage`) for the completion step. `completeSignInWithLink(locale, url, email)`: plain async function (not `useActionState`-shaped) that completes a passwordless sign-in from the emailed link's landing page — call from an effect on mount, not a form submit.
38
38
  - `./firebaseAuthMiddleware` — `updateSession`: session-cookie refresh, called automatically by `./middleware`'s default handler.
39
39
 
40
40
  ## `cookieConsent*` subpaths (require `cookieConsent` set on your `RoutingConfig`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudflare-next-intl",
3
- "version": "0.8.20",
3
+ "version": "0.8.22",
4
4
  "description": "Optimized Next Intl Package Special for App Router and Cloudflare",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",