@supabase/auth-js 3.0.0-next.1 → 3.0.0-next.10

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 (60) hide show
  1. package/dist/main/GoTrueAdminApi.d.ts +28 -4
  2. package/dist/main/GoTrueAdminApi.d.ts.map +1 -1
  3. package/dist/main/GoTrueAdminApi.js +50 -3
  4. package/dist/main/GoTrueAdminApi.js.map +1 -1
  5. package/dist/main/GoTrueClient.d.ts +65 -3
  6. package/dist/main/GoTrueClient.d.ts.map +1 -1
  7. package/dist/main/GoTrueClient.js +348 -7
  8. package/dist/main/GoTrueClient.js.map +1 -1
  9. package/dist/main/lib/fetch.d.ts +1 -1
  10. package/dist/main/lib/fetch.d.ts.map +1 -1
  11. package/dist/main/lib/helpers.d.ts +3 -0
  12. package/dist/main/lib/helpers.d.ts.map +1 -1
  13. package/dist/main/lib/helpers.js +7 -1
  14. package/dist/main/lib/helpers.js.map +1 -1
  15. package/dist/main/lib/types.d.ts +128 -1
  16. package/dist/main/lib/types.d.ts.map +1 -1
  17. package/dist/main/lib/types.js.map +1 -1
  18. package/dist/main/lib/version.d.ts +1 -1
  19. package/dist/main/lib/version.d.ts.map +1 -1
  20. package/dist/main/lib/version.js +1 -1
  21. package/dist/main/lib/version.js.map +1 -1
  22. package/dist/main/lib/webauthn.d.ts +8 -0
  23. package/dist/main/lib/webauthn.d.ts.map +1 -1
  24. package/dist/main/lib/webauthn.js +1 -0
  25. package/dist/main/lib/webauthn.js.map +1 -1
  26. package/dist/module/GoTrueAdminApi.d.ts +28 -4
  27. package/dist/module/GoTrueAdminApi.d.ts.map +1 -1
  28. package/dist/module/GoTrueAdminApi.js +51 -4
  29. package/dist/module/GoTrueAdminApi.js.map +1 -1
  30. package/dist/module/GoTrueClient.d.ts +65 -3
  31. package/dist/module/GoTrueClient.d.ts.map +1 -1
  32. package/dist/module/GoTrueClient.js +350 -9
  33. package/dist/module/GoTrueClient.js.map +1 -1
  34. package/dist/module/lib/fetch.d.ts +1 -1
  35. package/dist/module/lib/fetch.d.ts.map +1 -1
  36. package/dist/module/lib/helpers.d.ts +3 -0
  37. package/dist/module/lib/helpers.d.ts.map +1 -1
  38. package/dist/module/lib/helpers.js +6 -1
  39. package/dist/module/lib/helpers.js.map +1 -1
  40. package/dist/module/lib/types.d.ts +128 -1
  41. package/dist/module/lib/types.d.ts.map +1 -1
  42. package/dist/module/lib/types.js.map +1 -1
  43. package/dist/module/lib/version.d.ts +1 -1
  44. package/dist/module/lib/version.d.ts.map +1 -1
  45. package/dist/module/lib/version.js +1 -1
  46. package/dist/module/lib/version.js.map +1 -1
  47. package/dist/module/lib/webauthn.d.ts +8 -0
  48. package/dist/module/lib/webauthn.d.ts.map +1 -1
  49. package/dist/module/lib/webauthn.js +1 -1
  50. package/dist/module/lib/webauthn.js.map +1 -1
  51. package/dist/tsconfig.module.tsbuildinfo +1 -1
  52. package/dist/tsconfig.tsbuildinfo +1 -1
  53. package/package.json +1 -1
  54. package/src/GoTrueAdminApi.ts +82 -3
  55. package/src/GoTrueClient.ts +440 -4
  56. package/src/lib/fetch.ts +1 -1
  57. package/src/lib/helpers.ts +9 -1
  58. package/src/lib/types.ts +178 -0
  59. package/src/lib/version.ts +1 -1
  60. package/src/lib/webauthn.ts +1 -1
@@ -2,14 +2,14 @@ import GoTrueAdminApi from './GoTrueAdminApi';
2
2
  import { AUTO_REFRESH_TICK_DURATION_MS, AUTO_REFRESH_TICK_THRESHOLD, DEFAULT_HEADERS, EXPIRY_MARGIN_MS, GOTRUE_URL, JWKS_TTL, STORAGE_KEY, } from './lib/constants';
3
3
  import { AuthImplicitGrantRedirectError, AuthInvalidCredentialsError, AuthInvalidJwtError, AuthInvalidTokenResponseError, AuthPKCECodeVerifierMissingError, AuthPKCEGrantCodeExchangeError, AuthSessionMissingError, AuthUnknownError, isAuthApiError, isAuthError, isAuthImplicitGrantRedirectError, isAuthRetryableFetchError, isAuthSessionMissingError, } from './lib/errors';
4
4
  import { _request, _sessionResponse, _sessionResponsePassword, _ssoResponse, _userResponse, } from './lib/fetch';
5
- import { decodeJWT, deepClone, Deferred, generateCallbackId, getAlgorithm, getCodeChallengeAndMethod, getItemAsync, insecureUserWarningProxy, isBrowser, parseParametersFromURL, removeItemAsync, resolveFetch, retryable, setItemAsync, sleep, supportsLocalStorage, userNotAvailableProxy, validateExp, } from './lib/helpers';
5
+ import { assertPasskeyExperimentalEnabled, decodeJWT, deepClone, Deferred, generateCallbackId, getAlgorithm, getCodeChallengeAndMethod, getItemAsync, insecureUserWarningProxy, isBrowser, parseParametersFromURL, removeItemAsync, resolveFetch, retryable, setItemAsync, sleep, supportsLocalStorage, userNotAvailableProxy, validateExp, } from './lib/helpers';
6
6
  import { memoryLocalStorageAdapter } from './lib/local-storage';
7
7
  import { LockAcquireTimeoutError, navigatorLock } from './lib/locks';
8
8
  import { polyfillGlobalThis } from './lib/polyfills';
9
9
  import { version } from './lib/version';
10
10
  import { bytesToBase64URL, stringToUint8Array } from './lib/base64url';
11
11
  import { createSiweMessage, fromHex, getAddress, toHex, } from './lib/web3/ethereum';
12
- import { deserializeCredentialCreationOptions, deserializeCredentialRequestOptions, serializeCredentialCreationResponse, serializeCredentialRequestResponse, WebAuthnApi, } from './lib/webauthn';
12
+ import { createCredential, deserializeCredentialCreationOptions, deserializeCredentialRequestOptions, getCredential, serializeCredentialCreationResponse, serializeCredentialRequestResponse, browserSupportsWebAuthn, webAuthnAbortService, WebAuthnApi, } from './lib/webauthn';
13
13
  polyfillGlobalThis(); // Make "globalThis" available
14
14
  const DEFAULT_OPTIONS = {
15
15
  url: GOTRUE_URL,
@@ -24,6 +24,7 @@ const DEFAULT_OPTIONS = {
24
24
  throwOnError: false,
25
25
  lockAcquireTimeout: 5000, // 5 seconds
26
26
  skipAutoInitialize: false,
27
+ experimental: {},
27
28
  };
28
29
  async function lockNoOp(name, acquireTimeout, fn) {
29
30
  return await fn();
@@ -62,7 +63,7 @@ class GoTrueClient {
62
63
  * ```ts
63
64
  * import { createClient } from '@supabase/supabase-js'
64
65
  *
65
- * const supabase = createClient('https://xyzcompany.supabase.co', 'publishable-or-anon-key')
66
+ * const supabase = createClient('https://xyzcompany.supabase.co', 'your-publishable-key')
66
67
  * const { data, error } = await supabase.auth.getUser()
67
68
  * ```
68
69
  *
@@ -72,13 +73,13 @@ class GoTrueClient {
72
73
  *
73
74
  * const auth = new GoTrueClient({
74
75
  * url: 'https://xyzcompany.supabase.co/auth/v1',
75
- * headers: { apikey: 'publishable-or-anon-key' },
76
+ * headers: { apikey: 'your-publishable-key' },
76
77
  * storageKey: 'supabase-auth',
77
78
  * })
78
79
  * ```
79
80
  */
80
81
  constructor(options) {
81
- var _a, _b, _c;
82
+ var _a, _b, _c, _d;
82
83
  /**
83
84
  * @experimental
84
85
  */
@@ -123,10 +124,12 @@ class GoTrueClient {
123
124
  }
124
125
  this.persistSession = settings.persistSession;
125
126
  this.autoRefreshToken = settings.autoRefreshToken;
127
+ this.experimental = (_b = settings.experimental) !== null && _b !== void 0 ? _b : {};
126
128
  this.admin = new GoTrueAdminApi({
127
129
  url: settings.url,
128
130
  headers: settings.headers,
129
131
  fetch: settings.fetch,
132
+ experimental: this.experimental,
130
133
  });
131
134
  this.url = settings.url;
132
135
  this.headers = settings.headers;
@@ -140,7 +143,7 @@ class GoTrueClient {
140
143
  if (settings.lock) {
141
144
  this.lock = settings.lock;
142
145
  }
143
- else if (this.persistSession && isBrowser() && ((_b = globalThis === null || globalThis === void 0 ? void 0 : globalThis.navigator) === null || _b === void 0 ? void 0 : _b.locks)) {
146
+ else if (this.persistSession && isBrowser() && ((_c = globalThis === null || globalThis === void 0 ? void 0 : globalThis.navigator) === null || _c === void 0 ? void 0 : _c.locks)) {
144
147
  this.lock = navigatorLock;
145
148
  }
146
149
  else {
@@ -167,6 +170,15 @@ class GoTrueClient {
167
170
  listGrants: this._listOAuthGrants.bind(this),
168
171
  revokeGrant: this._revokeOAuthGrant.bind(this),
169
172
  };
173
+ this.passkey = {
174
+ startRegistration: this._startPasskeyRegistration.bind(this),
175
+ verifyRegistration: this._verifyPasskeyRegistration.bind(this),
176
+ startAuthentication: this._startPasskeyAuthentication.bind(this),
177
+ verifyAuthentication: this._verifyPasskeyAuthentication.bind(this),
178
+ list: this._listPasskeys.bind(this),
179
+ update: this._updatePasskey.bind(this),
180
+ delete: this._deletePasskey.bind(this),
181
+ };
170
182
  if (this.persistSession) {
171
183
  if (settings.storage) {
172
184
  this.storage = settings.storage;
@@ -195,7 +207,7 @@ class GoTrueClient {
195
207
  catch (e) {
196
208
  console.error('Failed to create a new BroadcastChannel, multi-tab state changes will not be available', e);
197
209
  }
198
- (_c = this.broadcastChannel) === null || _c === void 0 ? void 0 : _c.addEventListener('message', async (event) => {
210
+ (_d = this.broadcastChannel) === null || _d === void 0 ? void 0 : _d.addEventListener('message', async (event) => {
199
211
  this._debug('received broadcast notification from other tab or client', event);
200
212
  try {
201
213
  await this._notifyAllSubscribers(event.data.event, event.data.session, false); // broadcast = false so we don't get an endless loop of messages
@@ -1478,7 +1490,7 @@ class GoTrueClient {
1478
1490
  }
1479
1491
  if (data.session) {
1480
1492
  await this._saveSession(data.session);
1481
- await this._notifyAllSubscribers('SIGNED_IN', data.session);
1493
+ await this._notifyAllSubscribers(redirectType === 'recovery' ? 'PASSWORD_RECOVERY' : 'SIGNED_IN', data.session);
1482
1494
  }
1483
1495
  return this._returnResult({ data: Object.assign(Object.assign({}, data), { redirectType: redirectType !== null && redirectType !== void 0 ? redirectType : null }), error });
1484
1496
  }
@@ -3007,6 +3019,7 @@ class GoTrueClient {
3007
3019
  * Gets the session data from a URL string
3008
3020
  */
3009
3021
  async _getSessionFromURL(params, callbackUrlType) {
3022
+ var _a;
3010
3023
  try {
3011
3024
  if (!isBrowser())
3012
3025
  throw new AuthImplicitGrantRedirectError('No browser detected.');
@@ -3045,7 +3058,10 @@ class GoTrueClient {
3045
3058
  const url = new URL(window.location.href);
3046
3059
  url.searchParams.delete('code');
3047
3060
  window.history.replaceState(window.history.state, '', url.toString());
3048
- return { data: { session: data.session, redirectType: null }, error: null };
3061
+ return {
3062
+ data: { session: data.session, redirectType: (_a = data.redirectType) !== null && _a !== void 0 ? _a : null },
3063
+ error: null,
3064
+ };
3049
3065
  }
3050
3066
  const { provider_token, provider_refresh_token, access_token, refresh_token, expires_in, expires_at, token_type, } = params;
3051
3067
  if (!access_token || !expires_in || !refresh_token || !token_type) {
@@ -4852,6 +4868,331 @@ class GoTrueClient {
4852
4868
  throw error;
4853
4869
  }
4854
4870
  }
4871
+ // --- Passkey Methods ---
4872
+ /**
4873
+ * Sign in with a passkey. Handles the full WebAuthn ceremony:
4874
+ * 1. Fetches authentication challenge from server
4875
+ * 2. Prompts user via navigator.credentials.get()
4876
+ * 3. Verifies credential with server and creates session
4877
+ *
4878
+ * Requires `auth.experimental.passkey: true`.
4879
+ */
4880
+ async signInWithPasskey(credentials) {
4881
+ var _a, _b, _c;
4882
+ assertPasskeyExperimentalEnabled(this.experimental);
4883
+ try {
4884
+ if (!browserSupportsWebAuthn()) {
4885
+ return this._returnResult({
4886
+ data: null,
4887
+ error: new AuthUnknownError('Browser does not support WebAuthn', null),
4888
+ });
4889
+ }
4890
+ // 1. Get challenge options from server
4891
+ const { data: options, error: optionsError } = await this._startPasskeyAuthentication({
4892
+ options: { captchaToken: (_a = credentials === null || credentials === void 0 ? void 0 : credentials.options) === null || _a === void 0 ? void 0 : _a.captchaToken },
4893
+ });
4894
+ if (optionsError || !options) {
4895
+ return this._returnResult({ data: null, error: optionsError });
4896
+ }
4897
+ // 2. Deserialize and prompt user via browser WebAuthn API
4898
+ const publicKeyOptions = deserializeCredentialRequestOptions(options.options);
4899
+ const signal = (_c = (_b = credentials === null || credentials === void 0 ? void 0 : credentials.options) === null || _b === void 0 ? void 0 : _b.signal) !== null && _c !== void 0 ? _c : webAuthnAbortService.createNewAbortSignal();
4900
+ const { data: credential, error: credentialError } = await getCredential({
4901
+ publicKey: publicKeyOptions,
4902
+ signal,
4903
+ });
4904
+ if (credentialError || !credential) {
4905
+ return this._returnResult({
4906
+ data: null,
4907
+ error: credentialError !== null && credentialError !== void 0 ? credentialError : new AuthUnknownError('WebAuthn ceremony failed', null),
4908
+ });
4909
+ }
4910
+ // 3. Serialize and verify with server
4911
+ const serialized = serializeCredentialRequestResponse(credential);
4912
+ return this._verifyPasskeyAuthentication({
4913
+ challengeId: options.challenge_id,
4914
+ credential: serialized,
4915
+ });
4916
+ }
4917
+ catch (error) {
4918
+ if (isAuthError(error)) {
4919
+ return this._returnResult({ data: null, error });
4920
+ }
4921
+ throw error;
4922
+ }
4923
+ }
4924
+ /**
4925
+ * Register a passkey for the current authenticated user. Handles the full WebAuthn ceremony:
4926
+ * 1. Fetches registration challenge from server
4927
+ * 2. Prompts user via navigator.credentials.create()
4928
+ * 3. Verifies credential with server
4929
+ *
4930
+ * Requires an active session. Requires `auth.experimental.passkey: true`.
4931
+ */
4932
+ async registerPasskey(credentials) {
4933
+ var _a, _b;
4934
+ assertPasskeyExperimentalEnabled(this.experimental);
4935
+ try {
4936
+ if (!browserSupportsWebAuthn()) {
4937
+ return this._returnResult({
4938
+ data: null,
4939
+ error: new AuthUnknownError('Browser does not support WebAuthn', null),
4940
+ });
4941
+ }
4942
+ // 1. Get challenge options from server
4943
+ const { data: options, error: optionsError } = await this._startPasskeyRegistration();
4944
+ if (optionsError || !options) {
4945
+ return this._returnResult({ data: null, error: optionsError });
4946
+ }
4947
+ // 2. Deserialize and prompt user via browser WebAuthn API
4948
+ const publicKeyOptions = deserializeCredentialCreationOptions(options.options);
4949
+ const signal = (_b = (_a = credentials === null || credentials === void 0 ? void 0 : credentials.options) === null || _a === void 0 ? void 0 : _a.signal) !== null && _b !== void 0 ? _b : webAuthnAbortService.createNewAbortSignal();
4950
+ const { data: credential, error: credentialError } = await createCredential({
4951
+ publicKey: publicKeyOptions,
4952
+ signal,
4953
+ });
4954
+ if (credentialError || !credential) {
4955
+ return this._returnResult({
4956
+ data: null,
4957
+ error: credentialError !== null && credentialError !== void 0 ? credentialError : new AuthUnknownError('WebAuthn ceremony failed', null),
4958
+ });
4959
+ }
4960
+ // 3. Serialize and verify with server
4961
+ const serialized = serializeCredentialCreationResponse(credential);
4962
+ return this._verifyPasskeyRegistration({
4963
+ challengeId: options.challenge_id,
4964
+ credential: serialized,
4965
+ });
4966
+ }
4967
+ catch (error) {
4968
+ if (isAuthError(error)) {
4969
+ return this._returnResult({ data: null, error });
4970
+ }
4971
+ throw error;
4972
+ }
4973
+ }
4974
+ /**
4975
+ * Start passkey registration for the current authenticated user.
4976
+ * Returns WebAuthn credential creation options to pass to navigator.credentials.create().
4977
+ */
4978
+ async _startPasskeyRegistration() {
4979
+ assertPasskeyExperimentalEnabled(this.experimental);
4980
+ try {
4981
+ return await this._useSession(async (result) => {
4982
+ const { data: { session }, error: sessionError, } = result;
4983
+ if (sessionError) {
4984
+ return this._returnResult({ data: null, error: sessionError });
4985
+ }
4986
+ if (!session) {
4987
+ return this._returnResult({ data: null, error: new AuthSessionMissingError() });
4988
+ }
4989
+ const { data, error } = await _request(this.fetch, 'POST', `${this.url}/passkeys/registration/options`, {
4990
+ headers: this.headers,
4991
+ jwt: session.access_token,
4992
+ body: {},
4993
+ });
4994
+ if (error) {
4995
+ return this._returnResult({ data: null, error });
4996
+ }
4997
+ return this._returnResult({ data, error: null });
4998
+ });
4999
+ }
5000
+ catch (error) {
5001
+ if (isAuthError(error)) {
5002
+ return this._returnResult({ data: null, error });
5003
+ }
5004
+ throw error;
5005
+ }
5006
+ }
5007
+ /**
5008
+ * Verify passkey registration with the credential response.
5009
+ * The credentialResponse should be the serialized output of navigator.credentials.create().
5010
+ */
5011
+ async _verifyPasskeyRegistration(params) {
5012
+ assertPasskeyExperimentalEnabled(this.experimental);
5013
+ try {
5014
+ return await this._useSession(async (result) => {
5015
+ const { data: { session }, error: sessionError, } = result;
5016
+ if (sessionError) {
5017
+ return this._returnResult({ data: null, error: sessionError });
5018
+ }
5019
+ if (!session) {
5020
+ return this._returnResult({ data: null, error: new AuthSessionMissingError() });
5021
+ }
5022
+ const { data, error } = await _request(this.fetch, 'POST', `${this.url}/passkeys/registration/verify`, {
5023
+ headers: this.headers,
5024
+ jwt: session.access_token,
5025
+ body: {
5026
+ challenge_id: params.challengeId,
5027
+ credential: params.credential,
5028
+ },
5029
+ });
5030
+ if (error) {
5031
+ return this._returnResult({ data: null, error });
5032
+ }
5033
+ return this._returnResult({ data, error: null });
5034
+ });
5035
+ }
5036
+ catch (error) {
5037
+ if (isAuthError(error)) {
5038
+ return this._returnResult({ data: null, error });
5039
+ }
5040
+ throw error;
5041
+ }
5042
+ }
5043
+ /**
5044
+ * Start passkey authentication.
5045
+ * Returns WebAuthn credential request options to pass to navigator.credentials.get().
5046
+ */
5047
+ async _startPasskeyAuthentication(params) {
5048
+ var _a;
5049
+ assertPasskeyExperimentalEnabled(this.experimental);
5050
+ try {
5051
+ const { data, error } = await _request(this.fetch, 'POST', `${this.url}/passkeys/authentication/options`, {
5052
+ headers: this.headers,
5053
+ body: {
5054
+ gotrue_meta_security: { captcha_token: (_a = params === null || params === void 0 ? void 0 : params.options) === null || _a === void 0 ? void 0 : _a.captchaToken },
5055
+ },
5056
+ });
5057
+ if (error) {
5058
+ return this._returnResult({ data: null, error });
5059
+ }
5060
+ return this._returnResult({ data, error: null });
5061
+ }
5062
+ catch (error) {
5063
+ if (isAuthError(error)) {
5064
+ return this._returnResult({ data: null, error });
5065
+ }
5066
+ throw error;
5067
+ }
5068
+ }
5069
+ /**
5070
+ * Verify passkey authentication and create a session.
5071
+ * The credential should be the serialized output of navigator.credentials.get().
5072
+ */
5073
+ async _verifyPasskeyAuthentication(params) {
5074
+ assertPasskeyExperimentalEnabled(this.experimental);
5075
+ try {
5076
+ const { data, error } = await _request(this.fetch, 'POST', `${this.url}/passkeys/authentication/verify`, {
5077
+ headers: this.headers,
5078
+ body: {
5079
+ challenge_id: params.challengeId,
5080
+ credential: params.credential,
5081
+ },
5082
+ xform: _sessionResponse,
5083
+ });
5084
+ if (error) {
5085
+ return this._returnResult({ data: null, error });
5086
+ }
5087
+ if (data.session) {
5088
+ await this._saveSession(data.session);
5089
+ await this._notifyAllSubscribers('SIGNED_IN', data.session);
5090
+ }
5091
+ return this._returnResult({ data, error: null });
5092
+ }
5093
+ catch (error) {
5094
+ if (isAuthError(error)) {
5095
+ return this._returnResult({ data: null, error });
5096
+ }
5097
+ throw error;
5098
+ }
5099
+ }
5100
+ /**
5101
+ * List all passkeys for the current user.
5102
+ */
5103
+ async _listPasskeys() {
5104
+ assertPasskeyExperimentalEnabled(this.experimental);
5105
+ try {
5106
+ return await this._useSession(async (result) => {
5107
+ const { data: { session }, error: sessionError, } = result;
5108
+ if (sessionError) {
5109
+ return this._returnResult({ data: null, error: sessionError });
5110
+ }
5111
+ if (!session) {
5112
+ return this._returnResult({ data: null, error: new AuthSessionMissingError() });
5113
+ }
5114
+ const { data, error } = await _request(this.fetch, 'GET', `${this.url}/passkeys`, {
5115
+ headers: this.headers,
5116
+ jwt: session.access_token,
5117
+ xform: (data) => ({ data, error: null }),
5118
+ });
5119
+ if (error) {
5120
+ return this._returnResult({ data: null, error });
5121
+ }
5122
+ return this._returnResult({ data, error: null });
5123
+ });
5124
+ }
5125
+ catch (error) {
5126
+ if (isAuthError(error)) {
5127
+ return this._returnResult({ data: null, error });
5128
+ }
5129
+ throw error;
5130
+ }
5131
+ }
5132
+ /**
5133
+ * Update a passkey.
5134
+ */
5135
+ async _updatePasskey(params) {
5136
+ assertPasskeyExperimentalEnabled(this.experimental);
5137
+ try {
5138
+ return await this._useSession(async (result) => {
5139
+ const { data: { session }, error: sessionError, } = result;
5140
+ if (sessionError) {
5141
+ return this._returnResult({ data: null, error: sessionError });
5142
+ }
5143
+ if (!session) {
5144
+ return this._returnResult({ data: null, error: new AuthSessionMissingError() });
5145
+ }
5146
+ const { data, error } = await _request(this.fetch, 'PATCH', `${this.url}/passkeys/${params.passkeyId}`, {
5147
+ headers: this.headers,
5148
+ jwt: session.access_token,
5149
+ body: { friendly_name: params.friendlyName },
5150
+ });
5151
+ if (error) {
5152
+ return this._returnResult({ data: null, error });
5153
+ }
5154
+ return this._returnResult({ data, error: null });
5155
+ });
5156
+ }
5157
+ catch (error) {
5158
+ if (isAuthError(error)) {
5159
+ return this._returnResult({ data: null, error });
5160
+ }
5161
+ throw error;
5162
+ }
5163
+ }
5164
+ /**
5165
+ * Delete a passkey.
5166
+ */
5167
+ async _deletePasskey(params) {
5168
+ assertPasskeyExperimentalEnabled(this.experimental);
5169
+ try {
5170
+ return await this._useSession(async (result) => {
5171
+ const { data: { session }, error: sessionError, } = result;
5172
+ if (sessionError) {
5173
+ return this._returnResult({ data: null, error: sessionError });
5174
+ }
5175
+ if (!session) {
5176
+ return this._returnResult({ data: null, error: new AuthSessionMissingError() });
5177
+ }
5178
+ const { error } = await _request(this.fetch, 'DELETE', `${this.url}/passkeys/${params.passkeyId}`, {
5179
+ headers: this.headers,
5180
+ jwt: session.access_token,
5181
+ noResolveJson: true,
5182
+ });
5183
+ if (error) {
5184
+ return this._returnResult({ data: null, error });
5185
+ }
5186
+ return this._returnResult({ data: null, error: null });
5187
+ });
5188
+ }
5189
+ catch (error) {
5190
+ if (isAuthError(error)) {
5191
+ return this._returnResult({ data: null, error });
5192
+ }
5193
+ throw error;
5194
+ }
5195
+ }
4855
5196
  }
4856
5197
  GoTrueClient.nextInstanceID = {};
4857
5198
  export default GoTrueClient;