@supabase/auth-js 2.100.0-rc.0 → 2.100.1
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/main/GoTrueAdminApi.d.ts +449 -0
- package/dist/main/GoTrueAdminApi.d.ts.map +1 -1
- package/dist/main/GoTrueAdminApi.js +449 -0
- package/dist/main/GoTrueAdminApi.js.map +1 -1
- package/dist/main/GoTrueClient.d.ts +1668 -63
- package/dist/main/GoTrueClient.d.ts.map +1 -1
- package/dist/main/GoTrueClient.js +1889 -70
- package/dist/main/GoTrueClient.js.map +1 -1
- package/dist/main/lib/locks.d.ts.map +1 -1
- package/dist/main/lib/locks.js +69 -39
- package/dist/main/lib/locks.js.map +1 -1
- package/dist/main/lib/types.d.ts +409 -0
- package/dist/main/lib/types.d.ts.map +1 -1
- package/dist/main/lib/types.js.map +1 -1
- package/dist/main/lib/version.d.ts +1 -1
- package/dist/main/lib/version.d.ts.map +1 -1
- package/dist/main/lib/version.js +1 -1
- package/dist/main/lib/version.js.map +1 -1
- package/dist/module/GoTrueAdminApi.d.ts +449 -0
- package/dist/module/GoTrueAdminApi.d.ts.map +1 -1
- package/dist/module/GoTrueAdminApi.js +449 -0
- package/dist/module/GoTrueAdminApi.js.map +1 -1
- package/dist/module/GoTrueClient.d.ts +1668 -63
- package/dist/module/GoTrueClient.d.ts.map +1 -1
- package/dist/module/GoTrueClient.js +1889 -70
- package/dist/module/GoTrueClient.js.map +1 -1
- package/dist/module/lib/locks.d.ts.map +1 -1
- package/dist/module/lib/locks.js +69 -39
- package/dist/module/lib/locks.js.map +1 -1
- package/dist/module/lib/types.d.ts +409 -0
- package/dist/module/lib/types.d.ts.map +1 -1
- package/dist/module/lib/types.js.map +1 -1
- package/dist/module/lib/version.d.ts +1 -1
- package/dist/module/lib/version.d.ts.map +1 -1
- package/dist/module/lib/version.js +1 -1
- package/dist/module/lib/version.js.map +1 -1
- package/dist/tsconfig.module.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/GoTrueAdminApi.ts +449 -0
- package/src/GoTrueClient.ts +1889 -70
- package/src/lib/locks.ts +92 -54
- package/src/lib/types.ts +409 -0
- package/src/lib/version.ts +1 -1
|
@@ -111,6 +111,8 @@ export default class GoTrueClient {
|
|
|
111
111
|
* Initializes the client session either from the url or from storage.
|
|
112
112
|
* This method is automatically called when instantiating the client, but should also be called
|
|
113
113
|
* manually when checking for an error from an auth redirect (oauth, magiclink, password recovery, etc).
|
|
114
|
+
*
|
|
115
|
+
* @category Auth
|
|
114
116
|
*/
|
|
115
117
|
initialize(): Promise<InitializeResult>;
|
|
116
118
|
/**
|
|
@@ -124,6 +126,74 @@ export default class GoTrueClient {
|
|
|
124
126
|
* Creates a new anonymous user.
|
|
125
127
|
*
|
|
126
128
|
* @returns A session where the is_anonymous claim in the access token JWT set to true
|
|
129
|
+
*
|
|
130
|
+
* @category Auth
|
|
131
|
+
*
|
|
132
|
+
* @remarks
|
|
133
|
+
* - Returns an anonymous user
|
|
134
|
+
* - It is recommended to set up captcha for anonymous sign-ins to prevent abuse. You can pass in the captcha token in the `options` param.
|
|
135
|
+
*
|
|
136
|
+
* @example Create an anonymous user
|
|
137
|
+
* ```js
|
|
138
|
+
* const { data, error } = await supabase.auth.signInAnonymously({
|
|
139
|
+
* options: {
|
|
140
|
+
* captchaToken
|
|
141
|
+
* }
|
|
142
|
+
* });
|
|
143
|
+
* ```
|
|
144
|
+
*
|
|
145
|
+
* @exampleResponse Create an anonymous user
|
|
146
|
+
* ```json
|
|
147
|
+
* {
|
|
148
|
+
* "data": {
|
|
149
|
+
* "user": {
|
|
150
|
+
* "id": "11111111-1111-1111-1111-111111111111",
|
|
151
|
+
* "aud": "authenticated",
|
|
152
|
+
* "role": "authenticated",
|
|
153
|
+
* "email": "",
|
|
154
|
+
* "phone": "",
|
|
155
|
+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
|
|
156
|
+
* "app_metadata": {},
|
|
157
|
+
* "user_metadata": {},
|
|
158
|
+
* "identities": [],
|
|
159
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
160
|
+
* "updated_at": "2024-01-01T00:00:00Z",
|
|
161
|
+
* "is_anonymous": true
|
|
162
|
+
* },
|
|
163
|
+
* "session": {
|
|
164
|
+
* "access_token": "<ACCESS_TOKEN>",
|
|
165
|
+
* "token_type": "bearer",
|
|
166
|
+
* "expires_in": 3600,
|
|
167
|
+
* "expires_at": 1700000000,
|
|
168
|
+
* "refresh_token": "<REFRESH_TOKEN>",
|
|
169
|
+
* "user": {
|
|
170
|
+
* "id": "11111111-1111-1111-1111-111111111111",
|
|
171
|
+
* "aud": "authenticated",
|
|
172
|
+
* "role": "authenticated",
|
|
173
|
+
* "email": "",
|
|
174
|
+
* "phone": "",
|
|
175
|
+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
|
|
176
|
+
* "app_metadata": {},
|
|
177
|
+
* "user_metadata": {},
|
|
178
|
+
* "identities": [],
|
|
179
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
180
|
+
* "updated_at": "2024-01-01T00:00:00Z",
|
|
181
|
+
* "is_anonymous": true
|
|
182
|
+
* }
|
|
183
|
+
* }
|
|
184
|
+
* },
|
|
185
|
+
* "error": null
|
|
186
|
+
* }
|
|
187
|
+
* ```
|
|
188
|
+
*
|
|
189
|
+
* @example Create an anonymous user with custom user metadata
|
|
190
|
+
* ```js
|
|
191
|
+
* const { data, error } = await supabase.auth.signInAnonymously({
|
|
192
|
+
* options: {
|
|
193
|
+
* data
|
|
194
|
+
* }
|
|
195
|
+
* })
|
|
196
|
+
* ```
|
|
127
197
|
*/
|
|
128
198
|
signInAnonymously(credentials?: SignInAnonymouslyCredentials): Promise<AuthResponse>;
|
|
129
199
|
/**
|
|
@@ -311,90 +381,899 @@ export default class GoTrueClient {
|
|
|
311
381
|
* between the cases where the account does not exist or that the
|
|
312
382
|
* email/phone and password combination is wrong or that the account can only
|
|
313
383
|
* be accessed via social login.
|
|
384
|
+
*
|
|
385
|
+
* @category Auth
|
|
386
|
+
*
|
|
387
|
+
* @remarks
|
|
388
|
+
* - Requires either an email and password or a phone number and password.
|
|
389
|
+
*
|
|
390
|
+
* @example Sign in with email and password
|
|
391
|
+
* ```js
|
|
392
|
+
* const { data, error } = await supabase.auth.signInWithPassword({
|
|
393
|
+
* email: 'example@email.com',
|
|
394
|
+
* password: 'example-password',
|
|
395
|
+
* })
|
|
396
|
+
* ```
|
|
397
|
+
*
|
|
398
|
+
* @exampleResponse Sign in with email and password
|
|
399
|
+
* ```json
|
|
400
|
+
* {
|
|
401
|
+
* "data": {
|
|
402
|
+
* "user": {
|
|
403
|
+
* "id": "11111111-1111-1111-1111-111111111111",
|
|
404
|
+
* "aud": "authenticated",
|
|
405
|
+
* "role": "authenticated",
|
|
406
|
+
* "email": "example@email.com",
|
|
407
|
+
* "email_confirmed_at": "2024-01-01T00:00:00Z",
|
|
408
|
+
* "phone": "",
|
|
409
|
+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
|
|
410
|
+
* "app_metadata": {
|
|
411
|
+
* "provider": "email",
|
|
412
|
+
* "providers": [
|
|
413
|
+
* "email"
|
|
414
|
+
* ]
|
|
415
|
+
* },
|
|
416
|
+
* "user_metadata": {},
|
|
417
|
+
* "identities": [
|
|
418
|
+
* {
|
|
419
|
+
* "identity_id": "22222222-2222-2222-2222-222222222222",
|
|
420
|
+
* "id": "11111111-1111-1111-1111-111111111111",
|
|
421
|
+
* "user_id": "11111111-1111-1111-1111-111111111111",
|
|
422
|
+
* "identity_data": {
|
|
423
|
+
* "email": "example@email.com",
|
|
424
|
+
* "email_verified": false,
|
|
425
|
+
* "phone_verified": false,
|
|
426
|
+
* "sub": "11111111-1111-1111-1111-111111111111"
|
|
427
|
+
* },
|
|
428
|
+
* "provider": "email",
|
|
429
|
+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
|
|
430
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
431
|
+
* "updated_at": "2024-01-01T00:00:00Z",
|
|
432
|
+
* "email": "example@email.com"
|
|
433
|
+
* }
|
|
434
|
+
* ],
|
|
435
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
436
|
+
* "updated_at": "2024-01-01T00:00:00Z"
|
|
437
|
+
* },
|
|
438
|
+
* "session": {
|
|
439
|
+
* "access_token": "<ACCESS_TOKEN>",
|
|
440
|
+
* "token_type": "bearer",
|
|
441
|
+
* "expires_in": 3600,
|
|
442
|
+
* "expires_at": 1700000000,
|
|
443
|
+
* "refresh_token": "<REFRESH_TOKEN>",
|
|
444
|
+
* "user": {
|
|
445
|
+
* "id": "11111111-1111-1111-1111-111111111111",
|
|
446
|
+
* "aud": "authenticated",
|
|
447
|
+
* "role": "authenticated",
|
|
448
|
+
* "email": "example@email.com",
|
|
449
|
+
* "email_confirmed_at": "2024-01-01T00:00:00Z",
|
|
450
|
+
* "phone": "",
|
|
451
|
+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
|
|
452
|
+
* "app_metadata": {
|
|
453
|
+
* "provider": "email",
|
|
454
|
+
* "providers": [
|
|
455
|
+
* "email"
|
|
456
|
+
* ]
|
|
457
|
+
* },
|
|
458
|
+
* "user_metadata": {},
|
|
459
|
+
* "identities": [
|
|
460
|
+
* {
|
|
461
|
+
* "identity_id": "22222222-2222-2222-2222-222222222222",
|
|
462
|
+
* "id": "11111111-1111-1111-1111-111111111111",
|
|
463
|
+
* "user_id": "11111111-1111-1111-1111-111111111111",
|
|
464
|
+
* "identity_data": {
|
|
465
|
+
* "email": "example@email.com",
|
|
466
|
+
* "email_verified": false,
|
|
467
|
+
* "phone_verified": false,
|
|
468
|
+
* "sub": "11111111-1111-1111-1111-111111111111"
|
|
469
|
+
* },
|
|
470
|
+
* "provider": "email",
|
|
471
|
+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
|
|
472
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
473
|
+
* "updated_at": "2024-01-01T00:00:00Z",
|
|
474
|
+
* "email": "example@email.com"
|
|
475
|
+
* }
|
|
476
|
+
* ],
|
|
477
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
478
|
+
* "updated_at": "2024-01-01T00:00:00Z"
|
|
479
|
+
* }
|
|
480
|
+
* }
|
|
481
|
+
* },
|
|
482
|
+
* "error": null
|
|
483
|
+
* }
|
|
484
|
+
* ```
|
|
485
|
+
*
|
|
486
|
+
* @example Sign in with phone and password
|
|
487
|
+
* ```js
|
|
488
|
+
* const { data, error } = await supabase.auth.signInWithPassword({
|
|
489
|
+
* phone: '+13334445555',
|
|
490
|
+
* password: 'some-password',
|
|
491
|
+
* })
|
|
492
|
+
* ```
|
|
314
493
|
*/
|
|
315
494
|
signInWithPassword(credentials: SignInWithPasswordCredentials): Promise<AuthTokenResponsePassword>;
|
|
316
495
|
/**
|
|
317
496
|
* Log in an existing user via a third-party provider.
|
|
318
497
|
* This method supports the PKCE flow.
|
|
498
|
+
*
|
|
499
|
+
* @category Auth
|
|
500
|
+
*
|
|
501
|
+
* @remarks
|
|
502
|
+
* - This method is used for signing in using [Social Login (OAuth) providers](/docs/guides/auth#configure-third-party-providers).
|
|
503
|
+
* - It works by redirecting your application to the provider's authorization screen, before bringing back the user to your app.
|
|
504
|
+
*
|
|
505
|
+
* @example Sign in using a third-party provider
|
|
506
|
+
* ```js
|
|
507
|
+
* const { data, error } = await supabase.auth.signInWithOAuth({
|
|
508
|
+
* provider: 'github'
|
|
509
|
+
* })
|
|
510
|
+
* ```
|
|
511
|
+
*
|
|
512
|
+
* @exampleResponse Sign in using a third-party provider
|
|
513
|
+
* ```json
|
|
514
|
+
* {
|
|
515
|
+
* data: {
|
|
516
|
+
* provider: 'github',
|
|
517
|
+
* url: <PROVIDER_URL_TO_REDIRECT_TO>
|
|
518
|
+
* },
|
|
519
|
+
* error: null
|
|
520
|
+
* }
|
|
521
|
+
* ```
|
|
522
|
+
*
|
|
523
|
+
* @exampleDescription Sign in using a third-party provider with redirect
|
|
524
|
+
* - When the OAuth provider successfully authenticates the user, they are redirected to the URL specified in the `redirectTo` parameter. This parameter defaults to the [`SITE_URL`](/docs/guides/auth/redirect-urls#use-wildcards-in-redirect-urls). It does not redirect the user immediately after invoking this method.
|
|
525
|
+
* - See [redirect URLs and wildcards](/docs/guides/auth/redirect-urls#use-wildcards-in-redirect-urls) to add additional redirect URLs to your project.
|
|
526
|
+
*
|
|
527
|
+
* @example Sign in using a third-party provider with redirect
|
|
528
|
+
* ```js
|
|
529
|
+
* const { data, error } = await supabase.auth.signInWithOAuth({
|
|
530
|
+
* provider: 'github',
|
|
531
|
+
* options: {
|
|
532
|
+
* redirectTo: 'https://example.com/welcome'
|
|
533
|
+
* }
|
|
534
|
+
* })
|
|
535
|
+
* ```
|
|
536
|
+
*
|
|
537
|
+
* @exampleDescription Sign in with scopes and access provider tokens
|
|
538
|
+
* If you need additional access from an OAuth provider, in order to access provider specific APIs in the name of the user, you can do this by passing in the scopes the user should authorize for your application. Note that the `scopes` option takes in **a space-separated list** of scopes.
|
|
539
|
+
*
|
|
540
|
+
* Because OAuth sign-in often includes redirects, you should register an `onAuthStateChange` callback immediately after you create the Supabase client. This callback will listen for the presence of `provider_token` and `provider_refresh_token` properties on the `session` object and store them in local storage. The client library will emit these values **only once** immediately after the user signs in. You can then access them by looking them up in local storage, or send them to your backend servers for further processing.
|
|
541
|
+
*
|
|
542
|
+
* Finally, make sure you remove them from local storage on the `SIGNED_OUT` event. If the OAuth provider supports token revocation, make sure you call those APIs either from the frontend or schedule them to be called on the backend.
|
|
543
|
+
*
|
|
544
|
+
* @example Sign in with scopes and access provider tokens
|
|
545
|
+
* ```js
|
|
546
|
+
* // Register this immediately after calling createClient!
|
|
547
|
+
* // Because signInWithOAuth causes a redirect, you need to fetch the
|
|
548
|
+
* // provider tokens from the callback.
|
|
549
|
+
* supabase.auth.onAuthStateChange((event, session) => {
|
|
550
|
+
* if (session && session.provider_token) {
|
|
551
|
+
* window.localStorage.setItem('oauth_provider_token', session.provider_token)
|
|
552
|
+
* }
|
|
553
|
+
*
|
|
554
|
+
* if (session && session.provider_refresh_token) {
|
|
555
|
+
* window.localStorage.setItem('oauth_provider_refresh_token', session.provider_refresh_token)
|
|
556
|
+
* }
|
|
557
|
+
*
|
|
558
|
+
* if (event === 'SIGNED_OUT') {
|
|
559
|
+
* window.localStorage.removeItem('oauth_provider_token')
|
|
560
|
+
* window.localStorage.removeItem('oauth_provider_refresh_token')
|
|
561
|
+
* }
|
|
562
|
+
* })
|
|
563
|
+
*
|
|
564
|
+
* // Call this on your Sign in with GitHub button to initiate OAuth
|
|
565
|
+
* // with GitHub with the requested elevated scopes.
|
|
566
|
+
* await supabase.auth.signInWithOAuth({
|
|
567
|
+
* provider: 'github',
|
|
568
|
+
* options: {
|
|
569
|
+
* scopes: 'repo gist notifications'
|
|
570
|
+
* }
|
|
571
|
+
* })
|
|
572
|
+
* ```
|
|
319
573
|
*/
|
|
320
574
|
signInWithOAuth(credentials: SignInWithOAuthCredentials): Promise<OAuthResponse>;
|
|
321
575
|
/**
|
|
322
576
|
* Log in an existing user by exchanging an Auth Code issued during the PKCE flow.
|
|
323
|
-
*/
|
|
324
|
-
exchangeCodeForSession(authCode: string): Promise<AuthTokenResponse>;
|
|
325
|
-
/**
|
|
326
|
-
* Signs in a user by verifying a message signed by the user's private key.
|
|
327
|
-
* Supports Ethereum (via Sign-In-With-Ethereum) & Solana (Sign-In-With-Solana) standards,
|
|
328
|
-
* both of which derive from the EIP-4361 standard
|
|
329
|
-
* With slight variation on Solana's side.
|
|
330
|
-
* @reference https://eips.ethereum.org/EIPS/eip-4361
|
|
331
|
-
*/
|
|
332
|
-
signInWithWeb3(credentials: Web3Credentials): Promise<{
|
|
333
|
-
data: {
|
|
334
|
-
session: Session;
|
|
335
|
-
user: User;
|
|
336
|
-
};
|
|
337
|
-
error: null;
|
|
338
|
-
} | {
|
|
339
|
-
data: {
|
|
340
|
-
session: null;
|
|
341
|
-
user: null;
|
|
342
|
-
};
|
|
343
|
-
error: AuthError;
|
|
344
|
-
}>;
|
|
345
|
-
private signInWithEthereum;
|
|
346
|
-
private signInWithSolana;
|
|
347
|
-
private _exchangeCodeForSession;
|
|
348
|
-
/**
|
|
349
|
-
* Allows signing in with an OIDC ID token. The authentication provider used
|
|
350
|
-
* should be enabled and configured.
|
|
351
|
-
*/
|
|
352
|
-
signInWithIdToken(credentials: SignInWithIdTokenCredentials): Promise<AuthTokenResponse>;
|
|
353
|
-
/**
|
|
354
|
-
* Log in a user using magiclink or a one-time password (OTP).
|
|
355
|
-
*
|
|
356
|
-
* If the `{{ .ConfirmationURL }}` variable is specified in the email template, a magiclink will be sent.
|
|
357
|
-
* If the `{{ .Token }}` variable is specified in the email template, an OTP will be sent.
|
|
358
|
-
* If you're using phone sign-ins, only an OTP will be sent. You won't be able to send a magiclink for phone sign-ins.
|
|
359
577
|
*
|
|
360
|
-
*
|
|
361
|
-
* between the cases where the account does not exist or, that the account
|
|
362
|
-
* can only be accessed via social login.
|
|
578
|
+
* @category Auth
|
|
363
579
|
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
* channel is not supported on other providers
|
|
367
|
-
* at this time.
|
|
368
|
-
* This method supports PKCE when an email is passed.
|
|
369
|
-
*/
|
|
370
|
-
signInWithOtp(credentials: SignInWithPasswordlessCredentials): Promise<AuthOtpResponse>;
|
|
371
|
-
/**
|
|
372
|
-
* Log in a user given a User supplied OTP or TokenHash received through mobile or email.
|
|
373
|
-
*/
|
|
374
|
-
verifyOtp(params: VerifyOtpParams): Promise<AuthResponse>;
|
|
375
|
-
/**
|
|
376
|
-
* Attempts a single-sign on using an enterprise Identity Provider. A
|
|
377
|
-
* successful SSO attempt will redirect the current page to the identity
|
|
378
|
-
* provider authorization page. The redirect URL is implementation and SSO
|
|
379
|
-
* protocol specific.
|
|
580
|
+
* @remarks
|
|
581
|
+
* - Used when `flowType` is set to `pkce` in client options.
|
|
380
582
|
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
583
|
+
* @example Exchange Auth Code
|
|
584
|
+
* ```js
|
|
585
|
+
* supabase.auth.exchangeCodeForSession('34e770dd-9ff9-416c-87fa-43b31d7ef225')
|
|
586
|
+
* ```
|
|
385
587
|
*
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
|
|
389
|
-
|
|
588
|
+
* @exampleResponse Exchange Auth Code
|
|
589
|
+
* ```json
|
|
590
|
+
* {
|
|
591
|
+
* "data": {
|
|
592
|
+
* session: {
|
|
593
|
+
* access_token: '<ACCESS_TOKEN>',
|
|
594
|
+
* token_type: 'bearer',
|
|
595
|
+
* expires_in: 3600,
|
|
596
|
+
* expires_at: 1700000000,
|
|
597
|
+
* refresh_token: '<REFRESH_TOKEN>',
|
|
598
|
+
* user: {
|
|
599
|
+
* id: '11111111-1111-1111-1111-111111111111',
|
|
600
|
+
* aud: 'authenticated',
|
|
601
|
+
* role: 'authenticated',
|
|
602
|
+
* email: 'example@email.com'
|
|
603
|
+
* email_confirmed_at: '2024-01-01T00:00:00Z',
|
|
604
|
+
* phone: '',
|
|
605
|
+
* confirmation_sent_at: '2024-01-01T00:00:00Z',
|
|
606
|
+
* confirmed_at: '2024-01-01T00:00:00Z',
|
|
607
|
+
* last_sign_in_at: '2024-01-01T00:00:00Z',
|
|
608
|
+
* app_metadata: {
|
|
609
|
+
* "provider": "email",
|
|
610
|
+
* "providers": [
|
|
611
|
+
* "email",
|
|
612
|
+
* "<OTHER_PROVIDER>"
|
|
613
|
+
* ]
|
|
614
|
+
* },
|
|
615
|
+
* user_metadata: {
|
|
616
|
+
* email: 'email@email.com',
|
|
617
|
+
* email_verified: true,
|
|
618
|
+
* full_name: 'User Name',
|
|
619
|
+
* iss: '<ISS>',
|
|
620
|
+
* name: 'User Name',
|
|
621
|
+
* phone_verified: false,
|
|
622
|
+
* provider_id: '<PROVIDER_ID>',
|
|
623
|
+
* sub: '<SUB>'
|
|
624
|
+
* },
|
|
625
|
+
* identities: [
|
|
626
|
+
* {
|
|
627
|
+
* "identity_id": "22222222-2222-2222-2222-222222222222",
|
|
628
|
+
* "id": "11111111-1111-1111-1111-111111111111",
|
|
629
|
+
* "user_id": "11111111-1111-1111-1111-111111111111",
|
|
630
|
+
* "identity_data": {
|
|
631
|
+
* "email": "example@email.com",
|
|
632
|
+
* "email_verified": false,
|
|
633
|
+
* "phone_verified": false,
|
|
634
|
+
* "sub": "11111111-1111-1111-1111-111111111111"
|
|
635
|
+
* },
|
|
636
|
+
* "provider": "email",
|
|
637
|
+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
|
|
638
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
639
|
+
* "updated_at": "2024-01-01T00:00:00Z",
|
|
640
|
+
* "email": "email@example.com"
|
|
641
|
+
* },
|
|
642
|
+
* {
|
|
643
|
+
* "identity_id": "33333333-3333-3333-3333-333333333333",
|
|
644
|
+
* "id": "<ID>",
|
|
645
|
+
* "user_id": "<USER_ID>",
|
|
646
|
+
* "identity_data": {
|
|
647
|
+
* "email": "example@email.com",
|
|
648
|
+
* "email_verified": true,
|
|
649
|
+
* "full_name": "User Name",
|
|
650
|
+
* "iss": "<ISS>",
|
|
651
|
+
* "name": "User Name",
|
|
652
|
+
* "phone_verified": false,
|
|
653
|
+
* "provider_id": "<PROVIDER_ID>",
|
|
654
|
+
* "sub": "<SUB>"
|
|
655
|
+
* },
|
|
656
|
+
* "provider": "<PROVIDER>",
|
|
657
|
+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
|
|
658
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
659
|
+
* "updated_at": "2024-01-01T00:00:00Z",
|
|
660
|
+
* "email": "example@email.com"
|
|
661
|
+
* }
|
|
662
|
+
* ],
|
|
663
|
+
* created_at: '2024-01-01T00:00:00Z',
|
|
664
|
+
* updated_at: '2024-01-01T00:00:00Z',
|
|
665
|
+
* is_anonymous: false
|
|
666
|
+
* },
|
|
667
|
+
* provider_token: '<PROVIDER_TOKEN>',
|
|
668
|
+
* provider_refresh_token: '<PROVIDER_REFRESH_TOKEN>'
|
|
669
|
+
* },
|
|
670
|
+
* user: {
|
|
671
|
+
* id: '11111111-1111-1111-1111-111111111111',
|
|
672
|
+
* aud: 'authenticated',
|
|
673
|
+
* role: 'authenticated',
|
|
674
|
+
* email: 'example@email.com',
|
|
675
|
+
* email_confirmed_at: '2024-01-01T00:00:00Z',
|
|
676
|
+
* phone: '',
|
|
677
|
+
* confirmation_sent_at: '2024-01-01T00:00:00Z',
|
|
678
|
+
* confirmed_at: '2024-01-01T00:00:00Z',
|
|
679
|
+
* last_sign_in_at: '2024-01-01T00:00:00Z',
|
|
680
|
+
* app_metadata: {
|
|
681
|
+
* provider: 'email',
|
|
682
|
+
* providers: [
|
|
683
|
+
* "email",
|
|
684
|
+
* "<OTHER_PROVIDER>"
|
|
685
|
+
* ]
|
|
686
|
+
* },
|
|
687
|
+
* user_metadata: {
|
|
688
|
+
* email: 'email@email.com',
|
|
689
|
+
* email_verified: true,
|
|
690
|
+
* full_name: 'User Name',
|
|
691
|
+
* iss: '<ISS>',
|
|
692
|
+
* name: 'User Name',
|
|
693
|
+
* phone_verified: false,
|
|
694
|
+
* provider_id: '<PROVIDER_ID>',
|
|
695
|
+
* sub: '<SUB>'
|
|
696
|
+
* },
|
|
697
|
+
* identities: [
|
|
698
|
+
* {
|
|
699
|
+
* "identity_id": "22222222-2222-2222-2222-222222222222",
|
|
700
|
+
* "id": "11111111-1111-1111-1111-111111111111",
|
|
701
|
+
* "user_id": "11111111-1111-1111-1111-111111111111",
|
|
702
|
+
* "identity_data": {
|
|
703
|
+
* "email": "example@email.com",
|
|
704
|
+
* "email_verified": false,
|
|
705
|
+
* "phone_verified": false,
|
|
706
|
+
* "sub": "11111111-1111-1111-1111-111111111111"
|
|
707
|
+
* },
|
|
708
|
+
* "provider": "email",
|
|
709
|
+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
|
|
710
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
711
|
+
* "updated_at": "2024-01-01T00:00:00Z",
|
|
712
|
+
* "email": "email@example.com"
|
|
713
|
+
* },
|
|
714
|
+
* {
|
|
715
|
+
* "identity_id": "33333333-3333-3333-3333-333333333333",
|
|
716
|
+
* "id": "<ID>",
|
|
717
|
+
* "user_id": "<USER_ID>",
|
|
718
|
+
* "identity_data": {
|
|
719
|
+
* "email": "example@email.com",
|
|
720
|
+
* "email_verified": true,
|
|
721
|
+
* "full_name": "User Name",
|
|
722
|
+
* "iss": "<ISS>",
|
|
723
|
+
* "name": "User Name",
|
|
724
|
+
* "phone_verified": false,
|
|
725
|
+
* "provider_id": "<PROVIDER_ID>",
|
|
726
|
+
* "sub": "<SUB>"
|
|
727
|
+
* },
|
|
728
|
+
* "provider": "<PROVIDER>",
|
|
729
|
+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
|
|
730
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
731
|
+
* "updated_at": "2024-01-01T00:00:00Z",
|
|
732
|
+
* "email": "example@email.com"
|
|
733
|
+
* }
|
|
734
|
+
* ],
|
|
735
|
+
* created_at: '2024-01-01T00:00:00Z',
|
|
736
|
+
* updated_at: '2024-01-01T00:00:00Z',
|
|
737
|
+
* is_anonymous: false
|
|
738
|
+
* },
|
|
739
|
+
* redirectType: null
|
|
740
|
+
* },
|
|
741
|
+
* "error": null
|
|
742
|
+
* }
|
|
743
|
+
* ```
|
|
744
|
+
*/
|
|
745
|
+
exchangeCodeForSession(authCode: string): Promise<AuthTokenResponse>;
|
|
746
|
+
/**
|
|
747
|
+
* Signs in a user by verifying a message signed by the user's private key.
|
|
748
|
+
* Supports Ethereum (via Sign-In-With-Ethereum) & Solana (Sign-In-With-Solana) standards,
|
|
749
|
+
* both of which derive from the EIP-4361 standard
|
|
750
|
+
* With slight variation on Solana's side.
|
|
751
|
+
* @reference https://eips.ethereum.org/EIPS/eip-4361
|
|
752
|
+
*
|
|
753
|
+
* @category Auth
|
|
754
|
+
*
|
|
755
|
+
* @remarks
|
|
756
|
+
* - Uses a Web3 (Ethereum, Solana) wallet to sign a user in.
|
|
757
|
+
* - Read up on the [potential for abuse](/docs/guides/auth/auth-web3#potential-for-abuse) before using it.
|
|
758
|
+
*
|
|
759
|
+
* @example Sign in with Solana or Ethereum (Window API)
|
|
760
|
+
* ```js
|
|
761
|
+
* // uses window.ethereum for the wallet
|
|
762
|
+
* const { data, error } = await supabase.auth.signInWithWeb3({
|
|
763
|
+
* chain: 'ethereum',
|
|
764
|
+
* statement: 'I accept the Terms of Service at https://example.com/tos'
|
|
765
|
+
* })
|
|
766
|
+
*
|
|
767
|
+
* // uses window.solana for the wallet
|
|
768
|
+
* const { data, error } = await supabase.auth.signInWithWeb3({
|
|
769
|
+
* chain: 'solana',
|
|
770
|
+
* statement: 'I accept the Terms of Service at https://example.com/tos'
|
|
771
|
+
* })
|
|
772
|
+
* ```
|
|
773
|
+
*
|
|
774
|
+
* @example Sign in with Ethereum (Message and Signature)
|
|
775
|
+
* ```js
|
|
776
|
+
* const { data, error } = await supabase.auth.signInWithWeb3({
|
|
777
|
+
* chain: 'ethereum',
|
|
778
|
+
* message: '<sign in with ethereum message>',
|
|
779
|
+
* signature: '<hex of the ethereum signature over the message>',
|
|
780
|
+
* })
|
|
781
|
+
* ```
|
|
782
|
+
*
|
|
783
|
+
* @example Sign in with Solana (Brave)
|
|
784
|
+
* ```js
|
|
785
|
+
* const { data, error } = await supabase.auth.signInWithWeb3({
|
|
786
|
+
* chain: 'solana',
|
|
787
|
+
* statement: 'I accept the Terms of Service at https://example.com/tos',
|
|
788
|
+
* wallet: window.braveSolana
|
|
789
|
+
* })
|
|
790
|
+
* ```
|
|
791
|
+
*
|
|
792
|
+
* @example Sign in with Solana (Wallet Adapter)
|
|
793
|
+
* ```jsx
|
|
794
|
+
* function SignInButton() {
|
|
795
|
+
* const wallet = useWallet()
|
|
796
|
+
*
|
|
797
|
+
* return (
|
|
798
|
+
* <>
|
|
799
|
+
* {wallet.connected ? (
|
|
800
|
+
* <button
|
|
801
|
+
* onClick={() => {
|
|
802
|
+
* supabase.auth.signInWithWeb3({
|
|
803
|
+
* chain: 'solana',
|
|
804
|
+
* statement: 'I accept the Terms of Service at https://example.com/tos',
|
|
805
|
+
* wallet,
|
|
806
|
+
* })
|
|
807
|
+
* }}
|
|
808
|
+
* >
|
|
809
|
+
* Sign in with Solana
|
|
810
|
+
* </button>
|
|
811
|
+
* ) : (
|
|
812
|
+
* <WalletMultiButton />
|
|
813
|
+
* )}
|
|
814
|
+
* </>
|
|
815
|
+
* )
|
|
816
|
+
* }
|
|
817
|
+
*
|
|
818
|
+
* function App() {
|
|
819
|
+
* const endpoint = clusterApiUrl('devnet')
|
|
820
|
+
* const wallets = useMemo(() => [], [])
|
|
821
|
+
*
|
|
822
|
+
* return (
|
|
823
|
+
* <ConnectionProvider endpoint={endpoint}>
|
|
824
|
+
* <WalletProvider wallets={wallets}>
|
|
825
|
+
* <WalletModalProvider>
|
|
826
|
+
* <SignInButton />
|
|
827
|
+
* </WalletModalProvider>
|
|
828
|
+
* </WalletProvider>
|
|
829
|
+
* </ConnectionProvider>
|
|
830
|
+
* )
|
|
831
|
+
* }
|
|
832
|
+
* ```
|
|
833
|
+
*/
|
|
834
|
+
signInWithWeb3(credentials: Web3Credentials): Promise<{
|
|
835
|
+
data: {
|
|
836
|
+
session: Session;
|
|
837
|
+
user: User;
|
|
838
|
+
};
|
|
839
|
+
error: null;
|
|
840
|
+
} | {
|
|
841
|
+
data: {
|
|
842
|
+
session: null;
|
|
843
|
+
user: null;
|
|
844
|
+
};
|
|
845
|
+
error: AuthError;
|
|
846
|
+
}>;
|
|
847
|
+
private signInWithEthereum;
|
|
848
|
+
private signInWithSolana;
|
|
849
|
+
private _exchangeCodeForSession;
|
|
850
|
+
/**
|
|
851
|
+
* Allows signing in with an OIDC ID token. The authentication provider used
|
|
852
|
+
* should be enabled and configured.
|
|
853
|
+
*
|
|
854
|
+
* @category Auth
|
|
855
|
+
*
|
|
856
|
+
* @remarks
|
|
857
|
+
* - Use an ID token to sign in.
|
|
858
|
+
* - Especially useful when implementing sign in using native platform dialogs in mobile or desktop apps using Sign in with Apple or Sign in with Google on iOS and Android.
|
|
859
|
+
* - You can also use Google's [One Tap](https://developers.google.com/identity/gsi/web/guides/display-google-one-tap) and [Automatic sign-in](https://developers.google.com/identity/gsi/web/guides/automatic-sign-in-sign-out) via this API.
|
|
860
|
+
*
|
|
861
|
+
* @example Sign In using ID Token
|
|
862
|
+
* ```js
|
|
863
|
+
* const { data, error } = await supabase.auth.signInWithIdToken({
|
|
864
|
+
* provider: 'google',
|
|
865
|
+
* token: 'your-id-token'
|
|
866
|
+
* })
|
|
867
|
+
* ```
|
|
868
|
+
*
|
|
869
|
+
* @exampleResponse Sign In using ID Token
|
|
870
|
+
* ```json
|
|
871
|
+
* {
|
|
872
|
+
* "data": {
|
|
873
|
+
* "user": {
|
|
874
|
+
* "id": "11111111-1111-1111-1111-111111111111",
|
|
875
|
+
* "aud": "authenticated",
|
|
876
|
+
* "role": "authenticated",
|
|
877
|
+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
|
|
878
|
+
* "app_metadata": {
|
|
879
|
+
* ...
|
|
880
|
+
* },
|
|
881
|
+
* "user_metadata": {
|
|
882
|
+
* ...
|
|
883
|
+
* },
|
|
884
|
+
* "identities": [
|
|
885
|
+
* {
|
|
886
|
+
* "identity_id": "22222222-2222-2222-2222-222222222222",
|
|
887
|
+
* "provider": "google",
|
|
888
|
+
* }
|
|
889
|
+
* ],
|
|
890
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
891
|
+
* "updated_at": "2024-01-01T00:00:00Z",
|
|
892
|
+
* },
|
|
893
|
+
* "session": {
|
|
894
|
+
* "access_token": "<ACCESS_TOKEN>",
|
|
895
|
+
* "token_type": "bearer",
|
|
896
|
+
* "expires_in": 3600,
|
|
897
|
+
* "expires_at": 1700000000,
|
|
898
|
+
* "refresh_token": "<REFRESH_TOKEN>",
|
|
899
|
+
* "user": {
|
|
900
|
+
* "id": "11111111-1111-1111-1111-111111111111",
|
|
901
|
+
* "aud": "authenticated",
|
|
902
|
+
* "role": "authenticated",
|
|
903
|
+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
|
|
904
|
+
* "app_metadata": {
|
|
905
|
+
* ...
|
|
906
|
+
* },
|
|
907
|
+
* "user_metadata": {
|
|
908
|
+
* ...
|
|
909
|
+
* },
|
|
910
|
+
* "identities": [
|
|
911
|
+
* {
|
|
912
|
+
* "identity_id": "22222222-2222-2222-2222-222222222222",
|
|
913
|
+
* "provider": "google",
|
|
914
|
+
* }
|
|
915
|
+
* ],
|
|
916
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
917
|
+
* "updated_at": "2024-01-01T00:00:00Z",
|
|
918
|
+
* }
|
|
919
|
+
* }
|
|
920
|
+
* },
|
|
921
|
+
* "error": null
|
|
922
|
+
* }
|
|
923
|
+
* ```
|
|
924
|
+
*/
|
|
925
|
+
signInWithIdToken(credentials: SignInWithIdTokenCredentials): Promise<AuthTokenResponse>;
|
|
926
|
+
/**
|
|
927
|
+
* Log in a user using magiclink or a one-time password (OTP).
|
|
928
|
+
*
|
|
929
|
+
* If the `{{ .ConfirmationURL }}` variable is specified in the email template, a magiclink will be sent.
|
|
930
|
+
* If the `{{ .Token }}` variable is specified in the email template, an OTP will be sent.
|
|
931
|
+
* If you're using phone sign-ins, only an OTP will be sent. You won't be able to send a magiclink for phone sign-ins.
|
|
932
|
+
*
|
|
933
|
+
* Be aware that you may get back an error message that will not distinguish
|
|
934
|
+
* between the cases where the account does not exist or, that the account
|
|
935
|
+
* can only be accessed via social login.
|
|
936
|
+
*
|
|
937
|
+
* Do note that you will need to configure a Whatsapp sender on Twilio
|
|
938
|
+
* if you are using phone sign in with the 'whatsapp' channel. The whatsapp
|
|
939
|
+
* channel is not supported on other providers
|
|
940
|
+
* at this time.
|
|
941
|
+
* This method supports PKCE when an email is passed.
|
|
942
|
+
*
|
|
943
|
+
* @category Auth
|
|
944
|
+
*
|
|
945
|
+
* @remarks
|
|
946
|
+
* - Requires either an email or phone number.
|
|
947
|
+
* - This method is used for passwordless sign-ins where a OTP is sent to the user's email or phone number.
|
|
948
|
+
* - If the user doesn't exist, `signInWithOtp()` will signup the user instead. To restrict this behavior, you can set `shouldCreateUser` in `SignInWithPasswordlessCredentials.options` to `false`.
|
|
949
|
+
* - If you're using an email, you can configure whether you want the user to receive a magiclink or a OTP.
|
|
950
|
+
* - If you're using phone, you can configure whether you want the user to receive a OTP.
|
|
951
|
+
* - The magic link's destination URL is determined by the [`SITE_URL`](/docs/guides/auth/redirect-urls#use-wildcards-in-redirect-urls).
|
|
952
|
+
* - See [redirect URLs and wildcards](/docs/guides/auth/redirect-urls#use-wildcards-in-redirect-urls) to add additional redirect URLs to your project.
|
|
953
|
+
* - Magic links and OTPs share the same implementation. To send users a one-time code instead of a magic link, [modify the magic link email template](/dashboard/project/_/auth/templates) to include `{{ .Token }}` instead of `{{ .ConfirmationURL }}`.
|
|
954
|
+
* - See our [Twilio Phone Auth Guide](/docs/guides/auth/phone-login?showSMSProvider=Twilio) for details about configuring WhatsApp sign in.
|
|
955
|
+
*
|
|
956
|
+
* @exampleDescription Sign in with email
|
|
957
|
+
* The user will be sent an email which contains either a magiclink or a OTP or both. By default, a given user can only request a OTP once every 60 seconds.
|
|
958
|
+
*
|
|
959
|
+
* @example Sign in with email
|
|
960
|
+
* ```js
|
|
961
|
+
* const { data, error } = await supabase.auth.signInWithOtp({
|
|
962
|
+
* email: 'example@email.com',
|
|
963
|
+
* options: {
|
|
964
|
+
* emailRedirectTo: 'https://example.com/welcome'
|
|
965
|
+
* }
|
|
966
|
+
* })
|
|
967
|
+
* ```
|
|
968
|
+
*
|
|
969
|
+
* @exampleResponse Sign in with email
|
|
970
|
+
* ```json
|
|
971
|
+
* {
|
|
972
|
+
* "data": {
|
|
973
|
+
* "user": null,
|
|
974
|
+
* "session": null
|
|
975
|
+
* },
|
|
976
|
+
* "error": null
|
|
977
|
+
* }
|
|
978
|
+
* ```
|
|
979
|
+
*
|
|
980
|
+
* @exampleDescription Sign in with SMS OTP
|
|
981
|
+
* The user will be sent a SMS which contains a OTP. By default, a given user can only request a OTP once every 60 seconds.
|
|
982
|
+
*
|
|
983
|
+
* @example Sign in with SMS OTP
|
|
984
|
+
* ```js
|
|
985
|
+
* const { data, error } = await supabase.auth.signInWithOtp({
|
|
986
|
+
* phone: '+13334445555',
|
|
987
|
+
* })
|
|
988
|
+
* ```
|
|
989
|
+
*
|
|
990
|
+
* @exampleDescription Sign in with WhatsApp OTP
|
|
991
|
+
* The user will be sent a WhatsApp message which contains a OTP. By default, a given user can only request a OTP once every 60 seconds. Note that a user will need to have a valid WhatsApp account that is linked to Twilio in order to use this feature.
|
|
992
|
+
*
|
|
993
|
+
* @example Sign in with WhatsApp OTP
|
|
994
|
+
* ```js
|
|
995
|
+
* const { data, error } = await supabase.auth.signInWithOtp({
|
|
996
|
+
* phone: '+13334445555',
|
|
997
|
+
* options: {
|
|
998
|
+
* channel:'whatsapp',
|
|
999
|
+
* }
|
|
1000
|
+
* })
|
|
1001
|
+
* ```
|
|
1002
|
+
*/
|
|
1003
|
+
signInWithOtp(credentials: SignInWithPasswordlessCredentials): Promise<AuthOtpResponse>;
|
|
1004
|
+
/**
|
|
1005
|
+
* Log in a user given a User supplied OTP or TokenHash received through mobile or email.
|
|
1006
|
+
*
|
|
1007
|
+
* @category Auth
|
|
1008
|
+
*
|
|
1009
|
+
* @remarks
|
|
1010
|
+
* - The `verifyOtp` method takes in different verification types.
|
|
1011
|
+
* - If a phone number is used, the type can either be:
|
|
1012
|
+
* 1. `sms` – Used when verifying a one-time password (OTP) sent via SMS during sign-up or sign-in.
|
|
1013
|
+
* 2. `phone_change` – Used when verifying an OTP sent to a new phone number during a phone number update process.
|
|
1014
|
+
* - If an email address is used, the type can be one of the following (note: `signup` and `magiclink` types are deprecated):
|
|
1015
|
+
* 1. `email` – Used when verifying an OTP sent to the user's email during sign-up or sign-in.
|
|
1016
|
+
* 2. `recovery` – Used when verifying an OTP sent for account recovery, typically after a password reset request.
|
|
1017
|
+
* 3. `invite` – Used when verifying an OTP sent as part of an invitation to join a project or organization.
|
|
1018
|
+
* 4. `email_change` – Used when verifying an OTP sent to a new email address during an email update process.
|
|
1019
|
+
* - The verification type used should be determined based on the corresponding auth method called before `verifyOtp` to sign up / sign-in a user.
|
|
1020
|
+
* - The `TokenHash` is contained in the [email templates](/docs/guides/auth/auth-email-templates) and can be used to sign in. You may wish to use the hash for the PKCE flow for Server Side Auth. Read [the Password-based Auth guide](/docs/guides/auth/passwords) for more details.
|
|
1021
|
+
*
|
|
1022
|
+
* @example Verify Signup One-Time Password (OTP)
|
|
1023
|
+
* ```js
|
|
1024
|
+
* const { data, error } = await supabase.auth.verifyOtp({ email, token, type: 'email'})
|
|
1025
|
+
* ```
|
|
1026
|
+
*
|
|
1027
|
+
* @exampleResponse Verify Signup One-Time Password (OTP)
|
|
1028
|
+
* ```json
|
|
1029
|
+
* {
|
|
1030
|
+
* "data": {
|
|
1031
|
+
* "user": {
|
|
1032
|
+
* "id": "11111111-1111-1111-1111-111111111111",
|
|
1033
|
+
* "aud": "authenticated",
|
|
1034
|
+
* "role": "authenticated",
|
|
1035
|
+
* "email": "example@email.com",
|
|
1036
|
+
* "email_confirmed_at": "2024-01-01T00:00:00Z",
|
|
1037
|
+
* "phone": "",
|
|
1038
|
+
* "confirmed_at": "2024-01-01T00:00:00Z",
|
|
1039
|
+
* "recovery_sent_at": "2024-01-01T00:00:00Z",
|
|
1040
|
+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
|
|
1041
|
+
* "app_metadata": {
|
|
1042
|
+
* "provider": "email",
|
|
1043
|
+
* "providers": [
|
|
1044
|
+
* "email"
|
|
1045
|
+
* ]
|
|
1046
|
+
* },
|
|
1047
|
+
* "user_metadata": {
|
|
1048
|
+
* "email": "example@email.com",
|
|
1049
|
+
* "email_verified": false,
|
|
1050
|
+
* "phone_verified": false,
|
|
1051
|
+
* "sub": "11111111-1111-1111-1111-111111111111"
|
|
1052
|
+
* },
|
|
1053
|
+
* "identities": [
|
|
1054
|
+
* {
|
|
1055
|
+
* "identity_id": "22222222-2222-2222-2222-222222222222",
|
|
1056
|
+
* "id": "11111111-1111-1111-1111-111111111111",
|
|
1057
|
+
* "user_id": "11111111-1111-1111-1111-111111111111",
|
|
1058
|
+
* "identity_data": {
|
|
1059
|
+
* "email": "example@email.com",
|
|
1060
|
+
* "email_verified": false,
|
|
1061
|
+
* "phone_verified": false,
|
|
1062
|
+
* "sub": "11111111-1111-1111-1111-111111111111"
|
|
1063
|
+
* },
|
|
1064
|
+
* "provider": "email",
|
|
1065
|
+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
|
|
1066
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
1067
|
+
* "updated_at": "2024-01-01T00:00:00Z",
|
|
1068
|
+
* "email": "example@email.com"
|
|
1069
|
+
* }
|
|
1070
|
+
* ],
|
|
1071
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
1072
|
+
* "updated_at": "2024-01-01T00:00:00Z",
|
|
1073
|
+
* "is_anonymous": false
|
|
1074
|
+
* },
|
|
1075
|
+
* "session": {
|
|
1076
|
+
* "access_token": "<ACCESS_TOKEN>",
|
|
1077
|
+
* "token_type": "bearer",
|
|
1078
|
+
* "expires_in": 3600,
|
|
1079
|
+
* "expires_at": 1700000000,
|
|
1080
|
+
* "refresh_token": "<REFRESH_TOKEN>",
|
|
1081
|
+
* "user": {
|
|
1082
|
+
* "id": "11111111-1111-1111-1111-111111111111",
|
|
1083
|
+
* "aud": "authenticated",
|
|
1084
|
+
* "role": "authenticated",
|
|
1085
|
+
* "email": "example@email.com",
|
|
1086
|
+
* "email_confirmed_at": "2024-01-01T00:00:00Z",
|
|
1087
|
+
* "phone": "",
|
|
1088
|
+
* "confirmed_at": "2024-01-01T00:00:00Z",
|
|
1089
|
+
* "recovery_sent_at": "2024-01-01T00:00:00Z",
|
|
1090
|
+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
|
|
1091
|
+
* "app_metadata": {
|
|
1092
|
+
* "provider": "email",
|
|
1093
|
+
* "providers": [
|
|
1094
|
+
* "email"
|
|
1095
|
+
* ]
|
|
1096
|
+
* },
|
|
1097
|
+
* "user_metadata": {
|
|
1098
|
+
* "email": "example@email.com",
|
|
1099
|
+
* "email_verified": false,
|
|
1100
|
+
* "phone_verified": false,
|
|
1101
|
+
* "sub": "11111111-1111-1111-1111-111111111111"
|
|
1102
|
+
* },
|
|
1103
|
+
* "identities": [
|
|
1104
|
+
* {
|
|
1105
|
+
* "identity_id": "22222222-2222-2222-2222-222222222222",
|
|
1106
|
+
* "id": "11111111-1111-1111-1111-111111111111",
|
|
1107
|
+
* "user_id": "11111111-1111-1111-1111-111111111111",
|
|
1108
|
+
* "identity_data": {
|
|
1109
|
+
* "email": "example@email.com",
|
|
1110
|
+
* "email_verified": false,
|
|
1111
|
+
* "phone_verified": false,
|
|
1112
|
+
* "sub": "11111111-1111-1111-1111-111111111111"
|
|
1113
|
+
* },
|
|
1114
|
+
* "provider": "email",
|
|
1115
|
+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
|
|
1116
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
1117
|
+
* "updated_at": "2024-01-01T00:00:00Z",
|
|
1118
|
+
* "email": "example@email.com"
|
|
1119
|
+
* }
|
|
1120
|
+
* ],
|
|
1121
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
1122
|
+
* "updated_at": "2024-01-01T00:00:00Z",
|
|
1123
|
+
* "is_anonymous": false
|
|
1124
|
+
* }
|
|
1125
|
+
* }
|
|
1126
|
+
* },
|
|
1127
|
+
* "error": null
|
|
1128
|
+
* }
|
|
1129
|
+
* ```
|
|
1130
|
+
*
|
|
1131
|
+
* @example Verify SMS One-Time Password (OTP)
|
|
1132
|
+
* ```js
|
|
1133
|
+
* const { data, error } = await supabase.auth.verifyOtp({ phone, token, type: 'sms'})
|
|
1134
|
+
* ```
|
|
1135
|
+
*
|
|
1136
|
+
* @example Verify Email Auth (Token Hash)
|
|
1137
|
+
* ```js
|
|
1138
|
+
* const { data, error } = await supabase.auth.verifyOtp({ token_hash: tokenHash, type: 'email'})
|
|
1139
|
+
* ```
|
|
1140
|
+
*/
|
|
1141
|
+
verifyOtp(params: VerifyOtpParams): Promise<AuthResponse>;
|
|
1142
|
+
/**
|
|
1143
|
+
* Attempts a single-sign on using an enterprise Identity Provider. A
|
|
1144
|
+
* successful SSO attempt will redirect the current page to the identity
|
|
1145
|
+
* provider authorization page. The redirect URL is implementation and SSO
|
|
1146
|
+
* protocol specific.
|
|
1147
|
+
*
|
|
1148
|
+
* You can use it by providing a SSO domain. Typically you can extract this
|
|
1149
|
+
* domain by asking users for their email address. If this domain is
|
|
1150
|
+
* registered on the Auth instance the redirect will use that organization's
|
|
1151
|
+
* currently active SSO Identity Provider for the login.
|
|
1152
|
+
*
|
|
1153
|
+
* If you have built an organization-specific login page, you can use the
|
|
1154
|
+
* organization's SSO Identity Provider UUID directly instead.
|
|
1155
|
+
*
|
|
1156
|
+
* @category Auth
|
|
1157
|
+
*
|
|
1158
|
+
* @remarks
|
|
1159
|
+
* - Before you can call this method you need to [establish a connection](/docs/guides/auth/sso/auth-sso-saml#managing-saml-20-connections) to an identity provider. Use the [CLI commands](/docs/reference/cli/supabase-sso) to do this.
|
|
1160
|
+
* - If you've associated an email domain to the identity provider, you can use the `domain` property to start a sign-in flow.
|
|
1161
|
+
* - In case you need to use a different way to start the authentication flow with an identity provider, you can use the `providerId` property. For example:
|
|
1162
|
+
* - Mapping specific user email addresses with an identity provider.
|
|
1163
|
+
* - Using different hints to identity the identity provider to be used by the user, like a company-specific page, IP address or other tracking information.
|
|
1164
|
+
*
|
|
1165
|
+
* @example Sign in with email domain
|
|
1166
|
+
* ```js
|
|
1167
|
+
* // You can extract the user's email domain and use it to trigger the
|
|
1168
|
+
* // authentication flow with the correct identity provider.
|
|
1169
|
+
*
|
|
1170
|
+
* const { data, error } = await supabase.auth.signInWithSSO({
|
|
1171
|
+
* domain: 'company.com'
|
|
1172
|
+
* })
|
|
1173
|
+
*
|
|
1174
|
+
* if (data?.url) {
|
|
1175
|
+
* // redirect the user to the identity provider's authentication flow
|
|
1176
|
+
* window.location.href = data.url
|
|
1177
|
+
* }
|
|
1178
|
+
* ```
|
|
1179
|
+
*
|
|
1180
|
+
* @example Sign in with provider UUID
|
|
1181
|
+
* ```js
|
|
1182
|
+
* // Useful when you need to map a user's sign in request according
|
|
1183
|
+
* // to different rules that can't use email domains.
|
|
1184
|
+
*
|
|
1185
|
+
* const { data, error } = await supabase.auth.signInWithSSO({
|
|
1186
|
+
* providerId: '21648a9d-8d5a-4555-a9d1-d6375dc14e92'
|
|
1187
|
+
* })
|
|
1188
|
+
*
|
|
1189
|
+
* if (data?.url) {
|
|
1190
|
+
* // redirect the user to the identity provider's authentication flow
|
|
1191
|
+
* window.location.href = data.url
|
|
1192
|
+
* }
|
|
1193
|
+
* ```
|
|
1194
|
+
*/
|
|
1195
|
+
signInWithSSO(params: SignInWithSSO): Promise<SSOResponse>;
|
|
390
1196
|
/**
|
|
391
1197
|
* Sends a reauthentication OTP to the user's email or phone number.
|
|
392
1198
|
* Requires the user to be signed-in.
|
|
1199
|
+
*
|
|
1200
|
+
* @category Auth
|
|
1201
|
+
*
|
|
1202
|
+
* @remarks
|
|
1203
|
+
* - This method is used together with `updateUser()` when a user's password needs to be updated.
|
|
1204
|
+
* - If you require your user to reauthenticate before updating their password, you need to enable the **Secure password change** option in your [project's email provider settings](/dashboard/project/_/auth/providers).
|
|
1205
|
+
* - A user is only require to reauthenticate before updating their password if **Secure password change** is enabled and the user **hasn't recently signed in**. A user is deemed recently signed in if the session was created in the last 24 hours.
|
|
1206
|
+
* - This method will send a nonce to the user's email. If the user doesn't have a confirmed email address, the method will send the nonce to the user's confirmed phone number instead.
|
|
1207
|
+
* - After receiving the OTP, include it as the `nonce` in your `updateUser()` call to finalize the password change.
|
|
1208
|
+
*
|
|
1209
|
+
* @exampleDescription Send reauthentication nonce
|
|
1210
|
+
* Sends a reauthentication nonce to the user's email or phone number.
|
|
1211
|
+
*
|
|
1212
|
+
* @example Send reauthentication nonce
|
|
1213
|
+
* ```js
|
|
1214
|
+
* const { error } = await supabase.auth.reauthenticate()
|
|
1215
|
+
* ```
|
|
393
1216
|
*/
|
|
394
1217
|
reauthenticate(): Promise<AuthResponse>;
|
|
395
1218
|
private _reauthenticate;
|
|
396
1219
|
/**
|
|
397
1220
|
* Resends an existing signup confirmation email, email change email, SMS OTP or phone change OTP.
|
|
1221
|
+
*
|
|
1222
|
+
* @category Auth
|
|
1223
|
+
*
|
|
1224
|
+
* @remarks
|
|
1225
|
+
* - Resends a signup confirmation, email change or phone change email to the user.
|
|
1226
|
+
* - Passwordless sign-ins can be resent by calling the `signInWithOtp()` method again.
|
|
1227
|
+
* - Password recovery emails can be resent by calling the `resetPasswordForEmail()` method again.
|
|
1228
|
+
* - This method will only resend an email or phone OTP to the user if there was an initial signup, email change or phone change request being made(note: For existing users signing in with OTP, you should use `signInWithOtp()` again to resend the OTP).
|
|
1229
|
+
* - You can specify a redirect url when you resend an email link using the `emailRedirectTo` option.
|
|
1230
|
+
*
|
|
1231
|
+
* @exampleDescription Resend an email signup confirmation
|
|
1232
|
+
* Resends the email signup confirmation to the user
|
|
1233
|
+
*
|
|
1234
|
+
* @example Resend an email signup confirmation
|
|
1235
|
+
* ```js
|
|
1236
|
+
* const { error } = await supabase.auth.resend({
|
|
1237
|
+
* type: 'signup',
|
|
1238
|
+
* email: 'email@example.com',
|
|
1239
|
+
* options: {
|
|
1240
|
+
* emailRedirectTo: 'https://example.com/welcome'
|
|
1241
|
+
* }
|
|
1242
|
+
* })
|
|
1243
|
+
* ```
|
|
1244
|
+
*
|
|
1245
|
+
* @exampleDescription Resend a phone signup confirmation
|
|
1246
|
+
* Resends the phone signup confirmation email to the user
|
|
1247
|
+
*
|
|
1248
|
+
* @example Resend a phone signup confirmation
|
|
1249
|
+
* ```js
|
|
1250
|
+
* const { error } = await supabase.auth.resend({
|
|
1251
|
+
* type: 'sms',
|
|
1252
|
+
* phone: '1234567890'
|
|
1253
|
+
* })
|
|
1254
|
+
* ```
|
|
1255
|
+
*
|
|
1256
|
+
* @exampleDescription Resend email change email
|
|
1257
|
+
* Resends the email change email to the user
|
|
1258
|
+
*
|
|
1259
|
+
* @example Resend email change email
|
|
1260
|
+
* ```js
|
|
1261
|
+
* const { error } = await supabase.auth.resend({
|
|
1262
|
+
* type: 'email_change',
|
|
1263
|
+
* email: 'email@example.com'
|
|
1264
|
+
* })
|
|
1265
|
+
* ```
|
|
1266
|
+
*
|
|
1267
|
+
* @exampleDescription Resend phone change OTP
|
|
1268
|
+
* Resends the phone change OTP to the user
|
|
1269
|
+
*
|
|
1270
|
+
* @example Resend phone change OTP
|
|
1271
|
+
* ```js
|
|
1272
|
+
* const { error } = await supabase.auth.resend({
|
|
1273
|
+
* type: 'phone_change',
|
|
1274
|
+
* phone: '1234567890'
|
|
1275
|
+
* })
|
|
1276
|
+
* ```
|
|
398
1277
|
*/
|
|
399
1278
|
resend(credentials: ResendParams): Promise<AuthOtpResponse>;
|
|
400
1279
|
/**
|
|
@@ -407,6 +1286,80 @@ export default class GoTrueClient {
|
|
|
407
1286
|
* the values in it may not be authentic and therefore it's strongly advised
|
|
408
1287
|
* against using this method and its results in such circumstances. A warning
|
|
409
1288
|
* will be emitted if this is detected. Use {@link #getUser()} instead.
|
|
1289
|
+
*
|
|
1290
|
+
* @category Auth
|
|
1291
|
+
*
|
|
1292
|
+
* @remarks
|
|
1293
|
+
* - Since the introduction of [asymmetric JWT signing keys](/docs/guides/auth/signing-keys), this method is considered low-level and we encourage you to use `getClaims()` or `getUser()` instead.
|
|
1294
|
+
* - Retrieves the current [user session](/docs/guides/auth/sessions) from the storage medium (local storage, cookies).
|
|
1295
|
+
* - The session contains an access token (signed JWT), a refresh token and the user object.
|
|
1296
|
+
* - If the session's access token is expired or is about to expire, this method will use the refresh token to refresh the session.
|
|
1297
|
+
* - When using in a browser, or you've called `startAutoRefresh()` in your environment (React Native, etc.) this function always returns a valid access token without refreshing the session itself, as this is done in the background. This function returns very fast.
|
|
1298
|
+
* - **IMPORTANT SECURITY NOTICE:** If using an insecure storage medium, such as cookies or request headers, the user object returned by this function **must not be trusted**. Always verify the JWT using `getClaims()` or your own JWT verification library to securely establish the user's identity and access. You can also use `getUser()` to fetch the user object directly from the Auth server for this purpose.
|
|
1299
|
+
* - When using in a browser, this function is synchronized across all tabs using the [LockManager](https://developer.mozilla.org/en-US/docs/Web/API/LockManager) API. In other environments make sure you've defined a proper `lock` property, if necessary, to make sure there are no race conditions while the session is being refreshed.
|
|
1300
|
+
*
|
|
1301
|
+
* @example Get the session data
|
|
1302
|
+
* ```js
|
|
1303
|
+
* const { data, error } = await supabase.auth.getSession()
|
|
1304
|
+
* ```
|
|
1305
|
+
*
|
|
1306
|
+
* @exampleResponse Get the session data
|
|
1307
|
+
* ```json
|
|
1308
|
+
* {
|
|
1309
|
+
* "data": {
|
|
1310
|
+
* "session": {
|
|
1311
|
+
* "access_token": "<ACCESS_TOKEN>",
|
|
1312
|
+
* "token_type": "bearer",
|
|
1313
|
+
* "expires_in": 3600,
|
|
1314
|
+
* "expires_at": 1700000000,
|
|
1315
|
+
* "refresh_token": "<REFRESH_TOKEN>",
|
|
1316
|
+
* "user": {
|
|
1317
|
+
* "id": "11111111-1111-1111-1111-111111111111",
|
|
1318
|
+
* "aud": "authenticated",
|
|
1319
|
+
* "role": "authenticated",
|
|
1320
|
+
* "email": "example@email.com",
|
|
1321
|
+
* "email_confirmed_at": "2024-01-01T00:00:00Z",
|
|
1322
|
+
* "phone": "",
|
|
1323
|
+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
|
|
1324
|
+
* "app_metadata": {
|
|
1325
|
+
* "provider": "email",
|
|
1326
|
+
* "providers": [
|
|
1327
|
+
* "email"
|
|
1328
|
+
* ]
|
|
1329
|
+
* },
|
|
1330
|
+
* "user_metadata": {
|
|
1331
|
+
* "email": "example@email.com",
|
|
1332
|
+
* "email_verified": false,
|
|
1333
|
+
* "phone_verified": false,
|
|
1334
|
+
* "sub": "11111111-1111-1111-1111-111111111111"
|
|
1335
|
+
* },
|
|
1336
|
+
* "identities": [
|
|
1337
|
+
* {
|
|
1338
|
+
* "identity_id": "22222222-2222-2222-2222-222222222222",
|
|
1339
|
+
* "id": "11111111-1111-1111-1111-111111111111",
|
|
1340
|
+
* "user_id": "11111111-1111-1111-1111-111111111111",
|
|
1341
|
+
* "identity_data": {
|
|
1342
|
+
* "email": "example@email.com",
|
|
1343
|
+
* "email_verified": false,
|
|
1344
|
+
* "phone_verified": false,
|
|
1345
|
+
* "sub": "11111111-1111-1111-1111-111111111111"
|
|
1346
|
+
* },
|
|
1347
|
+
* "provider": "email",
|
|
1348
|
+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
|
|
1349
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
1350
|
+
* "updated_at": "2024-01-01T00:00:00Z",
|
|
1351
|
+
* "email": "example@email.com"
|
|
1352
|
+
* }
|
|
1353
|
+
* ],
|
|
1354
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
1355
|
+
* "updated_at": "2024-01-01T00:00:00Z",
|
|
1356
|
+
* "is_anonymous": false
|
|
1357
|
+
* }
|
|
1358
|
+
* }
|
|
1359
|
+
* },
|
|
1360
|
+
* "error": null
|
|
1361
|
+
* }
|
|
1362
|
+
* ```
|
|
410
1363
|
*/
|
|
411
1364
|
getSession(): Promise<{
|
|
412
1365
|
data: {
|
|
@@ -447,11 +1400,191 @@ export default class GoTrueClient {
|
|
|
447
1400
|
* value is authentic and can be used to base authorization rules on.
|
|
448
1401
|
*
|
|
449
1402
|
* @param jwt Takes in an optional access token JWT. If no JWT is provided, the JWT from the current session is used.
|
|
1403
|
+
*
|
|
1404
|
+
* @category Auth
|
|
1405
|
+
*
|
|
1406
|
+
* @remarks
|
|
1407
|
+
* - This method fetches the user object from the database instead of local session.
|
|
1408
|
+
* - This method is useful for checking if the user is authorized because it validates the user's access token JWT on the server.
|
|
1409
|
+
* - Should always be used when checking for user authorization on the server. On the client, you can instead use `getSession().session.user` for faster results. `getSession` is insecure on the server.
|
|
1410
|
+
*
|
|
1411
|
+
* @example Get the logged in user with the current existing session
|
|
1412
|
+
* ```js
|
|
1413
|
+
* const { data: { user } } = await supabase.auth.getUser()
|
|
1414
|
+
* ```
|
|
1415
|
+
*
|
|
1416
|
+
* @exampleResponse Get the logged in user with the current existing session
|
|
1417
|
+
* ```json
|
|
1418
|
+
* {
|
|
1419
|
+
* "data": {
|
|
1420
|
+
* "user": {
|
|
1421
|
+
* "id": "11111111-1111-1111-1111-111111111111",
|
|
1422
|
+
* "aud": "authenticated",
|
|
1423
|
+
* "role": "authenticated",
|
|
1424
|
+
* "email": "example@email.com",
|
|
1425
|
+
* "email_confirmed_at": "2024-01-01T00:00:00Z",
|
|
1426
|
+
* "phone": "",
|
|
1427
|
+
* "confirmed_at": "2024-01-01T00:00:00Z",
|
|
1428
|
+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
|
|
1429
|
+
* "app_metadata": {
|
|
1430
|
+
* "provider": "email",
|
|
1431
|
+
* "providers": [
|
|
1432
|
+
* "email"
|
|
1433
|
+
* ]
|
|
1434
|
+
* },
|
|
1435
|
+
* "user_metadata": {
|
|
1436
|
+
* "email": "example@email.com",
|
|
1437
|
+
* "email_verified": false,
|
|
1438
|
+
* "phone_verified": false,
|
|
1439
|
+
* "sub": "11111111-1111-1111-1111-111111111111"
|
|
1440
|
+
* },
|
|
1441
|
+
* "identities": [
|
|
1442
|
+
* {
|
|
1443
|
+
* "identity_id": "22222222-2222-2222-2222-222222222222",
|
|
1444
|
+
* "id": "11111111-1111-1111-1111-111111111111",
|
|
1445
|
+
* "user_id": "11111111-1111-1111-1111-111111111111",
|
|
1446
|
+
* "identity_data": {
|
|
1447
|
+
* "email": "example@email.com",
|
|
1448
|
+
* "email_verified": false,
|
|
1449
|
+
* "phone_verified": false,
|
|
1450
|
+
* "sub": "11111111-1111-1111-1111-111111111111"
|
|
1451
|
+
* },
|
|
1452
|
+
* "provider": "email",
|
|
1453
|
+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
|
|
1454
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
1455
|
+
* "updated_at": "2024-01-01T00:00:00Z",
|
|
1456
|
+
* "email": "example@email.com"
|
|
1457
|
+
* }
|
|
1458
|
+
* ],
|
|
1459
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
1460
|
+
* "updated_at": "2024-01-01T00:00:00Z",
|
|
1461
|
+
* "is_anonymous": false
|
|
1462
|
+
* }
|
|
1463
|
+
* },
|
|
1464
|
+
* "error": null
|
|
1465
|
+
* }
|
|
1466
|
+
* ```
|
|
1467
|
+
*
|
|
1468
|
+
* @example Get the logged in user with a custom access token jwt
|
|
1469
|
+
* ```js
|
|
1470
|
+
* const { data: { user } } = await supabase.auth.getUser(jwt)
|
|
1471
|
+
* ```
|
|
450
1472
|
*/
|
|
451
1473
|
getUser(jwt?: string): Promise<UserResponse>;
|
|
452
1474
|
private _getUser;
|
|
453
1475
|
/**
|
|
454
1476
|
* Updates user data for a logged in user.
|
|
1477
|
+
*
|
|
1478
|
+
* @category Auth
|
|
1479
|
+
*
|
|
1480
|
+
* @remarks
|
|
1481
|
+
* - In order to use the `updateUser()` method, the user needs to be signed in first.
|
|
1482
|
+
* - By default, email updates sends a confirmation link to both the user's current and new email.
|
|
1483
|
+
* To only send a confirmation link to the user's new email, disable **Secure email change** in your project's [email auth provider settings](/dashboard/project/_/auth/providers).
|
|
1484
|
+
*
|
|
1485
|
+
* @exampleDescription Update the email for an authenticated user
|
|
1486
|
+
* Sends a "Confirm Email Change" email to the new address. If **Secure Email Change** is enabled (default), confirmation is also required from the **old email** before the change is applied. To skip dual confirmation and apply the change after only the new email is verified, disable **Secure Email Change** in the [Email Auth Provider settings](/dashboard/project/_/auth/providers?provider=Email).
|
|
1487
|
+
*
|
|
1488
|
+
* @example Update the email for an authenticated user
|
|
1489
|
+
* ```js
|
|
1490
|
+
* const { data, error } = await supabase.auth.updateUser({
|
|
1491
|
+
* email: 'new@email.com'
|
|
1492
|
+
* })
|
|
1493
|
+
* ```
|
|
1494
|
+
*
|
|
1495
|
+
* @exampleResponse Update the email for an authenticated user
|
|
1496
|
+
* ```json
|
|
1497
|
+
* {
|
|
1498
|
+
* "data": {
|
|
1499
|
+
* "user": {
|
|
1500
|
+
* "id": "11111111-1111-1111-1111-111111111111",
|
|
1501
|
+
* "aud": "authenticated",
|
|
1502
|
+
* "role": "authenticated",
|
|
1503
|
+
* "email": "example@email.com",
|
|
1504
|
+
* "email_confirmed_at": "2024-01-01T00:00:00Z",
|
|
1505
|
+
* "phone": "",
|
|
1506
|
+
* "confirmed_at": "2024-01-01T00:00:00Z",
|
|
1507
|
+
* "new_email": "new@email.com",
|
|
1508
|
+
* "email_change_sent_at": "2024-01-01T00:00:00Z",
|
|
1509
|
+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
|
|
1510
|
+
* "app_metadata": {
|
|
1511
|
+
* "provider": "email",
|
|
1512
|
+
* "providers": [
|
|
1513
|
+
* "email"
|
|
1514
|
+
* ]
|
|
1515
|
+
* },
|
|
1516
|
+
* "user_metadata": {
|
|
1517
|
+
* "email": "example@email.com",
|
|
1518
|
+
* "email_verified": false,
|
|
1519
|
+
* "phone_verified": false,
|
|
1520
|
+
* "sub": "11111111-1111-1111-1111-111111111111"
|
|
1521
|
+
* },
|
|
1522
|
+
* "identities": [
|
|
1523
|
+
* {
|
|
1524
|
+
* "identity_id": "22222222-2222-2222-2222-222222222222",
|
|
1525
|
+
* "id": "11111111-1111-1111-1111-111111111111",
|
|
1526
|
+
* "user_id": "11111111-1111-1111-1111-111111111111",
|
|
1527
|
+
* "identity_data": {
|
|
1528
|
+
* "email": "example@email.com",
|
|
1529
|
+
* "email_verified": false,
|
|
1530
|
+
* "phone_verified": false,
|
|
1531
|
+
* "sub": "11111111-1111-1111-1111-111111111111"
|
|
1532
|
+
* },
|
|
1533
|
+
* "provider": "email",
|
|
1534
|
+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
|
|
1535
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
1536
|
+
* "updated_at": "2024-01-01T00:00:00Z",
|
|
1537
|
+
* "email": "example@email.com"
|
|
1538
|
+
* }
|
|
1539
|
+
* ],
|
|
1540
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
1541
|
+
* "updated_at": "2024-01-01T00:00:00Z",
|
|
1542
|
+
* "is_anonymous": false
|
|
1543
|
+
* }
|
|
1544
|
+
* },
|
|
1545
|
+
* "error": null
|
|
1546
|
+
* }
|
|
1547
|
+
* ```
|
|
1548
|
+
*
|
|
1549
|
+
* @exampleDescription Update the phone number for an authenticated user
|
|
1550
|
+
* Sends a one-time password (OTP) to the new phone number.
|
|
1551
|
+
*
|
|
1552
|
+
* @example Update the phone number for an authenticated user
|
|
1553
|
+
* ```js
|
|
1554
|
+
* const { data, error } = await supabase.auth.updateUser({
|
|
1555
|
+
* phone: '123456789'
|
|
1556
|
+
* })
|
|
1557
|
+
* ```
|
|
1558
|
+
*
|
|
1559
|
+
* @example Update the password for an authenticated user
|
|
1560
|
+
* ```js
|
|
1561
|
+
* const { data, error } = await supabase.auth.updateUser({
|
|
1562
|
+
* password: 'new password'
|
|
1563
|
+
* })
|
|
1564
|
+
* ```
|
|
1565
|
+
*
|
|
1566
|
+
* @exampleDescription Update the user's metadata
|
|
1567
|
+
* Updates the user's custom metadata.
|
|
1568
|
+
*
|
|
1569
|
+
* **Note**: The `data` field maps to the `auth.users.raw_user_meta_data` column in your Supabase database. When calling `getUser()`, the data will be available as `user.user_metadata`.
|
|
1570
|
+
*
|
|
1571
|
+
* @example Update the user's metadata
|
|
1572
|
+
* ```js
|
|
1573
|
+
* const { data, error } = await supabase.auth.updateUser({
|
|
1574
|
+
* data: { hello: 'world' }
|
|
1575
|
+
* })
|
|
1576
|
+
* ```
|
|
1577
|
+
*
|
|
1578
|
+
* @exampleDescription Update the user's password with a nonce
|
|
1579
|
+
* If **Secure password change** is enabled in your [project's email provider settings](/dashboard/project/_/auth/providers), updating the user's password would require a nonce if the user **hasn't recently signed in**. The nonce is sent to the user's email or phone number. A user is deemed recently signed in if the session was created in the last 24 hours.
|
|
1580
|
+
*
|
|
1581
|
+
* @example Update the user's password with a nonce
|
|
1582
|
+
* ```js
|
|
1583
|
+
* const { data, error } = await supabase.auth.updateUser({
|
|
1584
|
+
* password: 'new password',
|
|
1585
|
+
* nonce: '123456'
|
|
1586
|
+
* })
|
|
1587
|
+
* ```
|
|
455
1588
|
*/
|
|
456
1589
|
updateUser(attributes: UserAttributes, options?: {
|
|
457
1590
|
emailRedirectTo?: string | undefined;
|
|
@@ -463,6 +1596,125 @@ export default class GoTrueClient {
|
|
|
463
1596
|
* Sets the session data from the current session. If the current session is expired, setSession will take care of refreshing it to obtain a new session.
|
|
464
1597
|
* If the refresh token or access token in the current session is invalid, an error will be thrown.
|
|
465
1598
|
* @param currentSession The current session that minimally contains an access token and refresh token.
|
|
1599
|
+
*
|
|
1600
|
+
* @category Auth
|
|
1601
|
+
*
|
|
1602
|
+
* @remarks
|
|
1603
|
+
* - This method sets the session using an `access_token` and `refresh_token`.
|
|
1604
|
+
* - If successful, a `SIGNED_IN` event is emitted.
|
|
1605
|
+
*
|
|
1606
|
+
* @exampleDescription Set the session
|
|
1607
|
+
* Sets the session data from an access_token and refresh_token, then returns an auth response or error.
|
|
1608
|
+
*
|
|
1609
|
+
* @example Set the session
|
|
1610
|
+
* ```js
|
|
1611
|
+
* const { data, error } = await supabase.auth.setSession({
|
|
1612
|
+
* access_token,
|
|
1613
|
+
* refresh_token
|
|
1614
|
+
* })
|
|
1615
|
+
* ```
|
|
1616
|
+
*
|
|
1617
|
+
* @exampleResponse Set the session
|
|
1618
|
+
* ```json
|
|
1619
|
+
* {
|
|
1620
|
+
* "data": {
|
|
1621
|
+
* "user": {
|
|
1622
|
+
* "id": "11111111-1111-1111-1111-111111111111",
|
|
1623
|
+
* "aud": "authenticated",
|
|
1624
|
+
* "role": "authenticated",
|
|
1625
|
+
* "email": "example@email.com",
|
|
1626
|
+
* "email_confirmed_at": "2024-01-01T00:00:00Z",
|
|
1627
|
+
* "phone": "",
|
|
1628
|
+
* "confirmed_at": "2024-01-01T00:00:00Z",
|
|
1629
|
+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
|
|
1630
|
+
* "app_metadata": {
|
|
1631
|
+
* "provider": "email",
|
|
1632
|
+
* "providers": [
|
|
1633
|
+
* "email"
|
|
1634
|
+
* ]
|
|
1635
|
+
* },
|
|
1636
|
+
* "user_metadata": {
|
|
1637
|
+
* "email": "example@email.com",
|
|
1638
|
+
* "email_verified": false,
|
|
1639
|
+
* "phone_verified": false,
|
|
1640
|
+
* "sub": "11111111-1111-1111-1111-111111111111"
|
|
1641
|
+
* },
|
|
1642
|
+
* "identities": [
|
|
1643
|
+
* {
|
|
1644
|
+
* "identity_id": "22222222-2222-2222-2222-222222222222",
|
|
1645
|
+
* "id": "11111111-1111-1111-1111-111111111111",
|
|
1646
|
+
* "user_id": "11111111-1111-1111-1111-111111111111",
|
|
1647
|
+
* "identity_data": {
|
|
1648
|
+
* "email": "example@email.com",
|
|
1649
|
+
* "email_verified": false,
|
|
1650
|
+
* "phone_verified": false,
|
|
1651
|
+
* "sub": "11111111-1111-1111-1111-111111111111"
|
|
1652
|
+
* },
|
|
1653
|
+
* "provider": "email",
|
|
1654
|
+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
|
|
1655
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
1656
|
+
* "updated_at": "2024-01-01T00:00:00Z",
|
|
1657
|
+
* "email": "example@email.com"
|
|
1658
|
+
* }
|
|
1659
|
+
* ],
|
|
1660
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
1661
|
+
* "updated_at": "2024-01-01T00:00:00Z",
|
|
1662
|
+
* "is_anonymous": false
|
|
1663
|
+
* },
|
|
1664
|
+
* "session": {
|
|
1665
|
+
* "access_token": "<ACCESS_TOKEN>",
|
|
1666
|
+
* "refresh_token": "<REFRESH_TOKEN>",
|
|
1667
|
+
* "user": {
|
|
1668
|
+
* "id": "11111111-1111-1111-1111-111111111111",
|
|
1669
|
+
* "aud": "authenticated",
|
|
1670
|
+
* "role": "authenticated",
|
|
1671
|
+
* "email": "example@email.com",
|
|
1672
|
+
* "email_confirmed_at": "2024-01-01T00:00:00Z",
|
|
1673
|
+
* "phone": "",
|
|
1674
|
+
* "confirmed_at": "2024-01-01T00:00:00Z",
|
|
1675
|
+
* "last_sign_in_at": "11111111-1111-1111-1111-111111111111",
|
|
1676
|
+
* "app_metadata": {
|
|
1677
|
+
* "provider": "email",
|
|
1678
|
+
* "providers": [
|
|
1679
|
+
* "email"
|
|
1680
|
+
* ]
|
|
1681
|
+
* },
|
|
1682
|
+
* "user_metadata": {
|
|
1683
|
+
* "email": "example@email.com",
|
|
1684
|
+
* "email_verified": false,
|
|
1685
|
+
* "phone_verified": false,
|
|
1686
|
+
* "sub": "11111111-1111-1111-1111-111111111111"
|
|
1687
|
+
* },
|
|
1688
|
+
* "identities": [
|
|
1689
|
+
* {
|
|
1690
|
+
* "identity_id": "2024-01-01T00:00:00Z",
|
|
1691
|
+
* "id": "11111111-1111-1111-1111-111111111111",
|
|
1692
|
+
* "user_id": "11111111-1111-1111-1111-111111111111",
|
|
1693
|
+
* "identity_data": {
|
|
1694
|
+
* "email": "example@email.com",
|
|
1695
|
+
* "email_verified": false,
|
|
1696
|
+
* "phone_verified": false,
|
|
1697
|
+
* "sub": "11111111-1111-1111-1111-111111111111"
|
|
1698
|
+
* },
|
|
1699
|
+
* "provider": "email",
|
|
1700
|
+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
|
|
1701
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
1702
|
+
* "updated_at": "2024-01-01T00:00:00Z",
|
|
1703
|
+
* "email": "example@email.com"
|
|
1704
|
+
* }
|
|
1705
|
+
* ],
|
|
1706
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
1707
|
+
* "updated_at": "2024-01-01T00:00:00Z",
|
|
1708
|
+
* "is_anonymous": false
|
|
1709
|
+
* },
|
|
1710
|
+
* "token_type": "bearer",
|
|
1711
|
+
* "expires_in": 3500,
|
|
1712
|
+
* "expires_at": 1700000000
|
|
1713
|
+
* }
|
|
1714
|
+
* },
|
|
1715
|
+
* "error": null
|
|
1716
|
+
* }
|
|
1717
|
+
* ```
|
|
466
1718
|
*/
|
|
467
1719
|
setSession(currentSession: {
|
|
468
1720
|
access_token: string;
|
|
@@ -477,6 +1729,125 @@ export default class GoTrueClient {
|
|
|
477
1729
|
* Takes in an optional current session. If not passed in, then refreshSession() will attempt to retrieve it from getSession().
|
|
478
1730
|
* If the current session's refresh token is invalid, an error will be thrown.
|
|
479
1731
|
* @param currentSession The current session. If passed in, it must contain a refresh token.
|
|
1732
|
+
*
|
|
1733
|
+
* @category Auth
|
|
1734
|
+
*
|
|
1735
|
+
* @remarks
|
|
1736
|
+
* - This method will refresh and return a new session whether the current one is expired or not.
|
|
1737
|
+
*
|
|
1738
|
+
* @example Refresh session using the current session
|
|
1739
|
+
* ```js
|
|
1740
|
+
* const { data, error } = await supabase.auth.refreshSession()
|
|
1741
|
+
* const { session, user } = data
|
|
1742
|
+
* ```
|
|
1743
|
+
*
|
|
1744
|
+
* @exampleResponse Refresh session using the current session
|
|
1745
|
+
* ```json
|
|
1746
|
+
* {
|
|
1747
|
+
* "data": {
|
|
1748
|
+
* "user": {
|
|
1749
|
+
* "id": "11111111-1111-1111-1111-111111111111",
|
|
1750
|
+
* "aud": "authenticated",
|
|
1751
|
+
* "role": "authenticated",
|
|
1752
|
+
* "email": "example@email.com",
|
|
1753
|
+
* "email_confirmed_at": "2024-01-01T00:00:00Z",
|
|
1754
|
+
* "phone": "",
|
|
1755
|
+
* "confirmed_at": "2024-01-01T00:00:00Z",
|
|
1756
|
+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
|
|
1757
|
+
* "app_metadata": {
|
|
1758
|
+
* "provider": "email",
|
|
1759
|
+
* "providers": [
|
|
1760
|
+
* "email"
|
|
1761
|
+
* ]
|
|
1762
|
+
* },
|
|
1763
|
+
* "user_metadata": {
|
|
1764
|
+
* "email": "example@email.com",
|
|
1765
|
+
* "email_verified": false,
|
|
1766
|
+
* "phone_verified": false,
|
|
1767
|
+
* "sub": "11111111-1111-1111-1111-111111111111"
|
|
1768
|
+
* },
|
|
1769
|
+
* "identities": [
|
|
1770
|
+
* {
|
|
1771
|
+
* "identity_id": "22222222-2222-2222-2222-222222222222",
|
|
1772
|
+
* "id": "11111111-1111-1111-1111-111111111111",
|
|
1773
|
+
* "user_id": "11111111-1111-1111-1111-111111111111",
|
|
1774
|
+
* "identity_data": {
|
|
1775
|
+
* "email": "example@email.com",
|
|
1776
|
+
* "email_verified": false,
|
|
1777
|
+
* "phone_verified": false,
|
|
1778
|
+
* "sub": "11111111-1111-1111-1111-111111111111"
|
|
1779
|
+
* },
|
|
1780
|
+
* "provider": "email",
|
|
1781
|
+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
|
|
1782
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
1783
|
+
* "updated_at": "2024-01-01T00:00:00Z",
|
|
1784
|
+
* "email": "example@email.com"
|
|
1785
|
+
* }
|
|
1786
|
+
* ],
|
|
1787
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
1788
|
+
* "updated_at": "2024-01-01T00:00:00Z",
|
|
1789
|
+
* "is_anonymous": false
|
|
1790
|
+
* },
|
|
1791
|
+
* "session": {
|
|
1792
|
+
* "access_token": "<ACCESS_TOKEN>",
|
|
1793
|
+
* "token_type": "bearer",
|
|
1794
|
+
* "expires_in": 3600,
|
|
1795
|
+
* "expires_at": 1700000000,
|
|
1796
|
+
* "refresh_token": "<REFRESH_TOKEN>",
|
|
1797
|
+
* "user": {
|
|
1798
|
+
* "id": "11111111-1111-1111-1111-111111111111",
|
|
1799
|
+
* "aud": "authenticated",
|
|
1800
|
+
* "role": "authenticated",
|
|
1801
|
+
* "email": "example@email.com",
|
|
1802
|
+
* "email_confirmed_at": "2024-01-01T00:00:00Z",
|
|
1803
|
+
* "phone": "",
|
|
1804
|
+
* "confirmed_at": "2024-01-01T00:00:00Z",
|
|
1805
|
+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
|
|
1806
|
+
* "app_metadata": {
|
|
1807
|
+
* "provider": "email",
|
|
1808
|
+
* "providers": [
|
|
1809
|
+
* "email"
|
|
1810
|
+
* ]
|
|
1811
|
+
* },
|
|
1812
|
+
* "user_metadata": {
|
|
1813
|
+
* "email": "example@email.com",
|
|
1814
|
+
* "email_verified": false,
|
|
1815
|
+
* "phone_verified": false,
|
|
1816
|
+
* "sub": "11111111-1111-1111-1111-111111111111"
|
|
1817
|
+
* },
|
|
1818
|
+
* "identities": [
|
|
1819
|
+
* {
|
|
1820
|
+
* "identity_id": "22222222-2222-2222-2222-222222222222",
|
|
1821
|
+
* "id": "11111111-1111-1111-1111-111111111111",
|
|
1822
|
+
* "user_id": "11111111-1111-1111-1111-111111111111",
|
|
1823
|
+
* "identity_data": {
|
|
1824
|
+
* "email": "example@email.com",
|
|
1825
|
+
* "email_verified": false,
|
|
1826
|
+
* "phone_verified": false,
|
|
1827
|
+
* "sub": "11111111-1111-1111-1111-111111111111"
|
|
1828
|
+
* },
|
|
1829
|
+
* "provider": "email",
|
|
1830
|
+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
|
|
1831
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
1832
|
+
* "updated_at": "2024-01-01T00:00:00Z",
|
|
1833
|
+
* "email": "example@email.com"
|
|
1834
|
+
* }
|
|
1835
|
+
* ],
|
|
1836
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
1837
|
+
* "updated_at": "2024-01-01T00:00:00Z",
|
|
1838
|
+
* "is_anonymous": false
|
|
1839
|
+
* }
|
|
1840
|
+
* }
|
|
1841
|
+
* },
|
|
1842
|
+
* "error": null
|
|
1843
|
+
* }
|
|
1844
|
+
* ```
|
|
1845
|
+
*
|
|
1846
|
+
* @example Refresh session using a refresh token
|
|
1847
|
+
* ```js
|
|
1848
|
+
* const { data, error } = await supabase.auth.refreshSession({ refresh_token })
|
|
1849
|
+
* const { session, user } = data
|
|
1850
|
+
* ```
|
|
480
1851
|
*/
|
|
481
1852
|
refreshSession(currentSession?: {
|
|
482
1853
|
refresh_token: string;
|
|
@@ -507,6 +1878,28 @@ export default class GoTrueClient {
|
|
|
507
1878
|
* There is no way to revoke a user's access token jwt until it expires. It is recommended to set a shorter expiry on the jwt for this reason.
|
|
508
1879
|
*
|
|
509
1880
|
* If using `others` scope, no `SIGNED_OUT` event is fired!
|
|
1881
|
+
*
|
|
1882
|
+
* @category Auth
|
|
1883
|
+
*
|
|
1884
|
+
* @remarks
|
|
1885
|
+
* - In order to use the `signOut()` method, the user needs to be signed in first.
|
|
1886
|
+
* - By default, `signOut()` uses the global scope, which signs out all other sessions that the user is logged into as well. Customize this behavior by passing a scope parameter.
|
|
1887
|
+
* - Since Supabase Auth uses JWTs for authentication, the access token JWT will be valid until it's expired. When the user signs out, Supabase revokes the refresh token and deletes the JWT from the client-side. This does not revoke the JWT and it will still be valid until it expires.
|
|
1888
|
+
*
|
|
1889
|
+
* @example Sign out (all sessions)
|
|
1890
|
+
* ```js
|
|
1891
|
+
* const { error } = await supabase.auth.signOut()
|
|
1892
|
+
* ```
|
|
1893
|
+
*
|
|
1894
|
+
* @example Sign out (current session)
|
|
1895
|
+
* ```js
|
|
1896
|
+
* const { error } = await supabase.auth.signOut({ scope: 'local' })
|
|
1897
|
+
* ```
|
|
1898
|
+
*
|
|
1899
|
+
* @example Sign out (other sessions)
|
|
1900
|
+
* ```js
|
|
1901
|
+
* const { error } = await supabase.auth.signOut({ scope: 'others' })
|
|
1902
|
+
* ```
|
|
510
1903
|
*/
|
|
511
1904
|
signOut(options?: SignOut): Promise<{
|
|
512
1905
|
error: AuthError | null;
|
|
@@ -549,6 +1942,66 @@ export default class GoTrueClient {
|
|
|
549
1942
|
* @param email The email address of the user.
|
|
550
1943
|
* @param options.redirectTo The URL to send the user to after they click the password reset link.
|
|
551
1944
|
* @param options.captchaToken Verification token received when the user completes the captcha on the site.
|
|
1945
|
+
*
|
|
1946
|
+
* @category Auth
|
|
1947
|
+
*
|
|
1948
|
+
* @remarks
|
|
1949
|
+
* - The password reset flow consist of 2 broad steps: (i) Allow the user to login via the password reset link; (ii) Update the user's password.
|
|
1950
|
+
* - The `resetPasswordForEmail()` only sends a password reset link to the user's email.
|
|
1951
|
+
* To update the user's password, see [`updateUser()`](/docs/reference/javascript/auth-updateuser).
|
|
1952
|
+
* - A `PASSWORD_RECOVERY` event will be emitted when the password recovery link is clicked.
|
|
1953
|
+
* You can use [`onAuthStateChange()`](/docs/reference/javascript/auth-onauthstatechange) to listen and invoke a callback function on these events.
|
|
1954
|
+
* - When the user clicks the reset link in the email they are redirected back to your application.
|
|
1955
|
+
* You can configure the URL that the user is redirected to with the `redirectTo` parameter.
|
|
1956
|
+
* See [redirect URLs and wildcards](/docs/guides/auth/redirect-urls#use-wildcards-in-redirect-urls) to add additional redirect URLs to your project.
|
|
1957
|
+
* - After the user has been redirected successfully, prompt them for a new password and call `updateUser()`:
|
|
1958
|
+
* ```js
|
|
1959
|
+
* const { data, error } = await supabase.auth.updateUser({
|
|
1960
|
+
* password: new_password
|
|
1961
|
+
* })
|
|
1962
|
+
* ```
|
|
1963
|
+
*
|
|
1964
|
+
* @example Reset password
|
|
1965
|
+
* ```js
|
|
1966
|
+
* const { data, error } = await supabase.auth.resetPasswordForEmail(email, {
|
|
1967
|
+
* redirectTo: 'https://example.com/update-password',
|
|
1968
|
+
* })
|
|
1969
|
+
* ```
|
|
1970
|
+
*
|
|
1971
|
+
* @exampleResponse Reset password
|
|
1972
|
+
* ```json
|
|
1973
|
+
* {
|
|
1974
|
+
* data: {}
|
|
1975
|
+
* error: null
|
|
1976
|
+
* }
|
|
1977
|
+
* ```
|
|
1978
|
+
*
|
|
1979
|
+
* @example Reset password (React)
|
|
1980
|
+
* ```js
|
|
1981
|
+
* /**
|
|
1982
|
+
* * Step 1: Send the user an email to get a password reset token.
|
|
1983
|
+
* * This email contains a link which sends the user back to your application.
|
|
1984
|
+
* *\/
|
|
1985
|
+
* const { data, error } = await supabase.auth
|
|
1986
|
+
* .resetPasswordForEmail('user@email.com')
|
|
1987
|
+
*
|
|
1988
|
+
* /**
|
|
1989
|
+
* * Step 2: Once the user is redirected back to your application,
|
|
1990
|
+
* * ask the user to reset their password.
|
|
1991
|
+
* *\/
|
|
1992
|
+
* useEffect(() => {
|
|
1993
|
+
* supabase.auth.onAuthStateChange(async (event, session) => {
|
|
1994
|
+
* if (event == "PASSWORD_RECOVERY") {
|
|
1995
|
+
* const newPassword = prompt("What would you like your new password to be?");
|
|
1996
|
+
* const { data, error } = await supabase.auth
|
|
1997
|
+
* .updateUser({ password: newPassword })
|
|
1998
|
+
*
|
|
1999
|
+
* if (data) alert("Password updated successfully!")
|
|
2000
|
+
* if (error) alert("There was an error updating your password.")
|
|
2001
|
+
* }
|
|
2002
|
+
* })
|
|
2003
|
+
* }, [])
|
|
2004
|
+
* ```
|
|
552
2005
|
*/
|
|
553
2006
|
resetPasswordForEmail(email: string, options?: {
|
|
554
2007
|
redirectTo?: string;
|
|
@@ -562,6 +2015,43 @@ export default class GoTrueClient {
|
|
|
562
2015
|
}>;
|
|
563
2016
|
/**
|
|
564
2017
|
* Gets all the identities linked to a user.
|
|
2018
|
+
*
|
|
2019
|
+
* @category Auth
|
|
2020
|
+
*
|
|
2021
|
+
* @remarks
|
|
2022
|
+
* - The user needs to be signed in to call `getUserIdentities()`.
|
|
2023
|
+
*
|
|
2024
|
+
* @example Returns a list of identities linked to the user
|
|
2025
|
+
* ```js
|
|
2026
|
+
* const { data, error } = await supabase.auth.getUserIdentities()
|
|
2027
|
+
* ```
|
|
2028
|
+
*
|
|
2029
|
+
* @exampleResponse Returns a list of identities linked to the user
|
|
2030
|
+
* ```json
|
|
2031
|
+
* {
|
|
2032
|
+
* "data": {
|
|
2033
|
+
* "identities": [
|
|
2034
|
+
* {
|
|
2035
|
+
* "identity_id": "22222222-2222-2222-2222-222222222222",
|
|
2036
|
+
* "id": "2024-01-01T00:00:00Z",
|
|
2037
|
+
* "user_id": "2024-01-01T00:00:00Z",
|
|
2038
|
+
* "identity_data": {
|
|
2039
|
+
* "email": "example@email.com",
|
|
2040
|
+
* "email_verified": false,
|
|
2041
|
+
* "phone_verified": false,
|
|
2042
|
+
* "sub": "11111111-1111-1111-1111-111111111111"
|
|
2043
|
+
* },
|
|
2044
|
+
* "provider": "email",
|
|
2045
|
+
* "last_sign_in_at": "2024-01-01T00:00:00Z",
|
|
2046
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
2047
|
+
* "updated_at": "2024-01-01T00:00:00Z",
|
|
2048
|
+
* "email": "example@email.com"
|
|
2049
|
+
* }
|
|
2050
|
+
* ]
|
|
2051
|
+
* },
|
|
2052
|
+
* "error": null
|
|
2053
|
+
* }
|
|
2054
|
+
* ```
|
|
565
2055
|
*/
|
|
566
2056
|
getUserIdentities(): Promise<{
|
|
567
2057
|
data: {
|
|
@@ -585,6 +2075,28 @@ export default class GoTrueClient {
|
|
|
585
2075
|
private linkIdentityIdToken;
|
|
586
2076
|
/**
|
|
587
2077
|
* Unlinks an identity from a user by deleting it. The user will no longer be able to sign in with that identity once it's unlinked.
|
|
2078
|
+
*
|
|
2079
|
+
* @category Auth
|
|
2080
|
+
*
|
|
2081
|
+
* @remarks
|
|
2082
|
+
* - The **Enable Manual Linking** option must be enabled from your [project's authentication settings](/dashboard/project/_/auth/providers).
|
|
2083
|
+
* - The user needs to be signed in to call `unlinkIdentity()`.
|
|
2084
|
+
* - The user must have at least 2 identities in order to unlink an identity.
|
|
2085
|
+
* - The identity to be unlinked must belong to the user.
|
|
2086
|
+
*
|
|
2087
|
+
* @example Unlink an identity
|
|
2088
|
+
* ```js
|
|
2089
|
+
* // retrieve all identities linked to a user
|
|
2090
|
+
* const identities = await supabase.auth.getUserIdentities()
|
|
2091
|
+
*
|
|
2092
|
+
* // find the google identity
|
|
2093
|
+
* const googleIdentity = identities.find(
|
|
2094
|
+
* identity => identity.provider === 'google'
|
|
2095
|
+
* )
|
|
2096
|
+
*
|
|
2097
|
+
* // unlink the google identity
|
|
2098
|
+
* const { error } = await supabase.auth.unlinkIdentity(googleIdentity)
|
|
2099
|
+
* ```
|
|
588
2100
|
*/
|
|
589
2101
|
unlinkIdentity(identity: UserIdentity): Promise<{
|
|
590
2102
|
data: {};
|
|
@@ -651,6 +2163,28 @@ export default class GoTrueClient {
|
|
|
651
2163
|
* appropriately to conserve resources.
|
|
652
2164
|
*
|
|
653
2165
|
* {@see #stopAutoRefresh}
|
|
2166
|
+
*
|
|
2167
|
+
* @category Auth
|
|
2168
|
+
*
|
|
2169
|
+
* @remarks
|
|
2170
|
+
* - Only useful in non-browser environments such as React Native or Electron.
|
|
2171
|
+
* - The Supabase Auth library automatically starts and stops proactively refreshing the session when a tab is focused or not.
|
|
2172
|
+
* - On non-browser platforms, such as mobile or desktop apps built with web technologies, the library is not able to effectively determine whether the application is _focused_ or not.
|
|
2173
|
+
* - To give this hint to the application, you should be calling this method when the app is in focus and calling `supabase.auth.stopAutoRefresh()` when it's out of focus.
|
|
2174
|
+
*
|
|
2175
|
+
* @example Start and stop auto refresh in React Native
|
|
2176
|
+
* ```js
|
|
2177
|
+
* import { AppState } from 'react-native'
|
|
2178
|
+
*
|
|
2179
|
+
* // make sure you register this only once!
|
|
2180
|
+
* AppState.addEventListener('change', (state) => {
|
|
2181
|
+
* if (state === 'active') {
|
|
2182
|
+
* supabase.auth.startAutoRefresh()
|
|
2183
|
+
* } else {
|
|
2184
|
+
* supabase.auth.stopAutoRefresh()
|
|
2185
|
+
* }
|
|
2186
|
+
* })
|
|
2187
|
+
* ```
|
|
654
2188
|
*/
|
|
655
2189
|
startAutoRefresh(): Promise<void>;
|
|
656
2190
|
/**
|
|
@@ -660,6 +2194,28 @@ export default class GoTrueClient {
|
|
|
660
2194
|
* removed and you must manage visibility changes on your own.
|
|
661
2195
|
*
|
|
662
2196
|
* See {@link #startAutoRefresh} for more details.
|
|
2197
|
+
*
|
|
2198
|
+
* @category Auth
|
|
2199
|
+
*
|
|
2200
|
+
* @remarks
|
|
2201
|
+
* - Only useful in non-browser environments such as React Native or Electron.
|
|
2202
|
+
* - The Supabase Auth library automatically starts and stops proactively refreshing the session when a tab is focused or not.
|
|
2203
|
+
* - On non-browser platforms, such as mobile or desktop apps built with web technologies, the library is not able to effectively determine whether the application is _focused_ or not.
|
|
2204
|
+
* - When your application goes in the background or out of focus, call this method to stop the proactive refreshing of the session.
|
|
2205
|
+
*
|
|
2206
|
+
* @example Start and stop auto refresh in React Native
|
|
2207
|
+
* ```js
|
|
2208
|
+
* import { AppState } from 'react-native'
|
|
2209
|
+
*
|
|
2210
|
+
* // make sure you register this only once!
|
|
2211
|
+
* AppState.addEventListener('change', (state) => {
|
|
2212
|
+
* if (state === 'active') {
|
|
2213
|
+
* supabase.auth.startAutoRefresh()
|
|
2214
|
+
* } else {
|
|
2215
|
+
* supabase.auth.stopAutoRefresh()
|
|
2216
|
+
* }
|
|
2217
|
+
* })
|
|
2218
|
+
* ```
|
|
663
2219
|
*/
|
|
664
2220
|
stopAutoRefresh(): Promise<void>;
|
|
665
2221
|
/**
|
|
@@ -753,6 +2309,55 @@ export default class GoTrueClient {
|
|
|
753
2309
|
* can obtain from {@link #getSession}.
|
|
754
2310
|
* @param options Various additional options that allow you to customize the
|
|
755
2311
|
* behavior of this method.
|
|
2312
|
+
*
|
|
2313
|
+
* @category Auth
|
|
2314
|
+
*
|
|
2315
|
+
* @remarks
|
|
2316
|
+
* - Parses the user's [access token](/docs/guides/auth/sessions#access-token-jwt-claims) as a [JSON Web Token (JWT)](/docs/guides/auth/jwts) and returns its components if valid and not expired.
|
|
2317
|
+
* - If your project is using asymmetric JWT signing keys, then the verification is done locally usually without a network request using the [WebCrypto API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API).
|
|
2318
|
+
* - A network request is sent to your project's JWT signing key discovery endpoint `https://project-id.supabase.co/auth/v1/.well-known/jwks.json`, which is cached locally. If your environment is ephemeral, such as a Lambda function that is destroyed after every request, a network request will be sent for each new invocation. Supabase provides a network-edge cache providing fast responses for these situations.
|
|
2319
|
+
* - If the user's access token is about to expire when calling this function, the user's session will first be refreshed before validating the JWT.
|
|
2320
|
+
* - If your project is using a symmetric secret to sign the JWT, it always sends a request similar to `getUser()` to validate the JWT at the server before returning the decoded token. This is also used if the WebCrypto API is not available in the environment. Make sure you polyfill it in such situations.
|
|
2321
|
+
* - The returned claims can be customized per project using the [Custom Access Token Hook](/docs/guides/auth/auth-hooks/custom-access-token-hook).
|
|
2322
|
+
*
|
|
2323
|
+
* @example Get JWT claims, header and signature
|
|
2324
|
+
* ```js
|
|
2325
|
+
* const { data, error } = await supabase.auth.getClaims()
|
|
2326
|
+
* ```
|
|
2327
|
+
*
|
|
2328
|
+
* @exampleResponse Get JWT claims, header and signature
|
|
2329
|
+
* ```json
|
|
2330
|
+
* {
|
|
2331
|
+
* "data": {
|
|
2332
|
+
* "claims": {
|
|
2333
|
+
* "aal": "aal1",
|
|
2334
|
+
* "amr": [{
|
|
2335
|
+
* "method": "email",
|
|
2336
|
+
* "timestamp": 1715766000
|
|
2337
|
+
* }],
|
|
2338
|
+
* "app_metadata": {},
|
|
2339
|
+
* "aud": "authenticated",
|
|
2340
|
+
* "email": "example@email.com",
|
|
2341
|
+
* "exp": 1715769600,
|
|
2342
|
+
* "iat": 1715766000,
|
|
2343
|
+
* "is_anonymous": false,
|
|
2344
|
+
* "iss": "https://project-id.supabase.co/auth/v1",
|
|
2345
|
+
* "phone": "+13334445555",
|
|
2346
|
+
* "role": "authenticated",
|
|
2347
|
+
* "session_id": "11111111-1111-1111-1111-111111111111",
|
|
2348
|
+
* "sub": "11111111-1111-1111-1111-111111111111",
|
|
2349
|
+
* "user_metadata": {}
|
|
2350
|
+
* },
|
|
2351
|
+
* "header": {
|
|
2352
|
+
* "alg": "RS256",
|
|
2353
|
+
* "typ": "JWT",
|
|
2354
|
+
* "kid": "11111111-1111-1111-1111-111111111111"
|
|
2355
|
+
* },
|
|
2356
|
+
* "signature": [/** Uint8Array *\/],
|
|
2357
|
+
* },
|
|
2358
|
+
* "error": null
|
|
2359
|
+
* }
|
|
2360
|
+
* ```
|
|
756
2361
|
*/
|
|
757
2362
|
getClaims(jwt?: string, options?: {
|
|
758
2363
|
/**
|