@supabase/auth-js 2.80.1-canary.1 → 2.80.1-canary.2

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.
Files changed (65) hide show
  1. package/README.md +37 -19
  2. package/dist/main/AuthAdminApi.js +2 -4
  3. package/dist/main/AuthAdminApi.js.map +1 -1
  4. package/dist/main/AuthClient.js +2 -4
  5. package/dist/main/AuthClient.js.map +1 -1
  6. package/dist/main/GoTrueAdminApi.d.ts +48 -1
  7. package/dist/main/GoTrueAdminApi.d.ts.map +1 -1
  8. package/dist/main/GoTrueAdminApi.js +162 -12
  9. package/dist/main/GoTrueAdminApi.js.map +1 -1
  10. package/dist/main/GoTrueClient.d.ts +58 -2
  11. package/dist/main/GoTrueClient.d.ts.map +1 -1
  12. package/dist/main/GoTrueClient.js +293 -156
  13. package/dist/main/GoTrueClient.js.map +1 -1
  14. package/dist/main/index.js +7 -23
  15. package/dist/main/index.js.map +1 -1
  16. package/dist/main/lib/error-codes.d.ts +1 -1
  17. package/dist/main/lib/fetch.js +2 -12
  18. package/dist/main/lib/fetch.js.map +1 -1
  19. package/dist/main/lib/helpers.d.ts +11 -0
  20. package/dist/main/lib/helpers.d.ts.map +1 -1
  21. package/dist/main/lib/helpers.js +39 -42
  22. package/dist/main/lib/helpers.js.map +1 -1
  23. package/dist/main/lib/types.d.ts +283 -2
  24. package/dist/main/lib/types.d.ts.map +1 -1
  25. package/dist/main/lib/types.js.map +1 -1
  26. package/dist/main/lib/version.d.ts +1 -1
  27. package/dist/main/lib/version.js +1 -1
  28. package/dist/main/lib/webauthn.d.ts +7 -5
  29. package/dist/main/lib/webauthn.d.ts.map +1 -1
  30. package/dist/main/lib/webauthn.js +5 -15
  31. package/dist/main/lib/webauthn.js.map +1 -1
  32. package/dist/module/GoTrueAdminApi.d.ts +48 -1
  33. package/dist/module/GoTrueAdminApi.d.ts.map +1 -1
  34. package/dist/module/GoTrueAdminApi.js +161 -11
  35. package/dist/module/GoTrueAdminApi.js.map +1 -1
  36. package/dist/module/GoTrueClient.d.ts +58 -2
  37. package/dist/module/GoTrueClient.d.ts.map +1 -1
  38. package/dist/module/GoTrueClient.js +292 -153
  39. package/dist/module/GoTrueClient.js.map +1 -1
  40. package/dist/module/lib/error-codes.d.ts +1 -1
  41. package/dist/module/lib/fetch.js +1 -11
  42. package/dist/module/lib/fetch.js.map +1 -1
  43. package/dist/module/lib/helpers.d.ts +11 -0
  44. package/dist/module/lib/helpers.d.ts.map +1 -1
  45. package/dist/module/lib/helpers.js +38 -9
  46. package/dist/module/lib/helpers.js.map +1 -1
  47. package/dist/module/lib/types.d.ts +283 -2
  48. package/dist/module/lib/types.d.ts.map +1 -1
  49. package/dist/module/lib/types.js.map +1 -1
  50. package/dist/module/lib/version.d.ts +1 -1
  51. package/dist/module/lib/version.js +1 -1
  52. package/dist/module/lib/webauthn.d.ts +7 -5
  53. package/dist/module/lib/webauthn.d.ts.map +1 -1
  54. package/dist/module/lib/webauthn.js +3 -13
  55. package/dist/module/lib/webauthn.js.map +1 -1
  56. package/dist/tsconfig.module.tsbuildinfo +1 -0
  57. package/dist/tsconfig.tsbuildinfo +1 -0
  58. package/package.json +12 -13
  59. package/src/GoTrueAdminApi.ts +186 -0
  60. package/src/GoTrueClient.ts +378 -150
  61. package/src/lib/error-codes.ts +1 -1
  62. package/src/lib/helpers.ts +46 -8
  63. package/src/lib/types.ts +307 -1
  64. package/src/lib/version.ts +1 -1
  65. package/src/lib/webauthn.ts +12 -8
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Known error codes. Note that the server may also return other error codes
3
- * not included in this list (if the client library is older than the version
3
+ * not included in this list (if the SDK is older than the version
4
4
  * on the server).
5
5
  */
6
6
  export type ErrorCode =
@@ -94,16 +94,10 @@ export function parseParametersFromURL(href: string) {
94
94
  type Fetch = typeof fetch
95
95
 
96
96
  export const resolveFetch = (customFetch?: Fetch): Fetch => {
97
- let _fetch: Fetch
98
97
  if (customFetch) {
99
- _fetch = customFetch
100
- } else if (typeof fetch === 'undefined') {
101
- _fetch = (...args) =>
102
- import('@supabase/node-fetch' as any).then(({ default: fetch }) => fetch(...args))
103
- } else {
104
- _fetch = fetch
98
+ return (...args) => customFetch(...args)
105
99
  }
106
- return (...args) => _fetch(...args)
100
+ return (...args) => fetch(...args)
107
101
  }
108
102
 
109
103
  export const looksLikeFetchResponse = (maybeResponse: unknown): maybeResponse is Response => {
@@ -407,6 +401,50 @@ export function userNotAvailableProxy(): User {
407
401
  })
408
402
  }
409
403
 
404
+ /**
405
+ * Creates a proxy around a user object that warns when properties are accessed on the server.
406
+ * This is used to alert developers that using user data from getSession() on the server is insecure.
407
+ *
408
+ * @param user The actual user object to wrap
409
+ * @param suppressWarningRef An object with a 'value' property that controls warning suppression
410
+ * @returns A proxied user object that warns on property access
411
+ */
412
+ export function insecureUserWarningProxy(user: User, suppressWarningRef: { value: boolean }): User {
413
+ return new Proxy(user, {
414
+ get: (target: any, prop: string | symbol, receiver: any) => {
415
+ // Allow internal checks without warning
416
+ if (prop === '__isInsecureUserWarningProxy') {
417
+ return true
418
+ }
419
+
420
+ // Preventative check for common problematic symbols during cloning/inspection
421
+ // These symbols might be accessed by structuredClone or other internal mechanisms
422
+ if (typeof prop === 'symbol') {
423
+ const sProp = prop.toString()
424
+ if (
425
+ sProp === 'Symbol(Symbol.toPrimitive)' ||
426
+ sProp === 'Symbol(Symbol.toStringTag)' ||
427
+ sProp === 'Symbol(util.inspect.custom)' ||
428
+ sProp === 'Symbol(nodejs.util.inspect.custom)'
429
+ ) {
430
+ // Return the actual value for these symbols to allow proper inspection
431
+ return Reflect.get(target, prop, receiver)
432
+ }
433
+ }
434
+
435
+ // Emit warning on first property access
436
+ if (!suppressWarningRef.value && typeof prop === 'string') {
437
+ console.warn(
438
+ 'Using the user object as returned from supabase.auth.getSession() or from some supabase.auth.onAuthStateChange() events could be insecure! This value comes directly from the storage medium (usually cookies on the server) and may not be authentic. Use supabase.auth.getUser() instead which authenticates the data by contacting the Supabase Auth server.'
439
+ )
440
+ suppressWarningRef.value = true
441
+ }
442
+
443
+ return Reflect.get(target, prop, receiver)
444
+ },
445
+ })
446
+ }
447
+
410
448
  /**
411
449
  * Deep clones a JSON-serializable object using JSON.parse(JSON.stringify(obj)).
412
450
  * Note: Only works for JSON-safe data.
package/src/lib/types.ts CHANGED
@@ -107,6 +107,11 @@ export type GoTrueClientOptions = {
107
107
  * @experimental
108
108
  */
109
109
  hasCustomAuthorizationHeader?: boolean
110
+ /**
111
+ * If there is an error with the query, throwOnError will reject the promise by
112
+ * throwing the error instead of returning it as part of a successful response.
113
+ */
114
+ throwOnError?: boolean
110
115
  }
111
116
 
112
117
  const WeakPasswordReasons = ['length', 'characters', 'pwned'] as const
@@ -346,7 +351,14 @@ export type Factor<
346
351
  }
347
352
 
348
353
  export interface UserAppMetadata {
354
+ /**
355
+ * The first provider that the user used to sign up with.
356
+ */
349
357
  provider?: string
358
+ /**
359
+ * A list of all providers that the user has linked to their account.
360
+ */
361
+ providers?: string[]
350
362
  [key: string]: any
351
363
  }
352
364
 
@@ -1434,7 +1446,31 @@ export type RequiredClaims = {
1434
1446
  session_id: string
1435
1447
  }
1436
1448
 
1437
- export type JwtPayload = RequiredClaims & {
1449
+ /**
1450
+ * JWT Payload containing claims for Supabase authentication tokens.
1451
+ *
1452
+ * Required claims (iss, aud, exp, iat, sub, role, aal, session_id) are inherited from RequiredClaims.
1453
+ * All other claims are optional as they can be customized via Custom Access Token Hooks.
1454
+ *
1455
+ * @see https://supabase.com/docs/guides/auth/jwt-fields
1456
+ */
1457
+ export interface JwtPayload extends RequiredClaims {
1458
+ // Standard optional claims (can be customized via custom access token hooks)
1459
+ email?: string
1460
+ phone?: string
1461
+ is_anonymous?: boolean
1462
+
1463
+ // Optional claims
1464
+ jti?: string
1465
+ nbf?: number
1466
+ app_metadata?: UserAppMetadata
1467
+ user_metadata?: UserMetadata
1468
+ amr?: AMREntry[]
1469
+
1470
+ // Special claims (only in anon/service role tokens)
1471
+ ref?: string
1472
+
1473
+ // Allow custom claims via custom access token hooks
1438
1474
  [key: string]: any
1439
1475
  }
1440
1476
 
@@ -1448,3 +1484,273 @@ export interface JWK {
1448
1484
 
1449
1485
  export const SIGN_OUT_SCOPES = ['global', 'local', 'others'] as const
1450
1486
  export type SignOutScope = (typeof SIGN_OUT_SCOPES)[number]
1487
+
1488
+ /**
1489
+ * OAuth client grant types supported by the OAuth 2.1 server.
1490
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1491
+ */
1492
+ export type OAuthClientGrantType = 'authorization_code' | 'refresh_token'
1493
+
1494
+ /**
1495
+ * OAuth client response types supported by the OAuth 2.1 server.
1496
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1497
+ */
1498
+ export type OAuthClientResponseType = 'code'
1499
+
1500
+ /**
1501
+ * OAuth client type indicating whether the client can keep credentials confidential.
1502
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1503
+ */
1504
+ export type OAuthClientType = 'public' | 'confidential'
1505
+
1506
+ /**
1507
+ * OAuth client registration type.
1508
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1509
+ */
1510
+ export type OAuthClientRegistrationType = 'dynamic' | 'manual'
1511
+
1512
+ /**
1513
+ * OAuth client object returned from the OAuth 2.1 server.
1514
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1515
+ */
1516
+ export type OAuthClient = {
1517
+ /** Unique identifier for the OAuth client */
1518
+ client_id: string
1519
+ /** Human-readable name of the OAuth client */
1520
+ client_name: string
1521
+ /** Client secret (only returned on registration and regeneration) */
1522
+ client_secret?: string
1523
+ /** Type of OAuth client */
1524
+ client_type: OAuthClientType
1525
+ /** Token endpoint authentication method */
1526
+ token_endpoint_auth_method: string
1527
+ /** Registration type of the client */
1528
+ registration_type: OAuthClientRegistrationType
1529
+ /** URI of the OAuth client */
1530
+ client_uri?: string
1531
+ /** URI of the OAuth client's logo */
1532
+ logo_uri?: string
1533
+ /** Array of allowed redirect URIs */
1534
+ redirect_uris: string[]
1535
+ /** Array of allowed grant types */
1536
+ grant_types: OAuthClientGrantType[]
1537
+ /** Array of allowed response types */
1538
+ response_types: OAuthClientResponseType[]
1539
+ /** Scope of the OAuth client */
1540
+ scope?: string
1541
+ /** Timestamp when the client was created */
1542
+ created_at: string
1543
+ /** Timestamp when the client was last updated */
1544
+ updated_at: string
1545
+ }
1546
+
1547
+ /**
1548
+ * Parameters for creating a new OAuth client.
1549
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1550
+ */
1551
+ export type CreateOAuthClientParams = {
1552
+ /** Human-readable name of the OAuth client */
1553
+ client_name: string
1554
+ /** URI of the OAuth client */
1555
+ client_uri?: string
1556
+ /** Array of allowed redirect URIs */
1557
+ redirect_uris: string[]
1558
+ /** Array of allowed grant types (optional, defaults to authorization_code and refresh_token) */
1559
+ grant_types?: OAuthClientGrantType[]
1560
+ /** Array of allowed response types (optional, defaults to code) */
1561
+ response_types?: OAuthClientResponseType[]
1562
+ /** Scope of the OAuth client */
1563
+ scope?: string
1564
+ }
1565
+
1566
+ /**
1567
+ * Parameters for updating an existing OAuth client.
1568
+ * All fields are optional. Only provided fields will be updated.
1569
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1570
+ */
1571
+ export type UpdateOAuthClientParams = {
1572
+ /** Human-readable name of the OAuth client */
1573
+ client_name?: string
1574
+ /** URI of the OAuth client */
1575
+ client_uri?: string
1576
+ /** URI of the OAuth client's logo */
1577
+ logo_uri?: string
1578
+ /** Array of allowed redirect URIs */
1579
+ redirect_uris?: string[]
1580
+ /** Array of allowed grant types */
1581
+ grant_types?: OAuthClientGrantType[]
1582
+ }
1583
+
1584
+ /**
1585
+ * Response type for OAuth client operations.
1586
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1587
+ */
1588
+ export type OAuthClientResponse = RequestResult<OAuthClient>
1589
+
1590
+ /**
1591
+ * Response type for listing OAuth clients.
1592
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1593
+ */
1594
+ export type OAuthClientListResponse =
1595
+ | {
1596
+ data: { clients: OAuthClient[]; aud: string } & Pagination
1597
+ error: null
1598
+ }
1599
+ | {
1600
+ data: { clients: [] }
1601
+ error: AuthError
1602
+ }
1603
+
1604
+ /**
1605
+ * Contains all OAuth client administration methods.
1606
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1607
+ */
1608
+ export interface GoTrueAdminOAuthApi {
1609
+ /**
1610
+ * Lists all OAuth clients with optional pagination.
1611
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1612
+ *
1613
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
1614
+ */
1615
+ listClients(params?: PageParams): Promise<OAuthClientListResponse>
1616
+
1617
+ /**
1618
+ * Creates a new OAuth client.
1619
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1620
+ *
1621
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
1622
+ */
1623
+ createClient(params: CreateOAuthClientParams): Promise<OAuthClientResponse>
1624
+
1625
+ /**
1626
+ * Gets details of a specific OAuth client.
1627
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1628
+ *
1629
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
1630
+ */
1631
+ getClient(clientId: string): Promise<OAuthClientResponse>
1632
+
1633
+ /**
1634
+ * Updates an existing OAuth client.
1635
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1636
+ *
1637
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
1638
+ */
1639
+ updateClient(clientId: string, params: UpdateOAuthClientParams): Promise<OAuthClientResponse>
1640
+
1641
+ /**
1642
+ * Deletes an OAuth client.
1643
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1644
+ *
1645
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
1646
+ */
1647
+ deleteClient(clientId: string): Promise<{ data: null; error: AuthError | null }>
1648
+
1649
+ /**
1650
+ * Regenerates the secret for an OAuth client.
1651
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1652
+ *
1653
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
1654
+ */
1655
+ regenerateClientSecret(clientId: string): Promise<OAuthClientResponse>
1656
+ }
1657
+
1658
+ /**
1659
+ * OAuth client details in an authorization request.
1660
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1661
+ */
1662
+ export type OAuthAuthorizationClient = {
1663
+ /** Unique identifier for the OAuth client (UUID) */
1664
+ client_id: string
1665
+ /** Human-readable name of the OAuth client */
1666
+ client_name: string
1667
+ /** URI of the OAuth client's website */
1668
+ client_uri: string
1669
+ /** URI of the OAuth client's logo */
1670
+ logo_uri: string
1671
+ }
1672
+
1673
+ /**
1674
+ * OAuth authorization details for the consent flow.
1675
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1676
+ */
1677
+ export type OAuthAuthorizationDetails = {
1678
+ /** The authorization ID */
1679
+ authorization_id: string
1680
+ /** Redirect URI - present if user already consented (can be used to trigger immediate redirect) */
1681
+ redirect_uri?: string
1682
+ /** OAuth client requesting authorization */
1683
+ client: OAuthAuthorizationClient
1684
+ /** User object associated with the authorization */
1685
+ user: {
1686
+ /** User ID (UUID) */
1687
+ id: string
1688
+ /** User email */
1689
+ email: string
1690
+ }
1691
+ /** Space-separated list of requested scopes */
1692
+ scope: string
1693
+ }
1694
+
1695
+ /**
1696
+ * Response type for getting OAuth authorization details.
1697
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1698
+ */
1699
+ export type AuthOAuthAuthorizationDetailsResponse = RequestResult<OAuthAuthorizationDetails>
1700
+
1701
+ /**
1702
+ * Response type for OAuth consent decision (approve/deny).
1703
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1704
+ */
1705
+ export type AuthOAuthConsentResponse = RequestResult<{
1706
+ /** URL to redirect the user back to the OAuth client */
1707
+ redirect_url: string
1708
+ }>
1709
+
1710
+ /**
1711
+ * Contains all OAuth 2.1 authorization server user-facing methods.
1712
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1713
+ *
1714
+ * These methods are used to implement the consent page.
1715
+ */
1716
+ export interface AuthOAuthServerApi {
1717
+ /**
1718
+ * Retrieves details about an OAuth authorization request.
1719
+ * Used to display consent information to the user.
1720
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1721
+ *
1722
+ * This method returns authorization details including client info, scopes, and user information.
1723
+ * If the response includes a redirect_uri, it means consent was already given - the caller
1724
+ * should handle the redirect manually if needed.
1725
+ *
1726
+ * @param authorizationId - The authorization ID from the authorization request
1727
+ * @returns Authorization details including client info and requested scopes
1728
+ */
1729
+ getAuthorizationDetails(authorizationId: string): Promise<AuthOAuthAuthorizationDetailsResponse>
1730
+
1731
+ /**
1732
+ * Approves an OAuth authorization request.
1733
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1734
+ *
1735
+ * @param authorizationId - The authorization ID to approve
1736
+ * @param options - Optional parameters including skipBrowserRedirect
1737
+ * @returns Redirect URL to send the user back to the OAuth client
1738
+ */
1739
+ approveAuthorization(
1740
+ authorizationId: string,
1741
+ options?: { skipBrowserRedirect?: boolean }
1742
+ ): Promise<AuthOAuthConsentResponse>
1743
+
1744
+ /**
1745
+ * Denies an OAuth authorization request.
1746
+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1747
+ *
1748
+ * @param authorizationId - The authorization ID to deny
1749
+ * @param options - Optional parameters including skipBrowserRedirect
1750
+ * @returns Redirect URL to send the user back to the OAuth client
1751
+ */
1752
+ denyAuthorization(
1753
+ authorizationId: string,
1754
+ options?: { skipBrowserRedirect?: boolean }
1755
+ ): Promise<AuthOAuthConsentResponse>
1756
+ }
@@ -4,4 +4,4 @@
4
4
  // - Debugging and support (identifying which version is running)
5
5
  // - Telemetry and logging (version reporting in errors/analytics)
6
6
  // - Ensuring build artifacts match the published package version
7
- export const version = '2.80.1-canary.1'
7
+ export const version = '2.80.1-canary.2'
@@ -763,10 +763,10 @@ export class WebAuthnApi {
763
763
  rpId = typeof window !== 'undefined' ? window.location.hostname : undefined,
764
764
  rpOrigins = typeof window !== 'undefined' ? [window.location.origin] : undefined,
765
765
  signal,
766
- },
766
+ } = {},
767
767
  }: {
768
768
  factorId: string
769
- webauthn: {
769
+ webauthn?: {
770
770
  rpId?: string
771
771
  rpOrigins?: string[]
772
772
  signal?: AbortSignal
@@ -844,14 +844,18 @@ export class WebAuthnApi {
844
844
  public async _register(
845
845
  {
846
846
  friendlyName,
847
- rpId = typeof window !== 'undefined' ? window.location.hostname : undefined,
848
- rpOrigins = typeof window !== 'undefined' ? [window.location.origin] : undefined,
849
- signal,
847
+ webauthn: {
848
+ rpId = typeof window !== 'undefined' ? window.location.hostname : undefined,
849
+ rpOrigins = typeof window !== 'undefined' ? [window.location.origin] : undefined,
850
+ signal,
851
+ } = {},
850
852
  }: {
851
853
  friendlyName: string
852
- rpId?: string
853
- rpOrigins?: string[]
854
- signal?: AbortSignal
854
+ webauthn?: {
855
+ rpId?: string
856
+ rpOrigins?: string[]
857
+ signal?: AbortSignal
858
+ }
855
859
  },
856
860
  overrides?: Partial<PublicKeyCredentialCreationOptionsFuture>
857
861
  ): Promise<RequestResult<AuthMFAVerifyResponseData, WebAuthnError | AuthError>> {