@netlify/identity 0.4.1 → 1.0.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;
@@ -92,11 +92,9 @@ interface AdminUserUpdates {
92
92
  app_metadata?: Record<string, unknown>;
93
93
  /** User-managed metadata (display name, avatar, preferences, etc.). */
94
94
  user_metadata?: Record<string, unknown>;
95
- [key: string]: unknown;
96
95
  }
97
96
  /**
98
- * Options for {@link admin.listUsers}. Only used on the server;
99
- * pagination is ignored in the browser (gotrue-js limitation).
97
+ * Pagination options for {@link admin.listUsers}.
100
98
  */
101
99
  interface ListUsersOptions {
102
100
  /** 1-based page number. */
@@ -107,9 +105,10 @@ interface ListUsersOptions {
107
105
  /**
108
106
  * Parameters for {@link admin.createUser}.
109
107
  *
110
- * The optional `data` fields are spread as top-level attributes in the GoTrue
111
- * request body (not nested under `user_metadata`). Use this to set `app_metadata`,
112
- * `user_metadata`, `role`, or other GoTrue user fields at creation time.
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`,
110
+ * `user_metadata`. Any other keys are silently ignored. `data` cannot override
111
+ * `email`, `password`, or `confirm`.
113
112
  *
114
113
  * @example
115
114
  * ```ts
@@ -123,14 +122,18 @@ interface ListUsersOptions {
123
122
  interface CreateUserParams {
124
123
  email: string;
125
124
  password: string;
126
- /** Additional GoTrue user fields spread into the request body. */
125
+ /** Identity user fields: `role`, `app_metadata`, `user_metadata`. Other keys are ignored. */
127
126
  data?: Record<string, unknown>;
128
127
  }
129
128
 
130
129
  /**
131
130
  * A normalized user object returned by all auth and admin functions.
132
131
  * Provides a consistent shape regardless of whether the user was loaded
133
- * 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.
134
137
  *
135
138
  * @example
136
139
  * ```ts
@@ -141,30 +144,46 @@ interface CreateUserParams {
141
144
  * ```
142
145
  */
143
146
  interface User {
144
- /** The user's unique identifier (GoTrue UUID). */
147
+ /** The user's unique identifier. */
145
148
  id: string;
146
149
  /** The user's email address. */
147
150
  email?: string;
148
- /** `true` if the user's email has been confirmed. */
149
- emailVerified?: boolean;
151
+ /** ISO 8601 timestamp of when the user's email was confirmed. `undefined` if not yet confirmed. */
152
+ confirmedAt?: string;
150
153
  /** ISO 8601 timestamp of when the account was created. */
151
154
  createdAt?: string;
152
155
  /** ISO 8601 timestamp of the last account update. */
153
156
  updatedAt?: string;
154
- /** 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`). */
155
164
  provider?: AuthProvider;
156
165
  /** Display name from `user_metadata.full_name` or `user_metadata.name`. */
157
166
  name?: string;
158
167
  /** Avatar URL from `user_metadata.avatar_url`. */
159
168
  pictureUrl?: string;
160
- /** 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. */
161
170
  roles?: string[];
162
- /** The full `user_metadata` object. */
163
- metadata?: Record<string, unknown>;
164
- /** 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. */
165
186
  appMetadata?: Record<string, unknown>;
166
- /** The raw GoTrue user data, for accessing fields not mapped to this interface. */
167
- rawGoTrueData?: Record<string, unknown>;
168
187
  }
169
188
  /**
170
189
  * Returns the currently authenticated user, or `null` if not logged in.
@@ -174,11 +193,11 @@ interface User {
174
193
  * (email, roles, timestamps, metadata, etc.) regardless of whether the
175
194
  * call happens in the browser or on the server.
176
195
  *
177
- * In the browser, checks gotrue-js localStorage first. If no localStorage
196
+ * In the browser, checks localStorage first. If no localStorage
178
197
  * session exists, hydrates from the `nf_jwt` cookie (set by server-side login).
179
198
  *
180
- * On the server, fetches the full user from GoTrue using the JWT from
181
- * 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.
182
201
  *
183
202
  * On the server in a Next.js App Router context, calls `headers()` from
184
203
  * `next/headers` to opt the route into dynamic rendering. Without this,
@@ -342,7 +361,7 @@ interface CallbackResult {
342
361
  */
343
362
  declare const handleAuthCallback: () => Promise<CallbackResult | null>;
344
363
  /**
345
- * Hydrates the browser-side gotrue-js session from server-set auth cookies.
364
+ * Hydrates the browser-side session from server-set auth cookies.
346
365
  * Call this on page load when using server-side login to enable browser
347
366
  * account operations (updateUser, verifyEmailChange, etc.).
348
367
  *
@@ -387,7 +406,7 @@ declare const refreshSession: () => Promise<string | null>;
387
406
  * Thrown by auth operations when something goes wrong: invalid credentials,
388
407
  * network failures, missing runtime context, etc.
389
408
  *
390
- * The `status` field contains the HTTP status code from GoTrue when available
409
+ * The `status` field contains the HTTP status code from the Identity API when available
391
410
  * (e.g., 401 for bad credentials, 422 for validation errors).
392
411
  * The `cause` field preserves the original error for debugging.
393
412
  *
@@ -404,7 +423,7 @@ declare const refreshSession: () => Promise<string | null>;
404
423
  */
405
424
  declare class AuthError extends Error {
406
425
  name: string;
407
- /** HTTP status code from GoTrue, if the error originated from an API response. */
426
+ /** HTTP status code from the Identity API, if the error originated from an API response. */
408
427
  status?: number;
409
428
  cause?: unknown;
410
429
  constructor(message: string, status?: number, options?: {
@@ -413,7 +432,7 @@ declare class AuthError extends Error {
413
432
  static from(error: unknown): AuthError;
414
433
  }
415
434
  /**
416
- * Thrown when a function requires a gotrue-js client but Netlify Identity
435
+ * Thrown when a function requires the Identity client but Netlify Identity
417
436
  * is not configured (no endpoint URL could be discovered).
418
437
  *
419
438
  * This typically means the site does not have Identity enabled, or the app
@@ -426,75 +445,61 @@ declare class MissingIdentityError extends Error {
426
445
 
427
446
  /**
428
447
  * The admin namespace for privileged user management operations.
429
- * All methods work in both server and browser contexts.
448
+ * All methods are server-only and require the operator token
449
+ * (automatically available in Netlify Functions and Edge Functions).
430
450
  *
431
- * **Server:** uses the operator token (automatically available in Netlify Functions).
432
- * **Browser:** requires a logged-in user with an admin role.
451
+ * Calling any admin method from a browser environment throws an `AuthError`.
433
452
  */
434
453
  interface Admin {
435
454
  /**
436
- * Lists all users. Works in both server and browser contexts.
455
+ * Lists all users. Server-only.
437
456
  *
438
- * **Server:** calls GoTrue `GET /admin/users` with the operator token. Pagination
457
+ * Calls `GET /admin/users` with the operator token. Pagination
439
458
  * options (`page`, `perPage`) are forwarded as query parameters.
440
459
  *
441
- * **Browser:** calls gotrue-js `user.admin.listUsers()`. The logged-in user must
442
- * have an admin role. Pagination options are ignored (gotrue-js does not support them).
443
- *
444
- * @throws {AuthError} If the operator token is missing (server) or no admin user is logged in (browser).
460
+ * @throws {AuthError} If called from a browser, or if the operator token is missing.
445
461
  */
446
462
  listUsers: (options?: ListUsersOptions) => Promise<User[]>;
447
463
  /**
448
- * Gets a single user by ID. Works in both server and browser contexts.
449
- *
450
- * **Server:** calls GoTrue `GET /admin/users/:id` with the operator token.
464
+ * Gets a single user by ID. Server-only.
451
465
  *
452
- * **Browser:** calls gotrue-js `user.admin.getUser()`. The logged-in user must
453
- * have an admin role.
466
+ * Calls `GET /admin/users/:id` with the operator token.
454
467
  *
455
- * @throws {AuthError} If the user is not found, the operator token is missing (server),
456
- * or no admin user is logged in (browser).
468
+ * @throws {AuthError} If called from a browser, the user is not found,
469
+ * or the operator token is missing.
457
470
  */
458
471
  getUser: (userId: string) => Promise<User>;
459
472
  /**
460
473
  * Creates a new user. The user is auto-confirmed (no confirmation email is sent).
461
- * Works in both server and browser contexts.
462
- *
463
- * The optional `data` fields are spread as **top-level attributes** in the GoTrue
464
- * request body (not nested under `user_metadata`). Use this to set `app_metadata`,
465
- * `user_metadata`, `role`, or any other GoTrue user field at creation time.
474
+ * Server-only.
466
475
  *
467
- * **Server:** calls GoTrue `POST /admin/users` with the operator token.
476
+ * The optional `data` fields are forwarded as top-level attributes in the Identity API
477
+ * request body. Accepted fields: `role`, `app_metadata`, `user_metadata`.
478
+ * Any other keys in `data` are silently ignored. `data` cannot override `email`,
479
+ * `password`, or `confirm`.
468
480
  *
469
- * **Browser:** calls gotrue-js `user.admin.createUser()`. The logged-in user must
470
- * have an admin role.
481
+ * Calls `POST /admin/users` with the operator token.
471
482
  *
472
- * @throws {AuthError} If the email already exists, the operator token is missing (server),
473
- * or no admin user is logged in (browser).
483
+ * @throws {AuthError} If called from a browser, the email already exists,
484
+ * or the operator token is missing.
474
485
  */
475
486
  createUser: (params: CreateUserParams) => Promise<User>;
476
487
  /**
477
- * Updates an existing user by ID. Works in both server and browser contexts.
488
+ * Updates an existing user by ID. Server-only.
478
489
  *
479
- * **Server:** calls GoTrue `PUT /admin/users/:id` with the operator token.
490
+ * Calls `PUT /admin/users/:id` with the operator token.
480
491
  *
481
- * **Browser:** calls gotrue-js `user.admin.updateUser()`. The logged-in user must
482
- * have an admin role.
483
- *
484
- * @throws {AuthError} If the user is not found, the update fails, the operator token
485
- * is missing (server), or no admin user is logged in (browser).
492
+ * @throws {AuthError} If called from a browser, the user is not found,
493
+ * the update fails, or the operator token is missing.
486
494
  */
487
495
  updateUser: (userId: string, attributes: AdminUserUpdates) => Promise<User>;
488
496
  /**
489
- * Deletes a user by ID. Works in both server and browser contexts.
490
- *
491
- * **Server:** calls GoTrue `DELETE /admin/users/:id` with the operator token.
497
+ * Deletes a user by ID. Server-only.
492
498
  *
493
- * **Browser:** calls gotrue-js `user.admin.deleteUser()`. The logged-in user must
494
- * have an admin role.
499
+ * Calls `DELETE /admin/users/:id` with the operator token.
495
500
  *
496
- * @throws {AuthError} If the user is not found, the deletion fails, the operator token
497
- * is missing (server), or no admin user is logged in (browser).
501
+ * @throws {AuthError} If called from a browser, the user is not found,
502
+ * the deletion fails, or the operator token is missing.
498
503
  */
499
504
  deleteUser: (userId: string) => Promise<void>;
500
505
  }
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;
@@ -92,11 +92,9 @@ interface AdminUserUpdates {
92
92
  app_metadata?: Record<string, unknown>;
93
93
  /** User-managed metadata (display name, avatar, preferences, etc.). */
94
94
  user_metadata?: Record<string, unknown>;
95
- [key: string]: unknown;
96
95
  }
97
96
  /**
98
- * Options for {@link admin.listUsers}. Only used on the server;
99
- * pagination is ignored in the browser (gotrue-js limitation).
97
+ * Pagination options for {@link admin.listUsers}.
100
98
  */
101
99
  interface ListUsersOptions {
102
100
  /** 1-based page number. */
@@ -107,9 +105,10 @@ interface ListUsersOptions {
107
105
  /**
108
106
  * Parameters for {@link admin.createUser}.
109
107
  *
110
- * The optional `data` fields are spread as top-level attributes in the GoTrue
111
- * request body (not nested under `user_metadata`). Use this to set `app_metadata`,
112
- * `user_metadata`, `role`, or other GoTrue user fields at creation time.
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`,
110
+ * `user_metadata`. Any other keys are silently ignored. `data` cannot override
111
+ * `email`, `password`, or `confirm`.
113
112
  *
114
113
  * @example
115
114
  * ```ts
@@ -123,14 +122,18 @@ interface ListUsersOptions {
123
122
  interface CreateUserParams {
124
123
  email: string;
125
124
  password: string;
126
- /** Additional GoTrue user fields spread into the request body. */
125
+ /** Identity user fields: `role`, `app_metadata`, `user_metadata`. Other keys are ignored. */
127
126
  data?: Record<string, unknown>;
128
127
  }
129
128
 
130
129
  /**
131
130
  * A normalized user object returned by all auth and admin functions.
132
131
  * Provides a consistent shape regardless of whether the user was loaded
133
- * 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.
134
137
  *
135
138
  * @example
136
139
  * ```ts
@@ -141,30 +144,46 @@ interface CreateUserParams {
141
144
  * ```
142
145
  */
143
146
  interface User {
144
- /** The user's unique identifier (GoTrue UUID). */
147
+ /** The user's unique identifier. */
145
148
  id: string;
146
149
  /** The user's email address. */
147
150
  email?: string;
148
- /** `true` if the user's email has been confirmed. */
149
- emailVerified?: boolean;
151
+ /** ISO 8601 timestamp of when the user's email was confirmed. `undefined` if not yet confirmed. */
152
+ confirmedAt?: string;
150
153
  /** ISO 8601 timestamp of when the account was created. */
151
154
  createdAt?: string;
152
155
  /** ISO 8601 timestamp of the last account update. */
153
156
  updatedAt?: string;
154
- /** 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`). */
155
164
  provider?: AuthProvider;
156
165
  /** Display name from `user_metadata.full_name` or `user_metadata.name`. */
157
166
  name?: string;
158
167
  /** Avatar URL from `user_metadata.avatar_url`. */
159
168
  pictureUrl?: string;
160
- /** 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. */
161
170
  roles?: string[];
162
- /** The full `user_metadata` object. */
163
- metadata?: Record<string, unknown>;
164
- /** 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. */
165
186
  appMetadata?: Record<string, unknown>;
166
- /** The raw GoTrue user data, for accessing fields not mapped to this interface. */
167
- rawGoTrueData?: Record<string, unknown>;
168
187
  }
169
188
  /**
170
189
  * Returns the currently authenticated user, or `null` if not logged in.
@@ -174,11 +193,11 @@ interface User {
174
193
  * (email, roles, timestamps, metadata, etc.) regardless of whether the
175
194
  * call happens in the browser or on the server.
176
195
  *
177
- * In the browser, checks gotrue-js localStorage first. If no localStorage
196
+ * In the browser, checks localStorage first. If no localStorage
178
197
  * session exists, hydrates from the `nf_jwt` cookie (set by server-side login).
179
198
  *
180
- * On the server, fetches the full user from GoTrue using the JWT from
181
- * 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.
182
201
  *
183
202
  * On the server in a Next.js App Router context, calls `headers()` from
184
203
  * `next/headers` to opt the route into dynamic rendering. Without this,
@@ -342,7 +361,7 @@ interface CallbackResult {
342
361
  */
343
362
  declare const handleAuthCallback: () => Promise<CallbackResult | null>;
344
363
  /**
345
- * Hydrates the browser-side gotrue-js session from server-set auth cookies.
364
+ * Hydrates the browser-side session from server-set auth cookies.
346
365
  * Call this on page load when using server-side login to enable browser
347
366
  * account operations (updateUser, verifyEmailChange, etc.).
348
367
  *
@@ -387,7 +406,7 @@ declare const refreshSession: () => Promise<string | null>;
387
406
  * Thrown by auth operations when something goes wrong: invalid credentials,
388
407
  * network failures, missing runtime context, etc.
389
408
  *
390
- * The `status` field contains the HTTP status code from GoTrue when available
409
+ * The `status` field contains the HTTP status code from the Identity API when available
391
410
  * (e.g., 401 for bad credentials, 422 for validation errors).
392
411
  * The `cause` field preserves the original error for debugging.
393
412
  *
@@ -404,7 +423,7 @@ declare const refreshSession: () => Promise<string | null>;
404
423
  */
405
424
  declare class AuthError extends Error {
406
425
  name: string;
407
- /** HTTP status code from GoTrue, if the error originated from an API response. */
426
+ /** HTTP status code from the Identity API, if the error originated from an API response. */
408
427
  status?: number;
409
428
  cause?: unknown;
410
429
  constructor(message: string, status?: number, options?: {
@@ -413,7 +432,7 @@ declare class AuthError extends Error {
413
432
  static from(error: unknown): AuthError;
414
433
  }
415
434
  /**
416
- * Thrown when a function requires a gotrue-js client but Netlify Identity
435
+ * Thrown when a function requires the Identity client but Netlify Identity
417
436
  * is not configured (no endpoint URL could be discovered).
418
437
  *
419
438
  * This typically means the site does not have Identity enabled, or the app
@@ -426,75 +445,61 @@ declare class MissingIdentityError extends Error {
426
445
 
427
446
  /**
428
447
  * The admin namespace for privileged user management operations.
429
- * All methods work in both server and browser contexts.
448
+ * All methods are server-only and require the operator token
449
+ * (automatically available in Netlify Functions and Edge Functions).
430
450
  *
431
- * **Server:** uses the operator token (automatically available in Netlify Functions).
432
- * **Browser:** requires a logged-in user with an admin role.
451
+ * Calling any admin method from a browser environment throws an `AuthError`.
433
452
  */
434
453
  interface Admin {
435
454
  /**
436
- * Lists all users. Works in both server and browser contexts.
455
+ * Lists all users. Server-only.
437
456
  *
438
- * **Server:** calls GoTrue `GET /admin/users` with the operator token. Pagination
457
+ * Calls `GET /admin/users` with the operator token. Pagination
439
458
  * options (`page`, `perPage`) are forwarded as query parameters.
440
459
  *
441
- * **Browser:** calls gotrue-js `user.admin.listUsers()`. The logged-in user must
442
- * have an admin role. Pagination options are ignored (gotrue-js does not support them).
443
- *
444
- * @throws {AuthError} If the operator token is missing (server) or no admin user is logged in (browser).
460
+ * @throws {AuthError} If called from a browser, or if the operator token is missing.
445
461
  */
446
462
  listUsers: (options?: ListUsersOptions) => Promise<User[]>;
447
463
  /**
448
- * Gets a single user by ID. Works in both server and browser contexts.
449
- *
450
- * **Server:** calls GoTrue `GET /admin/users/:id` with the operator token.
464
+ * Gets a single user by ID. Server-only.
451
465
  *
452
- * **Browser:** calls gotrue-js `user.admin.getUser()`. The logged-in user must
453
- * have an admin role.
466
+ * Calls `GET /admin/users/:id` with the operator token.
454
467
  *
455
- * @throws {AuthError} If the user is not found, the operator token is missing (server),
456
- * or no admin user is logged in (browser).
468
+ * @throws {AuthError} If called from a browser, the user is not found,
469
+ * or the operator token is missing.
457
470
  */
458
471
  getUser: (userId: string) => Promise<User>;
459
472
  /**
460
473
  * Creates a new user. The user is auto-confirmed (no confirmation email is sent).
461
- * Works in both server and browser contexts.
462
- *
463
- * The optional `data` fields are spread as **top-level attributes** in the GoTrue
464
- * request body (not nested under `user_metadata`). Use this to set `app_metadata`,
465
- * `user_metadata`, `role`, or any other GoTrue user field at creation time.
474
+ * Server-only.
466
475
  *
467
- * **Server:** calls GoTrue `POST /admin/users` with the operator token.
476
+ * The optional `data` fields are forwarded as top-level attributes in the Identity API
477
+ * request body. Accepted fields: `role`, `app_metadata`, `user_metadata`.
478
+ * Any other keys in `data` are silently ignored. `data` cannot override `email`,
479
+ * `password`, or `confirm`.
468
480
  *
469
- * **Browser:** calls gotrue-js `user.admin.createUser()`. The logged-in user must
470
- * have an admin role.
481
+ * Calls `POST /admin/users` with the operator token.
471
482
  *
472
- * @throws {AuthError} If the email already exists, the operator token is missing (server),
473
- * or no admin user is logged in (browser).
483
+ * @throws {AuthError} If called from a browser, the email already exists,
484
+ * or the operator token is missing.
474
485
  */
475
486
  createUser: (params: CreateUserParams) => Promise<User>;
476
487
  /**
477
- * Updates an existing user by ID. Works in both server and browser contexts.
488
+ * Updates an existing user by ID. Server-only.
478
489
  *
479
- * **Server:** calls GoTrue `PUT /admin/users/:id` with the operator token.
490
+ * Calls `PUT /admin/users/:id` with the operator token.
480
491
  *
481
- * **Browser:** calls gotrue-js `user.admin.updateUser()`. The logged-in user must
482
- * have an admin role.
483
- *
484
- * @throws {AuthError} If the user is not found, the update fails, the operator token
485
- * is missing (server), or no admin user is logged in (browser).
492
+ * @throws {AuthError} If called from a browser, the user is not found,
493
+ * the update fails, or the operator token is missing.
486
494
  */
487
495
  updateUser: (userId: string, attributes: AdminUserUpdates) => Promise<User>;
488
496
  /**
489
- * Deletes a user by ID. Works in both server and browser contexts.
490
- *
491
- * **Server:** calls GoTrue `DELETE /admin/users/:id` with the operator token.
497
+ * Deletes a user by ID. Server-only.
492
498
  *
493
- * **Browser:** calls gotrue-js `user.admin.deleteUser()`. The logged-in user must
494
- * have an admin role.
499
+ * Calls `DELETE /admin/users/:id` with the operator token.
495
500
  *
496
- * @throws {AuthError} If the user is not found, the deletion fails, the operator token
497
- * is missing (server), or no admin user is logged in (browser).
501
+ * @throws {AuthError} If called from a browser, the user is not found,
502
+ * the deletion fails, or the operator token is missing.
498
503
  */
499
504
  deleteUser: (userId: string) => Promise<void>;
500
505
  }