@netlify/identity 0.4.2 → 1.1.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/dist/index.d.cts CHANGED
@@ -1,10 +1,10 @@
1
1
  /** The supported OAuth and authentication providers. */
2
- declare const AUTH_PROVIDERS: readonly ["google", "github", "gitlab", "bitbucket", "facebook", "saml", "email"];
2
+ declare const AUTH_PROVIDERS: readonly ["google", "github", "gitlab", "bitbucket", "facebook", "email"];
3
3
  /** A supported authentication provider name (e.g., `'google'`, `'github'`, `'email'`). */
4
4
  type AuthProvider = (typeof AUTH_PROVIDERS)[number];
5
5
  /**
6
6
  * Provider and role metadata stored in a user's `app_metadata` field.
7
- * GoTrue sets `provider` automatically on signup; `roles` controls authorization.
7
+ * The `provider` field is set automatically on signup; `roles` controls authorization.
8
8
  * Additional keys may be present depending on your Identity configuration.
9
9
  *
10
10
  * @example
@@ -27,7 +27,7 @@ interface AppMetadata {
27
27
  * On the server, `token` is the operator token for admin operations.
28
28
  */
29
29
  interface IdentityConfig {
30
- /** The GoTrue API endpoint URL (e.g., `https://example.com/.netlify/identity`). */
30
+ /** The Identity API endpoint URL (e.g., `https://example.com/.netlify/identity`). */
31
31
  url: string;
32
32
  /** Operator token for server-side admin requests. Only available in Netlify Functions. */
33
33
  token?: string;
@@ -86,8 +86,6 @@ interface AdminUserUpdates {
86
86
  password?: string;
87
87
  /** The user's role (e.g., `'admin'`, `'editor'`). */
88
88
  role?: string;
89
- /** The user's audience (rarely needed; defaults to the site's audience). */
90
- aud?: string;
91
89
  /** Set to `true` to force-confirm the user's email without sending a confirmation email. */
92
90
  confirm?: boolean;
93
91
  /** Server-managed metadata. Only writable via admin operations. */
@@ -107,8 +105,8 @@ interface ListUsersOptions {
107
105
  /**
108
106
  * Parameters for {@link admin.createUser}.
109
107
  *
110
- * The optional `data` fields are forwarded as top-level attributes in the GoTrue
111
- * request body. Only these keys are accepted: `role`, `aud`, `app_metadata`,
108
+ * The optional `data` fields are forwarded as top-level attributes in the Identity API
109
+ * request body. Only these keys are accepted: `role`, `app_metadata`,
112
110
  * `user_metadata`. Any other keys are silently ignored. `data` cannot override
113
111
  * `email`, `password`, or `confirm`.
114
112
  *
@@ -124,14 +122,18 @@ interface ListUsersOptions {
124
122
  interface CreateUserParams {
125
123
  email: string;
126
124
  password: string;
127
- /** GoTrue user fields: `role`, `aud`, `app_metadata`, `user_metadata`. Other keys are ignored. */
125
+ /** Identity user fields: `role`, `app_metadata`, `user_metadata`. Other keys are ignored. */
128
126
  data?: Record<string, unknown>;
129
127
  }
130
128
 
131
129
  /**
132
130
  * A normalized user object returned by all auth and admin functions.
133
131
  * Provides a consistent shape regardless of whether the user was loaded
134
- * from gotrue-js, a JWT cookie, or the server-side identity context.
132
+ * from the Identity API, a JWT cookie, or the server-side identity context.
133
+ *
134
+ * All fields except `id` are optional and may be `undefined`. Empty strings
135
+ * are normalized to `undefined`. State-dependent fields (invite,
136
+ * recovery, email-change) are only present when the user is in that state.
135
137
  *
136
138
  * @example
137
139
  * ```ts
@@ -142,30 +144,46 @@ interface CreateUserParams {
142
144
  * ```
143
145
  */
144
146
  interface User {
145
- /** The user's unique identifier (GoTrue UUID). */
147
+ /** The user's unique identifier. */
146
148
  id: string;
147
149
  /** The user's email address. */
148
150
  email?: string;
149
- /** `true` if the user's email has been confirmed. */
150
- emailVerified?: boolean;
151
+ /** ISO 8601 timestamp of when the user's email was confirmed. `undefined` if not yet confirmed. */
152
+ confirmedAt?: string;
151
153
  /** ISO 8601 timestamp of when the account was created. */
152
154
  createdAt?: string;
153
155
  /** ISO 8601 timestamp of the last account update. */
154
156
  updatedAt?: string;
155
- /** The authentication provider used to create the account. */
157
+ /**
158
+ * The account-level role string (e.g., `"admin"`). This is a single value
159
+ * set via the admin API, distinct from `roles` which is an array in `app_metadata`.
160
+ * `undefined` when not set or empty.
161
+ */
162
+ role?: string;
163
+ /** The authentication provider used to create the account (from `app_metadata.provider`). */
156
164
  provider?: AuthProvider;
157
165
  /** Display name from `user_metadata.full_name` or `user_metadata.name`. */
158
166
  name?: string;
159
167
  /** Avatar URL from `user_metadata.avatar_url`. */
160
168
  pictureUrl?: string;
161
- /** Roles from `app_metadata.roles`, set via the admin API or Netlify UI. */
169
+ /** Application-level roles from `app_metadata.roles`, set via the admin API or Netlify UI. */
162
170
  roles?: string[];
163
- /** The full `user_metadata` object. */
164
- metadata?: Record<string, unknown>;
165
- /** The full `app_metadata` object. */
171
+ /** ISO 8601 timestamp of when the user was invited. Only present if the user was created via invitation. */
172
+ invitedAt?: string;
173
+ /** ISO 8601 timestamp of when the confirmation email was last sent. */
174
+ confirmationSentAt?: string;
175
+ /** ISO 8601 timestamp of when the recovery email was last sent. */
176
+ recoverySentAt?: string;
177
+ /** The pending email address during an email change flow. Only present while the change is awaiting confirmation. */
178
+ pendingEmail?: string;
179
+ /** ISO 8601 timestamp of when the email change verification was last sent. */
180
+ emailChangeSentAt?: string;
181
+ /** ISO 8601 timestamp of the user's most recent sign-in. */
182
+ lastSignInAt?: string;
183
+ /** Custom user metadata. Contains profile data like `full_name` and `avatar_url`, and any custom fields set via `updateUser()`. */
184
+ userMetadata?: Record<string, unknown>;
185
+ /** Application metadata managed by the server. Contains `provider`, `roles`, and other system-managed fields. */
166
186
  appMetadata?: Record<string, unknown>;
167
- /** The raw GoTrue user data, for accessing fields not mapped to this interface. */
168
- rawGoTrueData?: Record<string, unknown>;
169
187
  }
170
188
  /**
171
189
  * Returns the currently authenticated user, or `null` if not logged in.
@@ -175,11 +193,11 @@ interface User {
175
193
  * (email, roles, timestamps, metadata, etc.) regardless of whether the
176
194
  * call happens in the browser or on the server.
177
195
  *
178
- * In the browser, checks gotrue-js localStorage first. If no localStorage
196
+ * In the browser, checks localStorage first. If no localStorage
179
197
  * session exists, hydrates from the `nf_jwt` cookie (set by server-side login).
180
198
  *
181
- * On the server, fetches the full user from GoTrue using the JWT from
182
- * the request. Falls back to JWT claims if GoTrue is unreachable.
199
+ * On the server, fetches the full user from the Identity API using the JWT from
200
+ * the request. Falls back to JWT claims if the Identity API is unreachable.
183
201
  *
184
202
  * On the server in a Next.js App Router context, calls `headers()` from
185
203
  * `next/headers` to opt the route into dynamic rendering. Without this,
@@ -260,6 +278,10 @@ declare const onAuthChange: (callback: AuthCallback) => (() => void);
260
278
  * try/catch. Next.js implements `redirect()` by throwing a special error; wrapping it in
261
279
  * try/catch will swallow the redirect.
262
280
  *
281
+ * **Server-side CSRF:** When called from a server endpoint, the endpoint must have CSRF
282
+ * protection. If your framework does not check the request's `Origin` by default, call
283
+ * {@link verifyRequestOrigin} at the start of the handler before invoking `login()`.
284
+ *
263
285
  * @example
264
286
  * ```ts
265
287
  * // Next.js server action
@@ -277,6 +299,11 @@ declare const login: (email: string, password: string) => Promise<User>;
277
299
  * In that case, no cookies are set and no auth event is emitted.
278
300
  *
279
301
  * @throws {AuthError} On duplicate email, validation failure, network error, or missing Netlify runtime.
302
+ *
303
+ * @remarks
304
+ * **Server-side CSRF:** When called from a server endpoint, the endpoint must have CSRF
305
+ * protection. If your framework does not check the request's `Origin` by default, call
306
+ * {@link verifyRequestOrigin} at the start of the handler before invoking `signup()`.
280
307
  */
281
308
  declare const signup: (email: string, password: string, data?: SignupData) => Promise<User>;
282
309
  /**
@@ -286,6 +313,11 @@ declare const signup: (email: string, password: string, data?: SignupData) => Pr
286
313
  * invalidation request fails. In the browser, emits a `'logout'` event via {@link onAuthChange}.
287
314
  *
288
315
  * @throws {AuthError} On missing Netlify runtime (server) or logout failure (browser).
316
+ *
317
+ * @remarks
318
+ * **Server-side CSRF:** When called from a server endpoint, the endpoint must have CSRF
319
+ * protection. If your framework does not check the request's `Origin` by default, call
320
+ * {@link verifyRequestOrigin} at the start of the handler before invoking `logout()`.
289
321
  */
290
322
  declare const logout: () => Promise<void>;
291
323
  /**
@@ -343,7 +375,7 @@ interface CallbackResult {
343
375
  */
344
376
  declare const handleAuthCallback: () => Promise<CallbackResult | null>;
345
377
  /**
346
- * Hydrates the browser-side gotrue-js session from server-set auth cookies.
378
+ * Hydrates the browser-side session from server-set auth cookies.
347
379
  * Call this on page load when using server-side login to enable browser
348
380
  * account operations (updateUser, verifyEmailChange, etc.).
349
381
  *
@@ -388,7 +420,7 @@ declare const refreshSession: () => Promise<string | null>;
388
420
  * Thrown by auth operations when something goes wrong: invalid credentials,
389
421
  * network failures, missing runtime context, etc.
390
422
  *
391
- * The `status` field contains the HTTP status code from GoTrue when available
423
+ * The `status` field contains the HTTP status code from the Identity API when available
392
424
  * (e.g., 401 for bad credentials, 422 for validation errors).
393
425
  * The `cause` field preserves the original error for debugging.
394
426
  *
@@ -405,7 +437,7 @@ declare const refreshSession: () => Promise<string | null>;
405
437
  */
406
438
  declare class AuthError extends Error {
407
439
  name: string;
408
- /** HTTP status code from GoTrue, if the error originated from an API response. */
440
+ /** HTTP status code from the Identity API, if the error originated from an API response. */
409
441
  status?: number;
410
442
  cause?: unknown;
411
443
  constructor(message: string, status?: number, options?: {
@@ -414,7 +446,7 @@ declare class AuthError extends Error {
414
446
  static from(error: unknown): AuthError;
415
447
  }
416
448
  /**
417
- * Thrown when a function requires a gotrue-js client but Netlify Identity
449
+ * Thrown when a function requires the Identity client but Netlify Identity
418
450
  * is not configured (no endpoint URL could be discovered).
419
451
  *
420
452
  * This typically means the site does not have Identity enabled, or the app
@@ -425,6 +457,63 @@ declare class MissingIdentityError extends Error {
425
457
  constructor(message?: string);
426
458
  }
427
459
 
460
+ /**
461
+ * Options for {@link verifyRequestOrigin}.
462
+ */
463
+ interface VerifyRequestOriginOptions {
464
+ /**
465
+ * Origins that are allowed to make state-changing requests to this endpoint.
466
+ *
467
+ * If omitted, the request is only accepted from its own origin (the origin of `request.url`),
468
+ * which is the right default for sites whose login form and login endpoint live on the same origin.
469
+ *
470
+ * Pass an explicit list when you trust additional origins (for example, a separate frontend domain
471
+ * posting to an API on another domain). The list replaces the default, so it must include every
472
+ * origin you want to allow, including the request's own origin if applicable.
473
+ *
474
+ * Each value should be a full origin string with scheme and host: `'https://example.com'`.
475
+ */
476
+ allowedOrigins?: string[];
477
+ }
478
+ /**
479
+ * Same-origin check for state-changing requests, can be used to defend against Cross-Site Request
480
+ * Forgery (CSRF) on server-side endpoints that call {@link login}, {@link signup}, or {@link logout}.
481
+ *
482
+ * Compares the incoming request's `Origin` header against the request's own origin (or an explicit
483
+ * allowlist via `options.allowedOrigins`) and throws if they don't match. Call this at the start of
484
+ * any server-side handler that performs an auth mutation, before invoking the auth function.
485
+ *
486
+ * The check runs unconditionally on every call: any HTTP method, with or without an `Origin` header.
487
+ * If you don't want the check to apply to a given method or path, simply don't call the helper there.
488
+ *
489
+ * @throws {AuthError} with status `403` when the request has no `Origin` header.
490
+ * @throws {AuthError} with status `403` when the request's `Origin` is not in the allowed origins.
491
+ *
492
+ * @example
493
+ * ```ts
494
+ * // Netlify Function
495
+ * import { login, verifyRequestOrigin } from '@netlify/identity'
496
+ * import type { Context } from '@netlify/functions'
497
+ *
498
+ * export default async (req: Request, context: Context) => {
499
+ * verifyRequestOrigin(req)
500
+ * const { email, password } = await req.json()
501
+ * await login(email, password)
502
+ * return new Response(null, { status: 302, headers: { Location: '/dashboard' } })
503
+ * }
504
+ * ```
505
+ *
506
+ * @example
507
+ * ```ts
508
+ * // Allow a separate trusted origin (e.g. a marketing site posting to an app domain).
509
+ * // The list replaces the default, so include the request's own origin if you still want it allowed.
510
+ * verifyRequestOrigin(request, {
511
+ * allowedOrigins: ['https://app.example.com', 'https://www.example.com'],
512
+ * })
513
+ * ```
514
+ */
515
+ declare const verifyRequestOrigin: (request: Request, options?: VerifyRequestOriginOptions) => void;
516
+
428
517
  /**
429
518
  * The admin namespace for privileged user management operations.
430
519
  * All methods are server-only and require the operator token
@@ -436,7 +525,7 @@ interface Admin {
436
525
  /**
437
526
  * Lists all users. Server-only.
438
527
  *
439
- * Calls GoTrue `GET /admin/users` with the operator token. Pagination
528
+ * Calls `GET /admin/users` with the operator token. Pagination
440
529
  * options (`page`, `perPage`) are forwarded as query parameters.
441
530
  *
442
531
  * @throws {AuthError} If called from a browser, or if the operator token is missing.
@@ -445,7 +534,7 @@ interface Admin {
445
534
  /**
446
535
  * Gets a single user by ID. Server-only.
447
536
  *
448
- * Calls GoTrue `GET /admin/users/:id` with the operator token.
537
+ * Calls `GET /admin/users/:id` with the operator token.
449
538
  *
450
539
  * @throws {AuthError} If called from a browser, the user is not found,
451
540
  * or the operator token is missing.
@@ -455,12 +544,12 @@ interface Admin {
455
544
  * Creates a new user. The user is auto-confirmed (no confirmation email is sent).
456
545
  * Server-only.
457
546
  *
458
- * The optional `data` fields are forwarded as top-level attributes in the GoTrue
459
- * request body. Accepted fields: `role`, `aud`, `app_metadata`, `user_metadata`.
547
+ * The optional `data` fields are forwarded as top-level attributes in the Identity API
548
+ * request body. Accepted fields: `role`, `app_metadata`, `user_metadata`.
460
549
  * Any other keys in `data` are silently ignored. `data` cannot override `email`,
461
550
  * `password`, or `confirm`.
462
551
  *
463
- * Calls GoTrue `POST /admin/users` with the operator token.
552
+ * Calls `POST /admin/users` with the operator token.
464
553
  *
465
554
  * @throws {AuthError} If called from a browser, the email already exists,
466
555
  * or the operator token is missing.
@@ -469,7 +558,7 @@ interface Admin {
469
558
  /**
470
559
  * Updates an existing user by ID. Server-only.
471
560
  *
472
- * Calls GoTrue `PUT /admin/users/:id` with the operator token.
561
+ * Calls `PUT /admin/users/:id` with the operator token.
473
562
  *
474
563
  * @throws {AuthError} If called from a browser, the user is not found,
475
564
  * the update fails, or the operator token is missing.
@@ -478,7 +567,7 @@ interface Admin {
478
567
  /**
479
568
  * Deletes a user by ID. Server-only.
480
569
  *
481
- * Calls GoTrue `DELETE /admin/users/:id` with the operator token.
570
+ * Calls `DELETE /admin/users/:id` with the operator token.
482
571
  *
483
572
  * @throws {AuthError} If called from a browser, the user is not found,
484
573
  * the deletion fails, or the operator token is missing.
@@ -528,4 +617,4 @@ declare const verifyEmailChange: (token: string) => Promise<User>;
528
617
  */
529
618
  declare const updateUser: (updates: UserUpdates) => Promise<User>;
530
619
 
531
- export { AUTH_EVENTS, type Admin, type AdminUserUpdates, type AppMetadata, type AuthCallback, AuthError, type AuthEvent, type AuthProvider, type CallbackResult, type CreateUserParams, type IdentityConfig, type ListUsersOptions, MissingIdentityError, type Settings, type SignupData, type User, type UserUpdates, acceptInvite, admin, confirmEmail, getIdentityConfig, getSettings, getUser, handleAuthCallback, hydrateSession, isAuthenticated, login, logout, oauthLogin, onAuthChange, recoverPassword, refreshSession, requestPasswordRecovery, signup, updateUser, verifyEmailChange };
620
+ export { AUTH_EVENTS, type Admin, type AdminUserUpdates, type AppMetadata, type AuthCallback, AuthError, type AuthEvent, type AuthProvider, type CallbackResult, type CreateUserParams, type IdentityConfig, type ListUsersOptions, MissingIdentityError, type Settings, type SignupData, type User, type UserUpdates, type VerifyRequestOriginOptions, acceptInvite, admin, confirmEmail, getIdentityConfig, getSettings, getUser, handleAuthCallback, hydrateSession, isAuthenticated, login, logout, oauthLogin, onAuthChange, recoverPassword, refreshSession, requestPasswordRecovery, signup, updateUser, verifyEmailChange, verifyRequestOrigin };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  /** The supported OAuth and authentication providers. */
2
- declare const AUTH_PROVIDERS: readonly ["google", "github", "gitlab", "bitbucket", "facebook", "saml", "email"];
2
+ declare const AUTH_PROVIDERS: readonly ["google", "github", "gitlab", "bitbucket", "facebook", "email"];
3
3
  /** A supported authentication provider name (e.g., `'google'`, `'github'`, `'email'`). */
4
4
  type AuthProvider = (typeof AUTH_PROVIDERS)[number];
5
5
  /**
6
6
  * Provider and role metadata stored in a user's `app_metadata` field.
7
- * GoTrue sets `provider` automatically on signup; `roles` controls authorization.
7
+ * The `provider` field is set automatically on signup; `roles` controls authorization.
8
8
  * Additional keys may be present depending on your Identity configuration.
9
9
  *
10
10
  * @example
@@ -27,7 +27,7 @@ interface AppMetadata {
27
27
  * On the server, `token` is the operator token for admin operations.
28
28
  */
29
29
  interface IdentityConfig {
30
- /** The GoTrue API endpoint URL (e.g., `https://example.com/.netlify/identity`). */
30
+ /** The Identity API endpoint URL (e.g., `https://example.com/.netlify/identity`). */
31
31
  url: string;
32
32
  /** Operator token for server-side admin requests. Only available in Netlify Functions. */
33
33
  token?: string;
@@ -86,8 +86,6 @@ interface AdminUserUpdates {
86
86
  password?: string;
87
87
  /** The user's role (e.g., `'admin'`, `'editor'`). */
88
88
  role?: string;
89
- /** The user's audience (rarely needed; defaults to the site's audience). */
90
- aud?: string;
91
89
  /** Set to `true` to force-confirm the user's email without sending a confirmation email. */
92
90
  confirm?: boolean;
93
91
  /** Server-managed metadata. Only writable via admin operations. */
@@ -107,8 +105,8 @@ interface ListUsersOptions {
107
105
  /**
108
106
  * Parameters for {@link admin.createUser}.
109
107
  *
110
- * The optional `data` fields are forwarded as top-level attributes in the GoTrue
111
- * request body. Only these keys are accepted: `role`, `aud`, `app_metadata`,
108
+ * The optional `data` fields are forwarded as top-level attributes in the Identity API
109
+ * request body. Only these keys are accepted: `role`, `app_metadata`,
112
110
  * `user_metadata`. Any other keys are silently ignored. `data` cannot override
113
111
  * `email`, `password`, or `confirm`.
114
112
  *
@@ -124,14 +122,18 @@ interface ListUsersOptions {
124
122
  interface CreateUserParams {
125
123
  email: string;
126
124
  password: string;
127
- /** GoTrue user fields: `role`, `aud`, `app_metadata`, `user_metadata`. Other keys are ignored. */
125
+ /** Identity user fields: `role`, `app_metadata`, `user_metadata`. Other keys are ignored. */
128
126
  data?: Record<string, unknown>;
129
127
  }
130
128
 
131
129
  /**
132
130
  * A normalized user object returned by all auth and admin functions.
133
131
  * Provides a consistent shape regardless of whether the user was loaded
134
- * from gotrue-js, a JWT cookie, or the server-side identity context.
132
+ * from the Identity API, a JWT cookie, or the server-side identity context.
133
+ *
134
+ * All fields except `id` are optional and may be `undefined`. Empty strings
135
+ * are normalized to `undefined`. State-dependent fields (invite,
136
+ * recovery, email-change) are only present when the user is in that state.
135
137
  *
136
138
  * @example
137
139
  * ```ts
@@ -142,30 +144,46 @@ interface CreateUserParams {
142
144
  * ```
143
145
  */
144
146
  interface User {
145
- /** The user's unique identifier (GoTrue UUID). */
147
+ /** The user's unique identifier. */
146
148
  id: string;
147
149
  /** The user's email address. */
148
150
  email?: string;
149
- /** `true` if the user's email has been confirmed. */
150
- emailVerified?: boolean;
151
+ /** ISO 8601 timestamp of when the user's email was confirmed. `undefined` if not yet confirmed. */
152
+ confirmedAt?: string;
151
153
  /** ISO 8601 timestamp of when the account was created. */
152
154
  createdAt?: string;
153
155
  /** ISO 8601 timestamp of the last account update. */
154
156
  updatedAt?: string;
155
- /** The authentication provider used to create the account. */
157
+ /**
158
+ * The account-level role string (e.g., `"admin"`). This is a single value
159
+ * set via the admin API, distinct from `roles` which is an array in `app_metadata`.
160
+ * `undefined` when not set or empty.
161
+ */
162
+ role?: string;
163
+ /** The authentication provider used to create the account (from `app_metadata.provider`). */
156
164
  provider?: AuthProvider;
157
165
  /** Display name from `user_metadata.full_name` or `user_metadata.name`. */
158
166
  name?: string;
159
167
  /** Avatar URL from `user_metadata.avatar_url`. */
160
168
  pictureUrl?: string;
161
- /** Roles from `app_metadata.roles`, set via the admin API or Netlify UI. */
169
+ /** Application-level roles from `app_metadata.roles`, set via the admin API or Netlify UI. */
162
170
  roles?: string[];
163
- /** The full `user_metadata` object. */
164
- metadata?: Record<string, unknown>;
165
- /** The full `app_metadata` object. */
171
+ /** ISO 8601 timestamp of when the user was invited. Only present if the user was created via invitation. */
172
+ invitedAt?: string;
173
+ /** ISO 8601 timestamp of when the confirmation email was last sent. */
174
+ confirmationSentAt?: string;
175
+ /** ISO 8601 timestamp of when the recovery email was last sent. */
176
+ recoverySentAt?: string;
177
+ /** The pending email address during an email change flow. Only present while the change is awaiting confirmation. */
178
+ pendingEmail?: string;
179
+ /** ISO 8601 timestamp of when the email change verification was last sent. */
180
+ emailChangeSentAt?: string;
181
+ /** ISO 8601 timestamp of the user's most recent sign-in. */
182
+ lastSignInAt?: string;
183
+ /** Custom user metadata. Contains profile data like `full_name` and `avatar_url`, and any custom fields set via `updateUser()`. */
184
+ userMetadata?: Record<string, unknown>;
185
+ /** Application metadata managed by the server. Contains `provider`, `roles`, and other system-managed fields. */
166
186
  appMetadata?: Record<string, unknown>;
167
- /** The raw GoTrue user data, for accessing fields not mapped to this interface. */
168
- rawGoTrueData?: Record<string, unknown>;
169
187
  }
170
188
  /**
171
189
  * Returns the currently authenticated user, or `null` if not logged in.
@@ -175,11 +193,11 @@ interface User {
175
193
  * (email, roles, timestamps, metadata, etc.) regardless of whether the
176
194
  * call happens in the browser or on the server.
177
195
  *
178
- * In the browser, checks gotrue-js localStorage first. If no localStorage
196
+ * In the browser, checks localStorage first. If no localStorage
179
197
  * session exists, hydrates from the `nf_jwt` cookie (set by server-side login).
180
198
  *
181
- * On the server, fetches the full user from GoTrue using the JWT from
182
- * the request. Falls back to JWT claims if GoTrue is unreachable.
199
+ * On the server, fetches the full user from the Identity API using the JWT from
200
+ * the request. Falls back to JWT claims if the Identity API is unreachable.
183
201
  *
184
202
  * On the server in a Next.js App Router context, calls `headers()` from
185
203
  * `next/headers` to opt the route into dynamic rendering. Without this,
@@ -260,6 +278,10 @@ declare const onAuthChange: (callback: AuthCallback) => (() => void);
260
278
  * try/catch. Next.js implements `redirect()` by throwing a special error; wrapping it in
261
279
  * try/catch will swallow the redirect.
262
280
  *
281
+ * **Server-side CSRF:** When called from a server endpoint, the endpoint must have CSRF
282
+ * protection. If your framework does not check the request's `Origin` by default, call
283
+ * {@link verifyRequestOrigin} at the start of the handler before invoking `login()`.
284
+ *
263
285
  * @example
264
286
  * ```ts
265
287
  * // Next.js server action
@@ -277,6 +299,11 @@ declare const login: (email: string, password: string) => Promise<User>;
277
299
  * In that case, no cookies are set and no auth event is emitted.
278
300
  *
279
301
  * @throws {AuthError} On duplicate email, validation failure, network error, or missing Netlify runtime.
302
+ *
303
+ * @remarks
304
+ * **Server-side CSRF:** When called from a server endpoint, the endpoint must have CSRF
305
+ * protection. If your framework does not check the request's `Origin` by default, call
306
+ * {@link verifyRequestOrigin} at the start of the handler before invoking `signup()`.
280
307
  */
281
308
  declare const signup: (email: string, password: string, data?: SignupData) => Promise<User>;
282
309
  /**
@@ -286,6 +313,11 @@ declare const signup: (email: string, password: string, data?: SignupData) => Pr
286
313
  * invalidation request fails. In the browser, emits a `'logout'` event via {@link onAuthChange}.
287
314
  *
288
315
  * @throws {AuthError} On missing Netlify runtime (server) or logout failure (browser).
316
+ *
317
+ * @remarks
318
+ * **Server-side CSRF:** When called from a server endpoint, the endpoint must have CSRF
319
+ * protection. If your framework does not check the request's `Origin` by default, call
320
+ * {@link verifyRequestOrigin} at the start of the handler before invoking `logout()`.
289
321
  */
290
322
  declare const logout: () => Promise<void>;
291
323
  /**
@@ -343,7 +375,7 @@ interface CallbackResult {
343
375
  */
344
376
  declare const handleAuthCallback: () => Promise<CallbackResult | null>;
345
377
  /**
346
- * Hydrates the browser-side gotrue-js session from server-set auth cookies.
378
+ * Hydrates the browser-side session from server-set auth cookies.
347
379
  * Call this on page load when using server-side login to enable browser
348
380
  * account operations (updateUser, verifyEmailChange, etc.).
349
381
  *
@@ -388,7 +420,7 @@ declare const refreshSession: () => Promise<string | null>;
388
420
  * Thrown by auth operations when something goes wrong: invalid credentials,
389
421
  * network failures, missing runtime context, etc.
390
422
  *
391
- * The `status` field contains the HTTP status code from GoTrue when available
423
+ * The `status` field contains the HTTP status code from the Identity API when available
392
424
  * (e.g., 401 for bad credentials, 422 for validation errors).
393
425
  * The `cause` field preserves the original error for debugging.
394
426
  *
@@ -405,7 +437,7 @@ declare const refreshSession: () => Promise<string | null>;
405
437
  */
406
438
  declare class AuthError extends Error {
407
439
  name: string;
408
- /** HTTP status code from GoTrue, if the error originated from an API response. */
440
+ /** HTTP status code from the Identity API, if the error originated from an API response. */
409
441
  status?: number;
410
442
  cause?: unknown;
411
443
  constructor(message: string, status?: number, options?: {
@@ -414,7 +446,7 @@ declare class AuthError extends Error {
414
446
  static from(error: unknown): AuthError;
415
447
  }
416
448
  /**
417
- * Thrown when a function requires a gotrue-js client but Netlify Identity
449
+ * Thrown when a function requires the Identity client but Netlify Identity
418
450
  * is not configured (no endpoint URL could be discovered).
419
451
  *
420
452
  * This typically means the site does not have Identity enabled, or the app
@@ -425,6 +457,63 @@ declare class MissingIdentityError extends Error {
425
457
  constructor(message?: string);
426
458
  }
427
459
 
460
+ /**
461
+ * Options for {@link verifyRequestOrigin}.
462
+ */
463
+ interface VerifyRequestOriginOptions {
464
+ /**
465
+ * Origins that are allowed to make state-changing requests to this endpoint.
466
+ *
467
+ * If omitted, the request is only accepted from its own origin (the origin of `request.url`),
468
+ * which is the right default for sites whose login form and login endpoint live on the same origin.
469
+ *
470
+ * Pass an explicit list when you trust additional origins (for example, a separate frontend domain
471
+ * posting to an API on another domain). The list replaces the default, so it must include every
472
+ * origin you want to allow, including the request's own origin if applicable.
473
+ *
474
+ * Each value should be a full origin string with scheme and host: `'https://example.com'`.
475
+ */
476
+ allowedOrigins?: string[];
477
+ }
478
+ /**
479
+ * Same-origin check for state-changing requests, can be used to defend against Cross-Site Request
480
+ * Forgery (CSRF) on server-side endpoints that call {@link login}, {@link signup}, or {@link logout}.
481
+ *
482
+ * Compares the incoming request's `Origin` header against the request's own origin (or an explicit
483
+ * allowlist via `options.allowedOrigins`) and throws if they don't match. Call this at the start of
484
+ * any server-side handler that performs an auth mutation, before invoking the auth function.
485
+ *
486
+ * The check runs unconditionally on every call: any HTTP method, with or without an `Origin` header.
487
+ * If you don't want the check to apply to a given method or path, simply don't call the helper there.
488
+ *
489
+ * @throws {AuthError} with status `403` when the request has no `Origin` header.
490
+ * @throws {AuthError} with status `403` when the request's `Origin` is not in the allowed origins.
491
+ *
492
+ * @example
493
+ * ```ts
494
+ * // Netlify Function
495
+ * import { login, verifyRequestOrigin } from '@netlify/identity'
496
+ * import type { Context } from '@netlify/functions'
497
+ *
498
+ * export default async (req: Request, context: Context) => {
499
+ * verifyRequestOrigin(req)
500
+ * const { email, password } = await req.json()
501
+ * await login(email, password)
502
+ * return new Response(null, { status: 302, headers: { Location: '/dashboard' } })
503
+ * }
504
+ * ```
505
+ *
506
+ * @example
507
+ * ```ts
508
+ * // Allow a separate trusted origin (e.g. a marketing site posting to an app domain).
509
+ * // The list replaces the default, so include the request's own origin if you still want it allowed.
510
+ * verifyRequestOrigin(request, {
511
+ * allowedOrigins: ['https://app.example.com', 'https://www.example.com'],
512
+ * })
513
+ * ```
514
+ */
515
+ declare const verifyRequestOrigin: (request: Request, options?: VerifyRequestOriginOptions) => void;
516
+
428
517
  /**
429
518
  * The admin namespace for privileged user management operations.
430
519
  * All methods are server-only and require the operator token
@@ -436,7 +525,7 @@ interface Admin {
436
525
  /**
437
526
  * Lists all users. Server-only.
438
527
  *
439
- * Calls GoTrue `GET /admin/users` with the operator token. Pagination
528
+ * Calls `GET /admin/users` with the operator token. Pagination
440
529
  * options (`page`, `perPage`) are forwarded as query parameters.
441
530
  *
442
531
  * @throws {AuthError} If called from a browser, or if the operator token is missing.
@@ -445,7 +534,7 @@ interface Admin {
445
534
  /**
446
535
  * Gets a single user by ID. Server-only.
447
536
  *
448
- * Calls GoTrue `GET /admin/users/:id` with the operator token.
537
+ * Calls `GET /admin/users/:id` with the operator token.
449
538
  *
450
539
  * @throws {AuthError} If called from a browser, the user is not found,
451
540
  * or the operator token is missing.
@@ -455,12 +544,12 @@ interface Admin {
455
544
  * Creates a new user. The user is auto-confirmed (no confirmation email is sent).
456
545
  * Server-only.
457
546
  *
458
- * The optional `data` fields are forwarded as top-level attributes in the GoTrue
459
- * request body. Accepted fields: `role`, `aud`, `app_metadata`, `user_metadata`.
547
+ * The optional `data` fields are forwarded as top-level attributes in the Identity API
548
+ * request body. Accepted fields: `role`, `app_metadata`, `user_metadata`.
460
549
  * Any other keys in `data` are silently ignored. `data` cannot override `email`,
461
550
  * `password`, or `confirm`.
462
551
  *
463
- * Calls GoTrue `POST /admin/users` with the operator token.
552
+ * Calls `POST /admin/users` with the operator token.
464
553
  *
465
554
  * @throws {AuthError} If called from a browser, the email already exists,
466
555
  * or the operator token is missing.
@@ -469,7 +558,7 @@ interface Admin {
469
558
  /**
470
559
  * Updates an existing user by ID. Server-only.
471
560
  *
472
- * Calls GoTrue `PUT /admin/users/:id` with the operator token.
561
+ * Calls `PUT /admin/users/:id` with the operator token.
473
562
  *
474
563
  * @throws {AuthError} If called from a browser, the user is not found,
475
564
  * the update fails, or the operator token is missing.
@@ -478,7 +567,7 @@ interface Admin {
478
567
  /**
479
568
  * Deletes a user by ID. Server-only.
480
569
  *
481
- * Calls GoTrue `DELETE /admin/users/:id` with the operator token.
570
+ * Calls `DELETE /admin/users/:id` with the operator token.
482
571
  *
483
572
  * @throws {AuthError} If called from a browser, the user is not found,
484
573
  * the deletion fails, or the operator token is missing.
@@ -528,4 +617,4 @@ declare const verifyEmailChange: (token: string) => Promise<User>;
528
617
  */
529
618
  declare const updateUser: (updates: UserUpdates) => Promise<User>;
530
619
 
531
- export { AUTH_EVENTS, type Admin, type AdminUserUpdates, type AppMetadata, type AuthCallback, AuthError, type AuthEvent, type AuthProvider, type CallbackResult, type CreateUserParams, type IdentityConfig, type ListUsersOptions, MissingIdentityError, type Settings, type SignupData, type User, type UserUpdates, acceptInvite, admin, confirmEmail, getIdentityConfig, getSettings, getUser, handleAuthCallback, hydrateSession, isAuthenticated, login, logout, oauthLogin, onAuthChange, recoverPassword, refreshSession, requestPasswordRecovery, signup, updateUser, verifyEmailChange };
620
+ export { AUTH_EVENTS, type Admin, type AdminUserUpdates, type AppMetadata, type AuthCallback, AuthError, type AuthEvent, type AuthProvider, type CallbackResult, type CreateUserParams, type IdentityConfig, type ListUsersOptions, MissingIdentityError, type Settings, type SignupData, type User, type UserUpdates, type VerifyRequestOriginOptions, acceptInvite, admin, confirmEmail, getIdentityConfig, getSettings, getUser, handleAuthCallback, hydrateSession, isAuthenticated, login, logout, oauthLogin, onAuthChange, recoverPassword, refreshSession, requestPasswordRecovery, signup, updateUser, verifyEmailChange, verifyRequestOrigin };