@supabase/auth-js 2.100.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.
@@ -455,6 +455,8 @@ export default class GoTrueClient {
455
455
  * Initializes the client session either from the url or from storage.
456
456
  * This method is automatically called when instantiating the client, but should also be called
457
457
  * manually when checking for an error from an auth redirect (oauth, magiclink, password recovery, etc).
458
+ *
459
+ * @category Auth
458
460
  */
459
461
  async initialize(): Promise<InitializeResult> {
460
462
  if (this.initializePromise) {
@@ -561,6 +563,74 @@ export default class GoTrueClient {
561
563
  * Creates a new anonymous user.
562
564
  *
563
565
  * @returns A session where the is_anonymous claim in the access token JWT set to true
566
+ *
567
+ * @category Auth
568
+ *
569
+ * @remarks
570
+ * - Returns an anonymous user
571
+ * - 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.
572
+ *
573
+ * @example Create an anonymous user
574
+ * ```js
575
+ * const { data, error } = await supabase.auth.signInAnonymously({
576
+ * options: {
577
+ * captchaToken
578
+ * }
579
+ * });
580
+ * ```
581
+ *
582
+ * @exampleResponse Create an anonymous user
583
+ * ```json
584
+ * {
585
+ * "data": {
586
+ * "user": {
587
+ * "id": "11111111-1111-1111-1111-111111111111",
588
+ * "aud": "authenticated",
589
+ * "role": "authenticated",
590
+ * "email": "",
591
+ * "phone": "",
592
+ * "last_sign_in_at": "2024-01-01T00:00:00Z",
593
+ * "app_metadata": {},
594
+ * "user_metadata": {},
595
+ * "identities": [],
596
+ * "created_at": "2024-01-01T00:00:00Z",
597
+ * "updated_at": "2024-01-01T00:00:00Z",
598
+ * "is_anonymous": true
599
+ * },
600
+ * "session": {
601
+ * "access_token": "<ACCESS_TOKEN>",
602
+ * "token_type": "bearer",
603
+ * "expires_in": 3600,
604
+ * "expires_at": 1700000000,
605
+ * "refresh_token": "<REFRESH_TOKEN>",
606
+ * "user": {
607
+ * "id": "11111111-1111-1111-1111-111111111111",
608
+ * "aud": "authenticated",
609
+ * "role": "authenticated",
610
+ * "email": "",
611
+ * "phone": "",
612
+ * "last_sign_in_at": "2024-01-01T00:00:00Z",
613
+ * "app_metadata": {},
614
+ * "user_metadata": {},
615
+ * "identities": [],
616
+ * "created_at": "2024-01-01T00:00:00Z",
617
+ * "updated_at": "2024-01-01T00:00:00Z",
618
+ * "is_anonymous": true
619
+ * }
620
+ * }
621
+ * },
622
+ * "error": null
623
+ * }
624
+ * ```
625
+ *
626
+ * @example Create an anonymous user with custom user metadata
627
+ * ```js
628
+ * const { data, error } = await supabase.auth.signInAnonymously({
629
+ * options: {
630
+ * data
631
+ * }
632
+ * })
633
+ * ```
564
634
  */
565
635
  async signInAnonymously(credentials?: SignInAnonymouslyCredentials): Promise<AuthResponse> {
566
636
  try {
@@ -850,6 +920,115 @@ export default class GoTrueClient {
850
920
  * between the cases where the account does not exist or that the
851
921
  * email/phone and password combination is wrong or that the account can only
852
922
  * be accessed via social login.
923
+ *
924
+ * @category Auth
925
+ *
926
+ * @remarks
927
+ * - Requires either an email and password or a phone number and password.
928
+ *
929
+ * @example Sign in with email and password
930
+ * ```js
931
+ * const { data, error } = await supabase.auth.signInWithPassword({
932
+ * email: 'example@email.com',
933
+ * password: 'example-password',
934
+ * })
935
+ * ```
936
+ *
937
+ * @exampleResponse Sign in with email and password
938
+ * ```json
939
+ * {
940
+ * "data": {
941
+ * "user": {
942
+ * "id": "11111111-1111-1111-1111-111111111111",
943
+ * "aud": "authenticated",
944
+ * "role": "authenticated",
945
+ * "email": "example@email.com",
946
+ * "email_confirmed_at": "2024-01-01T00:00:00Z",
947
+ * "phone": "",
948
+ * "last_sign_in_at": "2024-01-01T00:00:00Z",
949
+ * "app_metadata": {
950
+ * "provider": "email",
951
+ * "providers": [
952
+ * "email"
953
+ * ]
954
+ * },
955
+ * "user_metadata": {},
956
+ * "identities": [
957
+ * {
958
+ * "identity_id": "22222222-2222-2222-2222-222222222222",
959
+ * "id": "11111111-1111-1111-1111-111111111111",
960
+ * "user_id": "11111111-1111-1111-1111-111111111111",
961
+ * "identity_data": {
962
+ * "email": "example@email.com",
963
+ * "email_verified": false,
964
+ * "phone_verified": false,
965
+ * "sub": "11111111-1111-1111-1111-111111111111"
966
+ * },
967
+ * "provider": "email",
968
+ * "last_sign_in_at": "2024-01-01T00:00:00Z",
969
+ * "created_at": "2024-01-01T00:00:00Z",
970
+ * "updated_at": "2024-01-01T00:00:00Z",
971
+ * "email": "example@email.com"
972
+ * }
973
+ * ],
974
+ * "created_at": "2024-01-01T00:00:00Z",
975
+ * "updated_at": "2024-01-01T00:00:00Z"
976
+ * },
977
+ * "session": {
978
+ * "access_token": "<ACCESS_TOKEN>",
979
+ * "token_type": "bearer",
980
+ * "expires_in": 3600,
981
+ * "expires_at": 1700000000,
982
+ * "refresh_token": "<REFRESH_TOKEN>",
983
+ * "user": {
984
+ * "id": "11111111-1111-1111-1111-111111111111",
985
+ * "aud": "authenticated",
986
+ * "role": "authenticated",
987
+ * "email": "example@email.com",
988
+ * "email_confirmed_at": "2024-01-01T00:00:00Z",
989
+ * "phone": "",
990
+ * "last_sign_in_at": "2024-01-01T00:00:00Z",
991
+ * "app_metadata": {
992
+ * "provider": "email",
993
+ * "providers": [
994
+ * "email"
995
+ * ]
996
+ * },
997
+ * "user_metadata": {},
998
+ * "identities": [
999
+ * {
1000
+ * "identity_id": "22222222-2222-2222-2222-222222222222",
1001
+ * "id": "11111111-1111-1111-1111-111111111111",
1002
+ * "user_id": "11111111-1111-1111-1111-111111111111",
1003
+ * "identity_data": {
1004
+ * "email": "example@email.com",
1005
+ * "email_verified": false,
1006
+ * "phone_verified": false,
1007
+ * "sub": "11111111-1111-1111-1111-111111111111"
1008
+ * },
1009
+ * "provider": "email",
1010
+ * "last_sign_in_at": "2024-01-01T00:00:00Z",
1011
+ * "created_at": "2024-01-01T00:00:00Z",
1012
+ * "updated_at": "2024-01-01T00:00:00Z",
1013
+ * "email": "example@email.com"
1014
+ * }
1015
+ * ],
1016
+ * "created_at": "2024-01-01T00:00:00Z",
1017
+ * "updated_at": "2024-01-01T00:00:00Z"
1018
+ * }
1019
+ * }
1020
+ * },
1021
+ * "error": null
1022
+ * }
1023
+ * ```
1024
+ *
1025
+ * @example Sign in with phone and password
1026
+ * ```js
1027
+ * const { data, error } = await supabase.auth.signInWithPassword({
1028
+ * phone: '+13334445555',
1029
+ * password: 'some-password',
1030
+ * })
1031
+ * ```
853
1032
  */
854
1033
  async signInWithPassword(
855
1034
  credentials: SignInWithPasswordCredentials
@@ -914,6 +1093,81 @@ export default class GoTrueClient {
914
1093
  /**
915
1094
  * Log in an existing user via a third-party provider.
916
1095
  * This method supports the PKCE flow.
1096
+ *
1097
+ * @category Auth
1098
+ *
1099
+ * @remarks
1100
+ * - This method is used for signing in using [Social Login (OAuth) providers](/docs/guides/auth#configure-third-party-providers).
1101
+ * - It works by redirecting your application to the provider's authorization screen, before bringing back the user to your app.
1102
+ *
1103
+ * @example Sign in using a third-party provider
1104
+ * ```js
1105
+ * const { data, error } = await supabase.auth.signInWithOAuth({
1106
+ * provider: 'github'
1107
+ * })
1108
+ * ```
1109
+ *
1110
+ * @exampleResponse Sign in using a third-party provider
1111
+ * ```json
1112
+ * {
1113
+ * data: {
1114
+ * provider: 'github',
1115
+ * url: <PROVIDER_URL_TO_REDIRECT_TO>
1116
+ * },
1117
+ * error: null
1118
+ * }
1119
+ * ```
1120
+ *
1121
+ * @exampleDescription Sign in using a third-party provider with redirect
1122
+ * - 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.
1123
+ * - See [redirect URLs and wildcards](/docs/guides/auth/redirect-urls#use-wildcards-in-redirect-urls) to add additional redirect URLs to your project.
1124
+ *
1125
+ * @example Sign in using a third-party provider with redirect
1126
+ * ```js
1127
+ * const { data, error } = await supabase.auth.signInWithOAuth({
1128
+ * provider: 'github',
1129
+ * options: {
1130
+ * redirectTo: 'https://example.com/welcome'
1131
+ * }
1132
+ * })
1133
+ * ```
1134
+ *
1135
+ * @exampleDescription Sign in with scopes and access provider tokens
1136
+ * 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.
1137
+ *
1138
+ * 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.
1139
+ *
1140
+ * 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.
1141
+ *
1142
+ * @example Sign in with scopes and access provider tokens
1143
+ * ```js
1144
+ * // Register this immediately after calling createClient!
1145
+ * // Because signInWithOAuth causes a redirect, you need to fetch the
1146
+ * // provider tokens from the callback.
1147
+ * supabase.auth.onAuthStateChange((event, session) => {
1148
+ * if (session && session.provider_token) {
1149
+ * window.localStorage.setItem('oauth_provider_token', session.provider_token)
1150
+ * }
1151
+ *
1152
+ * if (session && session.provider_refresh_token) {
1153
+ * window.localStorage.setItem('oauth_provider_refresh_token', session.provider_refresh_token)
1154
+ * }
1155
+ *
1156
+ * if (event === 'SIGNED_OUT') {
1157
+ * window.localStorage.removeItem('oauth_provider_token')
1158
+ * window.localStorage.removeItem('oauth_provider_refresh_token')
1159
+ * }
1160
+ * })
1161
+ *
1162
+ * // Call this on your Sign in with GitHub button to initiate OAuth
1163
+ * // with GitHub with the requested elevated scopes.
1164
+ * await supabase.auth.signInWithOAuth({
1165
+ * provider: 'github',
1166
+ * options: {
1167
+ * scopes: 'repo gist notifications'
1168
+ * }
1169
+ * })
1170
+ * ```
917
1171
  */
918
1172
  async signInWithOAuth(credentials: SignInWithOAuthCredentials): Promise<OAuthResponse> {
919
1173
  return await this._handleProviderSignIn(credentials.provider, {
@@ -926,73 +1180,321 @@ export default class GoTrueClient {
926
1180
 
927
1181
  /**
928
1182
  * Log in an existing user by exchanging an Auth Code issued during the PKCE flow.
929
- */
930
- async exchangeCodeForSession(authCode: string): Promise<AuthTokenResponse> {
931
- await this.initializePromise
932
-
933
- return this._acquireLock(this.lockAcquireTimeout, async () => {
934
- return this._exchangeCodeForSession(authCode)
935
- })
936
- }
937
-
938
- /**
939
- * Signs in a user by verifying a message signed by the user's private key.
940
- * Supports Ethereum (via Sign-In-With-Ethereum) & Solana (Sign-In-With-Solana) standards,
941
- * both of which derive from the EIP-4361 standard
942
- * With slight variation on Solana's side.
943
- * @reference https://eips.ethereum.org/EIPS/eip-4361
944
- */
945
- async signInWithWeb3(credentials: Web3Credentials): Promise<
946
- | {
947
- data: { session: Session; user: User }
948
- error: null
949
- }
950
- | { data: { session: null; user: null }; error: AuthError }
951
- > {
952
- const { chain } = credentials
953
-
954
- switch (chain) {
955
- case 'ethereum':
956
- return await this.signInWithEthereum(credentials)
957
- case 'solana':
958
- return await this.signInWithSolana(credentials)
959
- default:
960
- throw new Error(`@supabase/auth-js: Unsupported chain "${chain}"`)
961
- }
962
- }
963
-
964
- private async signInWithEthereum(
965
- credentials: EthereumWeb3Credentials
966
- ): Promise<
967
- | { data: { session: Session; user: User }; error: null }
968
- | { data: { session: null; user: null }; error: AuthError }
969
- > {
970
- // TODO: flatten type
971
- let message: string
972
- let signature: Hex
973
-
974
- if ('message' in credentials) {
975
- message = credentials.message
976
- signature = credentials.signature
977
- } else {
978
- const { chain, wallet, statement, options } = credentials
979
-
980
- let resolvedWallet: EthereumWallet
981
-
982
- if (!isBrowser()) {
983
- if (typeof wallet !== 'object' || !options?.url) {
984
- throw new Error(
985
- '@supabase/auth-js: Both wallet and url must be specified in non-browser environments.'
986
- )
987
- }
988
-
989
- resolvedWallet = wallet
990
- } else if (typeof wallet === 'object') {
991
- resolvedWallet = wallet
992
- } else {
993
- const windowAny = window as any
994
-
995
- if (
1183
+ *
1184
+ * @category Auth
1185
+ *
1186
+ * @remarks
1187
+ * - Used when `flowType` is set to `pkce` in client options.
1188
+ *
1189
+ * @example Exchange Auth Code
1190
+ * ```js
1191
+ * supabase.auth.exchangeCodeForSession('34e770dd-9ff9-416c-87fa-43b31d7ef225')
1192
+ * ```
1193
+ *
1194
+ * @exampleResponse Exchange Auth Code
1195
+ * ```json
1196
+ * {
1197
+ * "data": {
1198
+ * session: {
1199
+ * access_token: '<ACCESS_TOKEN>',
1200
+ * token_type: 'bearer',
1201
+ * expires_in: 3600,
1202
+ * expires_at: 1700000000,
1203
+ * refresh_token: '<REFRESH_TOKEN>',
1204
+ * user: {
1205
+ * id: '11111111-1111-1111-1111-111111111111',
1206
+ * aud: 'authenticated',
1207
+ * role: 'authenticated',
1208
+ * email: 'example@email.com'
1209
+ * email_confirmed_at: '2024-01-01T00:00:00Z',
1210
+ * phone: '',
1211
+ * confirmation_sent_at: '2024-01-01T00:00:00Z',
1212
+ * confirmed_at: '2024-01-01T00:00:00Z',
1213
+ * last_sign_in_at: '2024-01-01T00:00:00Z',
1214
+ * app_metadata: {
1215
+ * "provider": "email",
1216
+ * "providers": [
1217
+ * "email",
1218
+ * "<OTHER_PROVIDER>"
1219
+ * ]
1220
+ * },
1221
+ * user_metadata: {
1222
+ * email: 'email@email.com',
1223
+ * email_verified: true,
1224
+ * full_name: 'User Name',
1225
+ * iss: '<ISS>',
1226
+ * name: 'User Name',
1227
+ * phone_verified: false,
1228
+ * provider_id: '<PROVIDER_ID>',
1229
+ * sub: '<SUB>'
1230
+ * },
1231
+ * identities: [
1232
+ * {
1233
+ * "identity_id": "22222222-2222-2222-2222-222222222222",
1234
+ * "id": "11111111-1111-1111-1111-111111111111",
1235
+ * "user_id": "11111111-1111-1111-1111-111111111111",
1236
+ * "identity_data": {
1237
+ * "email": "example@email.com",
1238
+ * "email_verified": false,
1239
+ * "phone_verified": false,
1240
+ * "sub": "11111111-1111-1111-1111-111111111111"
1241
+ * },
1242
+ * "provider": "email",
1243
+ * "last_sign_in_at": "2024-01-01T00:00:00Z",
1244
+ * "created_at": "2024-01-01T00:00:00Z",
1245
+ * "updated_at": "2024-01-01T00:00:00Z",
1246
+ * "email": "email@example.com"
1247
+ * },
1248
+ * {
1249
+ * "identity_id": "33333333-3333-3333-3333-333333333333",
1250
+ * "id": "<ID>",
1251
+ * "user_id": "<USER_ID>",
1252
+ * "identity_data": {
1253
+ * "email": "example@email.com",
1254
+ * "email_verified": true,
1255
+ * "full_name": "User Name",
1256
+ * "iss": "<ISS>",
1257
+ * "name": "User Name",
1258
+ * "phone_verified": false,
1259
+ * "provider_id": "<PROVIDER_ID>",
1260
+ * "sub": "<SUB>"
1261
+ * },
1262
+ * "provider": "<PROVIDER>",
1263
+ * "last_sign_in_at": "2024-01-01T00:00:00Z",
1264
+ * "created_at": "2024-01-01T00:00:00Z",
1265
+ * "updated_at": "2024-01-01T00:00:00Z",
1266
+ * "email": "example@email.com"
1267
+ * }
1268
+ * ],
1269
+ * created_at: '2024-01-01T00:00:00Z',
1270
+ * updated_at: '2024-01-01T00:00:00Z',
1271
+ * is_anonymous: false
1272
+ * },
1273
+ * provider_token: '<PROVIDER_TOKEN>',
1274
+ * provider_refresh_token: '<PROVIDER_REFRESH_TOKEN>'
1275
+ * },
1276
+ * user: {
1277
+ * id: '11111111-1111-1111-1111-111111111111',
1278
+ * aud: 'authenticated',
1279
+ * role: 'authenticated',
1280
+ * email: 'example@email.com',
1281
+ * email_confirmed_at: '2024-01-01T00:00:00Z',
1282
+ * phone: '',
1283
+ * confirmation_sent_at: '2024-01-01T00:00:00Z',
1284
+ * confirmed_at: '2024-01-01T00:00:00Z',
1285
+ * last_sign_in_at: '2024-01-01T00:00:00Z',
1286
+ * app_metadata: {
1287
+ * provider: 'email',
1288
+ * providers: [
1289
+ * "email",
1290
+ * "<OTHER_PROVIDER>"
1291
+ * ]
1292
+ * },
1293
+ * user_metadata: {
1294
+ * email: 'email@email.com',
1295
+ * email_verified: true,
1296
+ * full_name: 'User Name',
1297
+ * iss: '<ISS>',
1298
+ * name: 'User Name',
1299
+ * phone_verified: false,
1300
+ * provider_id: '<PROVIDER_ID>',
1301
+ * sub: '<SUB>'
1302
+ * },
1303
+ * identities: [
1304
+ * {
1305
+ * "identity_id": "22222222-2222-2222-2222-222222222222",
1306
+ * "id": "11111111-1111-1111-1111-111111111111",
1307
+ * "user_id": "11111111-1111-1111-1111-111111111111",
1308
+ * "identity_data": {
1309
+ * "email": "example@email.com",
1310
+ * "email_verified": false,
1311
+ * "phone_verified": false,
1312
+ * "sub": "11111111-1111-1111-1111-111111111111"
1313
+ * },
1314
+ * "provider": "email",
1315
+ * "last_sign_in_at": "2024-01-01T00:00:00Z",
1316
+ * "created_at": "2024-01-01T00:00:00Z",
1317
+ * "updated_at": "2024-01-01T00:00:00Z",
1318
+ * "email": "email@example.com"
1319
+ * },
1320
+ * {
1321
+ * "identity_id": "33333333-3333-3333-3333-333333333333",
1322
+ * "id": "<ID>",
1323
+ * "user_id": "<USER_ID>",
1324
+ * "identity_data": {
1325
+ * "email": "example@email.com",
1326
+ * "email_verified": true,
1327
+ * "full_name": "User Name",
1328
+ * "iss": "<ISS>",
1329
+ * "name": "User Name",
1330
+ * "phone_verified": false,
1331
+ * "provider_id": "<PROVIDER_ID>",
1332
+ * "sub": "<SUB>"
1333
+ * },
1334
+ * "provider": "<PROVIDER>",
1335
+ * "last_sign_in_at": "2024-01-01T00:00:00Z",
1336
+ * "created_at": "2024-01-01T00:00:00Z",
1337
+ * "updated_at": "2024-01-01T00:00:00Z",
1338
+ * "email": "example@email.com"
1339
+ * }
1340
+ * ],
1341
+ * created_at: '2024-01-01T00:00:00Z',
1342
+ * updated_at: '2024-01-01T00:00:00Z',
1343
+ * is_anonymous: false
1344
+ * },
1345
+ * redirectType: null
1346
+ * },
1347
+ * "error": null
1348
+ * }
1349
+ * ```
1350
+ */
1351
+ async exchangeCodeForSession(authCode: string): Promise<AuthTokenResponse> {
1352
+ await this.initializePromise
1353
+
1354
+ return this._acquireLock(this.lockAcquireTimeout, async () => {
1355
+ return this._exchangeCodeForSession(authCode)
1356
+ })
1357
+ }
1358
+
1359
+ /**
1360
+ * Signs in a user by verifying a message signed by the user's private key.
1361
+ * Supports Ethereum (via Sign-In-With-Ethereum) & Solana (Sign-In-With-Solana) standards,
1362
+ * both of which derive from the EIP-4361 standard
1363
+ * With slight variation on Solana's side.
1364
+ * @reference https://eips.ethereum.org/EIPS/eip-4361
1365
+ *
1366
+ * @category Auth
1367
+ *
1368
+ * @remarks
1369
+ * - Uses a Web3 (Ethereum, Solana) wallet to sign a user in.
1370
+ * - Read up on the [potential for abuse](/docs/guides/auth/auth-web3#potential-for-abuse) before using it.
1371
+ *
1372
+ * @example Sign in with Solana or Ethereum (Window API)
1373
+ * ```js
1374
+ * // uses window.ethereum for the wallet
1375
+ * const { data, error } = await supabase.auth.signInWithWeb3({
1376
+ * chain: 'ethereum',
1377
+ * statement: 'I accept the Terms of Service at https://example.com/tos'
1378
+ * })
1379
+ *
1380
+ * // uses window.solana for the wallet
1381
+ * const { data, error } = await supabase.auth.signInWithWeb3({
1382
+ * chain: 'solana',
1383
+ * statement: 'I accept the Terms of Service at https://example.com/tos'
1384
+ * })
1385
+ * ```
1386
+ *
1387
+ * @example Sign in with Ethereum (Message and Signature)
1388
+ * ```js
1389
+ * const { data, error } = await supabase.auth.signInWithWeb3({
1390
+ * chain: 'ethereum',
1391
+ * message: '<sign in with ethereum message>',
1392
+ * signature: '<hex of the ethereum signature over the message>',
1393
+ * })
1394
+ * ```
1395
+ *
1396
+ * @example Sign in with Solana (Brave)
1397
+ * ```js
1398
+ * const { data, error } = await supabase.auth.signInWithWeb3({
1399
+ * chain: 'solana',
1400
+ * statement: 'I accept the Terms of Service at https://example.com/tos',
1401
+ * wallet: window.braveSolana
1402
+ * })
1403
+ * ```
1404
+ *
1405
+ * @example Sign in with Solana (Wallet Adapter)
1406
+ * ```jsx
1407
+ * function SignInButton() {
1408
+ * const wallet = useWallet()
1409
+ *
1410
+ * return (
1411
+ * <>
1412
+ * {wallet.connected ? (
1413
+ * <button
1414
+ * onClick={() => {
1415
+ * supabase.auth.signInWithWeb3({
1416
+ * chain: 'solana',
1417
+ * statement: 'I accept the Terms of Service at https://example.com/tos',
1418
+ * wallet,
1419
+ * })
1420
+ * }}
1421
+ * >
1422
+ * Sign in with Solana
1423
+ * </button>
1424
+ * ) : (
1425
+ * <WalletMultiButton />
1426
+ * )}
1427
+ * </>
1428
+ * )
1429
+ * }
1430
+ *
1431
+ * function App() {
1432
+ * const endpoint = clusterApiUrl('devnet')
1433
+ * const wallets = useMemo(() => [], [])
1434
+ *
1435
+ * return (
1436
+ * <ConnectionProvider endpoint={endpoint}>
1437
+ * <WalletProvider wallets={wallets}>
1438
+ * <WalletModalProvider>
1439
+ * <SignInButton />
1440
+ * </WalletModalProvider>
1441
+ * </WalletProvider>
1442
+ * </ConnectionProvider>
1443
+ * )
1444
+ * }
1445
+ * ```
1446
+ */
1447
+ async signInWithWeb3(credentials: Web3Credentials): Promise<
1448
+ | {
1449
+ data: { session: Session; user: User }
1450
+ error: null
1451
+ }
1452
+ | { data: { session: null; user: null }; error: AuthError }
1453
+ > {
1454
+ const { chain } = credentials
1455
+
1456
+ switch (chain) {
1457
+ case 'ethereum':
1458
+ return await this.signInWithEthereum(credentials)
1459
+ case 'solana':
1460
+ return await this.signInWithSolana(credentials)
1461
+ default:
1462
+ throw new Error(`@supabase/auth-js: Unsupported chain "${chain}"`)
1463
+ }
1464
+ }
1465
+
1466
+ private async signInWithEthereum(
1467
+ credentials: EthereumWeb3Credentials
1468
+ ): Promise<
1469
+ | { data: { session: Session; user: User }; error: null }
1470
+ | { data: { session: null; user: null }; error: AuthError }
1471
+ > {
1472
+ // TODO: flatten type
1473
+ let message: string
1474
+ let signature: Hex
1475
+
1476
+ if ('message' in credentials) {
1477
+ message = credentials.message
1478
+ signature = credentials.signature
1479
+ } else {
1480
+ const { chain, wallet, statement, options } = credentials
1481
+
1482
+ let resolvedWallet: EthereumWallet
1483
+
1484
+ if (!isBrowser()) {
1485
+ if (typeof wallet !== 'object' || !options?.url) {
1486
+ throw new Error(
1487
+ '@supabase/auth-js: Both wallet and url must be specified in non-browser environments.'
1488
+ )
1489
+ }
1490
+
1491
+ resolvedWallet = wallet
1492
+ } else if (typeof wallet === 'object') {
1493
+ resolvedWallet = wallet
1494
+ } else {
1495
+ const windowAny = window as any
1496
+
1497
+ if (
996
1498
  'ethereum' in windowAny &&
997
1499
  typeof windowAny.ethereum === 'object' &&
998
1500
  'request' in windowAny.ethereum &&
@@ -1343,6 +1845,77 @@ export default class GoTrueClient {
1343
1845
  /**
1344
1846
  * Allows signing in with an OIDC ID token. The authentication provider used
1345
1847
  * should be enabled and configured.
1848
+ *
1849
+ * @category Auth
1850
+ *
1851
+ * @remarks
1852
+ * - Use an ID token to sign in.
1853
+ * - 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.
1854
+ * - 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.
1855
+ *
1856
+ * @example Sign In using ID Token
1857
+ * ```js
1858
+ * const { data, error } = await supabase.auth.signInWithIdToken({
1859
+ * provider: 'google',
1860
+ * token: 'your-id-token'
1861
+ * })
1862
+ * ```
1863
+ *
1864
+ * @exampleResponse Sign In using ID Token
1865
+ * ```json
1866
+ * {
1867
+ * "data": {
1868
+ * "user": {
1869
+ * "id": "11111111-1111-1111-1111-111111111111",
1870
+ * "aud": "authenticated",
1871
+ * "role": "authenticated",
1872
+ * "last_sign_in_at": "2024-01-01T00:00:00Z",
1873
+ * "app_metadata": {
1874
+ * ...
1875
+ * },
1876
+ * "user_metadata": {
1877
+ * ...
1878
+ * },
1879
+ * "identities": [
1880
+ * {
1881
+ * "identity_id": "22222222-2222-2222-2222-222222222222",
1882
+ * "provider": "google",
1883
+ * }
1884
+ * ],
1885
+ * "created_at": "2024-01-01T00:00:00Z",
1886
+ * "updated_at": "2024-01-01T00:00:00Z",
1887
+ * },
1888
+ * "session": {
1889
+ * "access_token": "<ACCESS_TOKEN>",
1890
+ * "token_type": "bearer",
1891
+ * "expires_in": 3600,
1892
+ * "expires_at": 1700000000,
1893
+ * "refresh_token": "<REFRESH_TOKEN>",
1894
+ * "user": {
1895
+ * "id": "11111111-1111-1111-1111-111111111111",
1896
+ * "aud": "authenticated",
1897
+ * "role": "authenticated",
1898
+ * "last_sign_in_at": "2024-01-01T00:00:00Z",
1899
+ * "app_metadata": {
1900
+ * ...
1901
+ * },
1902
+ * "user_metadata": {
1903
+ * ...
1904
+ * },
1905
+ * "identities": [
1906
+ * {
1907
+ * "identity_id": "22222222-2222-2222-2222-222222222222",
1908
+ * "provider": "google",
1909
+ * }
1910
+ * ],
1911
+ * "created_at": "2024-01-01T00:00:00Z",
1912
+ * "updated_at": "2024-01-01T00:00:00Z",
1913
+ * }
1914
+ * }
1915
+ * },
1916
+ * "error": null
1917
+ * }
1918
+ * ```
1346
1919
  */
1347
1920
  async signInWithIdToken(credentials: SignInWithIdTokenCredentials): Promise<AuthTokenResponse> {
1348
1921
  try {
@@ -1396,6 +1969,66 @@ export default class GoTrueClient {
1396
1969
  * channel is not supported on other providers
1397
1970
  * at this time.
1398
1971
  * This method supports PKCE when an email is passed.
1972
+ *
1973
+ * @category Auth
1974
+ *
1975
+ * @remarks
1976
+ * - Requires either an email or phone number.
1977
+ * - This method is used for passwordless sign-ins where a OTP is sent to the user's email or phone number.
1978
+ * - 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`.
1979
+ * - If you're using an email, you can configure whether you want the user to receive a magiclink or a OTP.
1980
+ * - If you're using phone, you can configure whether you want the user to receive a OTP.
1981
+ * - The magic link's destination URL is determined by the [`SITE_URL`](/docs/guides/auth/redirect-urls#use-wildcards-in-redirect-urls).
1982
+ * - See [redirect URLs and wildcards](/docs/guides/auth/redirect-urls#use-wildcards-in-redirect-urls) to add additional redirect URLs to your project.
1983
+ * - 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 }}`.
1984
+ * - See our [Twilio Phone Auth Guide](/docs/guides/auth/phone-login?showSMSProvider=Twilio) for details about configuring WhatsApp sign in.
1985
+ *
1986
+ * @exampleDescription Sign in with email
1987
+ * 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.
1988
+ *
1989
+ * @example Sign in with email
1990
+ * ```js
1991
+ * const { data, error } = await supabase.auth.signInWithOtp({
1992
+ * email: 'example@email.com',
1993
+ * options: {
1994
+ * emailRedirectTo: 'https://example.com/welcome'
1995
+ * }
1996
+ * })
1997
+ * ```
1998
+ *
1999
+ * @exampleResponse Sign in with email
2000
+ * ```json
2001
+ * {
2002
+ * "data": {
2003
+ * "user": null,
2004
+ * "session": null
2005
+ * },
2006
+ * "error": null
2007
+ * }
2008
+ * ```
2009
+ *
2010
+ * @exampleDescription Sign in with SMS OTP
2011
+ * 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.
2012
+ *
2013
+ * @example Sign in with SMS OTP
2014
+ * ```js
2015
+ * const { data, error } = await supabase.auth.signInWithOtp({
2016
+ * phone: '+13334445555',
2017
+ * })
2018
+ * ```
2019
+ *
2020
+ * @exampleDescription Sign in with WhatsApp OTP
2021
+ * 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.
2022
+ *
2023
+ * @example Sign in with WhatsApp OTP
2024
+ * ```js
2025
+ * const { data, error } = await supabase.auth.signInWithOtp({
2026
+ * phone: '+13334445555',
2027
+ * options: {
2028
+ * channel:'whatsapp',
2029
+ * }
2030
+ * })
2031
+ * ```
1399
2032
  */
1400
2033
  async signInWithOtp(credentials: SignInWithPasswordlessCredentials): Promise<AuthOtpResponse> {
1401
2034
  try {
@@ -1453,9 +2086,143 @@ export default class GoTrueClient {
1453
2086
 
1454
2087
  /**
1455
2088
  * Log in a user given a User supplied OTP or TokenHash received through mobile or email.
1456
- */
1457
- async verifyOtp(params: VerifyOtpParams): Promise<AuthResponse> {
1458
- try {
2089
+ *
2090
+ * @category Auth
2091
+ *
2092
+ * @remarks
2093
+ * - The `verifyOtp` method takes in different verification types.
2094
+ * - If a phone number is used, the type can either be:
2095
+ * 1. `sms` – Used when verifying a one-time password (OTP) sent via SMS during sign-up or sign-in.
2096
+ * 2. `phone_change` – Used when verifying an OTP sent to a new phone number during a phone number update process.
2097
+ * - If an email address is used, the type can be one of the following (note: `signup` and `magiclink` types are deprecated):
2098
+ * 1. `email` – Used when verifying an OTP sent to the user's email during sign-up or sign-in.
2099
+ * 2. `recovery` – Used when verifying an OTP sent for account recovery, typically after a password reset request.
2100
+ * 3. `invite` – Used when verifying an OTP sent as part of an invitation to join a project or organization.
2101
+ * 4. `email_change` – Used when verifying an OTP sent to a new email address during an email update process.
2102
+ * - The verification type used should be determined based on the corresponding auth method called before `verifyOtp` to sign up / sign-in a user.
2103
+ * - 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.
2104
+ *
2105
+ * @example Verify Signup One-Time Password (OTP)
2106
+ * ```js
2107
+ * const { data, error } = await supabase.auth.verifyOtp({ email, token, type: 'email'})
2108
+ * ```
2109
+ *
2110
+ * @exampleResponse Verify Signup One-Time Password (OTP)
2111
+ * ```json
2112
+ * {
2113
+ * "data": {
2114
+ * "user": {
2115
+ * "id": "11111111-1111-1111-1111-111111111111",
2116
+ * "aud": "authenticated",
2117
+ * "role": "authenticated",
2118
+ * "email": "example@email.com",
2119
+ * "email_confirmed_at": "2024-01-01T00:00:00Z",
2120
+ * "phone": "",
2121
+ * "confirmed_at": "2024-01-01T00:00:00Z",
2122
+ * "recovery_sent_at": "2024-01-01T00:00:00Z",
2123
+ * "last_sign_in_at": "2024-01-01T00:00:00Z",
2124
+ * "app_metadata": {
2125
+ * "provider": "email",
2126
+ * "providers": [
2127
+ * "email"
2128
+ * ]
2129
+ * },
2130
+ * "user_metadata": {
2131
+ * "email": "example@email.com",
2132
+ * "email_verified": false,
2133
+ * "phone_verified": false,
2134
+ * "sub": "11111111-1111-1111-1111-111111111111"
2135
+ * },
2136
+ * "identities": [
2137
+ * {
2138
+ * "identity_id": "22222222-2222-2222-2222-222222222222",
2139
+ * "id": "11111111-1111-1111-1111-111111111111",
2140
+ * "user_id": "11111111-1111-1111-1111-111111111111",
2141
+ * "identity_data": {
2142
+ * "email": "example@email.com",
2143
+ * "email_verified": false,
2144
+ * "phone_verified": false,
2145
+ * "sub": "11111111-1111-1111-1111-111111111111"
2146
+ * },
2147
+ * "provider": "email",
2148
+ * "last_sign_in_at": "2024-01-01T00:00:00Z",
2149
+ * "created_at": "2024-01-01T00:00:00Z",
2150
+ * "updated_at": "2024-01-01T00:00:00Z",
2151
+ * "email": "example@email.com"
2152
+ * }
2153
+ * ],
2154
+ * "created_at": "2024-01-01T00:00:00Z",
2155
+ * "updated_at": "2024-01-01T00:00:00Z",
2156
+ * "is_anonymous": false
2157
+ * },
2158
+ * "session": {
2159
+ * "access_token": "<ACCESS_TOKEN>",
2160
+ * "token_type": "bearer",
2161
+ * "expires_in": 3600,
2162
+ * "expires_at": 1700000000,
2163
+ * "refresh_token": "<REFRESH_TOKEN>",
2164
+ * "user": {
2165
+ * "id": "11111111-1111-1111-1111-111111111111",
2166
+ * "aud": "authenticated",
2167
+ * "role": "authenticated",
2168
+ * "email": "example@email.com",
2169
+ * "email_confirmed_at": "2024-01-01T00:00:00Z",
2170
+ * "phone": "",
2171
+ * "confirmed_at": "2024-01-01T00:00:00Z",
2172
+ * "recovery_sent_at": "2024-01-01T00:00:00Z",
2173
+ * "last_sign_in_at": "2024-01-01T00:00:00Z",
2174
+ * "app_metadata": {
2175
+ * "provider": "email",
2176
+ * "providers": [
2177
+ * "email"
2178
+ * ]
2179
+ * },
2180
+ * "user_metadata": {
2181
+ * "email": "example@email.com",
2182
+ * "email_verified": false,
2183
+ * "phone_verified": false,
2184
+ * "sub": "11111111-1111-1111-1111-111111111111"
2185
+ * },
2186
+ * "identities": [
2187
+ * {
2188
+ * "identity_id": "22222222-2222-2222-2222-222222222222",
2189
+ * "id": "11111111-1111-1111-1111-111111111111",
2190
+ * "user_id": "11111111-1111-1111-1111-111111111111",
2191
+ * "identity_data": {
2192
+ * "email": "example@email.com",
2193
+ * "email_verified": false,
2194
+ * "phone_verified": false,
2195
+ * "sub": "11111111-1111-1111-1111-111111111111"
2196
+ * },
2197
+ * "provider": "email",
2198
+ * "last_sign_in_at": "2024-01-01T00:00:00Z",
2199
+ * "created_at": "2024-01-01T00:00:00Z",
2200
+ * "updated_at": "2024-01-01T00:00:00Z",
2201
+ * "email": "example@email.com"
2202
+ * }
2203
+ * ],
2204
+ * "created_at": "2024-01-01T00:00:00Z",
2205
+ * "updated_at": "2024-01-01T00:00:00Z",
2206
+ * "is_anonymous": false
2207
+ * }
2208
+ * }
2209
+ * },
2210
+ * "error": null
2211
+ * }
2212
+ * ```
2213
+ *
2214
+ * @example Verify SMS One-Time Password (OTP)
2215
+ * ```js
2216
+ * const { data, error } = await supabase.auth.verifyOtp({ phone, token, type: 'sms'})
2217
+ * ```
2218
+ *
2219
+ * @example Verify Email Auth (Token Hash)
2220
+ * ```js
2221
+ * const { data, error } = await supabase.auth.verifyOtp({ token_hash: tokenHash, type: 'email'})
2222
+ * ```
2223
+ */
2224
+ async verifyOtp(params: VerifyOtpParams): Promise<AuthResponse> {
2225
+ try {
1459
2226
  let redirectTo: string | undefined = undefined
1460
2227
  let captchaToken: string | undefined = undefined
1461
2228
  if ('options' in params) {
@@ -1514,6 +2281,45 @@ export default class GoTrueClient {
1514
2281
  *
1515
2282
  * If you have built an organization-specific login page, you can use the
1516
2283
  * organization's SSO Identity Provider UUID directly instead.
2284
+ *
2285
+ * @category Auth
2286
+ *
2287
+ * @remarks
2288
+ * - 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.
2289
+ * - If you've associated an email domain to the identity provider, you can use the `domain` property to start a sign-in flow.
2290
+ * - 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:
2291
+ * - Mapping specific user email addresses with an identity provider.
2292
+ * - 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.
2293
+ *
2294
+ * @example Sign in with email domain
2295
+ * ```js
2296
+ * // You can extract the user's email domain and use it to trigger the
2297
+ * // authentication flow with the correct identity provider.
2298
+ *
2299
+ * const { data, error } = await supabase.auth.signInWithSSO({
2300
+ * domain: 'company.com'
2301
+ * })
2302
+ *
2303
+ * if (data?.url) {
2304
+ * // redirect the user to the identity provider's authentication flow
2305
+ * window.location.href = data.url
2306
+ * }
2307
+ * ```
2308
+ *
2309
+ * @example Sign in with provider UUID
2310
+ * ```js
2311
+ * // Useful when you need to map a user's sign in request according
2312
+ * // to different rules that can't use email domains.
2313
+ *
2314
+ * const { data, error } = await supabase.auth.signInWithSSO({
2315
+ * providerId: '21648a9d-8d5a-4555-a9d1-d6375dc14e92'
2316
+ * })
2317
+ *
2318
+ * if (data?.url) {
2319
+ * // redirect the user to the identity provider's authentication flow
2320
+ * window.location.href = data.url
2321
+ * }
2322
+ * ```
1517
2323
  */
1518
2324
  async signInWithSSO(params: SignInWithSSO): Promise<SSOResponse> {
1519
2325
  try {
@@ -1560,6 +2366,23 @@ export default class GoTrueClient {
1560
2366
  /**
1561
2367
  * Sends a reauthentication OTP to the user's email or phone number.
1562
2368
  * Requires the user to be signed-in.
2369
+ *
2370
+ * @category Auth
2371
+ *
2372
+ * @remarks
2373
+ * - This method is used together with `updateUser()` when a user's password needs to be updated.
2374
+ * - 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).
2375
+ * - 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.
2376
+ * - 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.
2377
+ * - After receiving the OTP, include it as the `nonce` in your `updateUser()` call to finalize the password change.
2378
+ *
2379
+ * @exampleDescription Send reauthentication nonce
2380
+ * Sends a reauthentication nonce to the user's email or phone number.
2381
+ *
2382
+ * @example Send reauthentication nonce
2383
+ * ```js
2384
+ * const { error } = await supabase.auth.reauthenticate()
2385
+ * ```
1563
2386
  */
1564
2387
  async reauthenticate(): Promise<AuthResponse> {
1565
2388
  await this.initializePromise
@@ -1595,6 +2418,62 @@ export default class GoTrueClient {
1595
2418
 
1596
2419
  /**
1597
2420
  * Resends an existing signup confirmation email, email change email, SMS OTP or phone change OTP.
2421
+ *
2422
+ * @category Auth
2423
+ *
2424
+ * @remarks
2425
+ * - Resends a signup confirmation, email change or phone change email to the user.
2426
+ * - Passwordless sign-ins can be resent by calling the `signInWithOtp()` method again.
2427
+ * - Password recovery emails can be resent by calling the `resetPasswordForEmail()` method again.
2428
+ * - 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).
2429
+ * - You can specify a redirect url when you resend an email link using the `emailRedirectTo` option.
2430
+ *
2431
+ * @exampleDescription Resend an email signup confirmation
2432
+ * Resends the email signup confirmation to the user
2433
+ *
2434
+ * @example Resend an email signup confirmation
2435
+ * ```js
2436
+ * const { error } = await supabase.auth.resend({
2437
+ * type: 'signup',
2438
+ * email: 'email@example.com',
2439
+ * options: {
2440
+ * emailRedirectTo: 'https://example.com/welcome'
2441
+ * }
2442
+ * })
2443
+ * ```
2444
+ *
2445
+ * @exampleDescription Resend a phone signup confirmation
2446
+ * Resends the phone signup confirmation email to the user
2447
+ *
2448
+ * @example Resend a phone signup confirmation
2449
+ * ```js
2450
+ * const { error } = await supabase.auth.resend({
2451
+ * type: 'sms',
2452
+ * phone: '1234567890'
2453
+ * })
2454
+ * ```
2455
+ *
2456
+ * @exampleDescription Resend email change email
2457
+ * Resends the email change email to the user
2458
+ *
2459
+ * @example Resend email change email
2460
+ * ```js
2461
+ * const { error } = await supabase.auth.resend({
2462
+ * type: 'email_change',
2463
+ * email: 'email@example.com'
2464
+ * })
2465
+ * ```
2466
+ *
2467
+ * @exampleDescription Resend phone change OTP
2468
+ * Resends the phone change OTP to the user
2469
+ *
2470
+ * @example Resend phone change OTP
2471
+ * ```js
2472
+ * const { error } = await supabase.auth.resend({
2473
+ * type: 'phone_change',
2474
+ * phone: '1234567890'
2475
+ * })
2476
+ * ```
1598
2477
  */
1599
2478
  async resend(credentials: ResendParams): Promise<AuthOtpResponse> {
1600
2479
  try {
@@ -1647,6 +2526,80 @@ export default class GoTrueClient {
1647
2526
  * the values in it may not be authentic and therefore it's strongly advised
1648
2527
  * against using this method and its results in such circumstances. A warning
1649
2528
  * will be emitted if this is detected. Use {@link #getUser()} instead.
2529
+ *
2530
+ * @category Auth
2531
+ *
2532
+ * @remarks
2533
+ * - 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.
2534
+ * - Retrieves the current [user session](/docs/guides/auth/sessions) from the storage medium (local storage, cookies).
2535
+ * - The session contains an access token (signed JWT), a refresh token and the user object.
2536
+ * - If the session's access token is expired or is about to expire, this method will use the refresh token to refresh the session.
2537
+ * - 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.
2538
+ * - **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.
2539
+ * - 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.
2540
+ *
2541
+ * @example Get the session data
2542
+ * ```js
2543
+ * const { data, error } = await supabase.auth.getSession()
2544
+ * ```
2545
+ *
2546
+ * @exampleResponse Get the session data
2547
+ * ```json
2548
+ * {
2549
+ * "data": {
2550
+ * "session": {
2551
+ * "access_token": "<ACCESS_TOKEN>",
2552
+ * "token_type": "bearer",
2553
+ * "expires_in": 3600,
2554
+ * "expires_at": 1700000000,
2555
+ * "refresh_token": "<REFRESH_TOKEN>",
2556
+ * "user": {
2557
+ * "id": "11111111-1111-1111-1111-111111111111",
2558
+ * "aud": "authenticated",
2559
+ * "role": "authenticated",
2560
+ * "email": "example@email.com",
2561
+ * "email_confirmed_at": "2024-01-01T00:00:00Z",
2562
+ * "phone": "",
2563
+ * "last_sign_in_at": "2024-01-01T00:00:00Z",
2564
+ * "app_metadata": {
2565
+ * "provider": "email",
2566
+ * "providers": [
2567
+ * "email"
2568
+ * ]
2569
+ * },
2570
+ * "user_metadata": {
2571
+ * "email": "example@email.com",
2572
+ * "email_verified": false,
2573
+ * "phone_verified": false,
2574
+ * "sub": "11111111-1111-1111-1111-111111111111"
2575
+ * },
2576
+ * "identities": [
2577
+ * {
2578
+ * "identity_id": "22222222-2222-2222-2222-222222222222",
2579
+ * "id": "11111111-1111-1111-1111-111111111111",
2580
+ * "user_id": "11111111-1111-1111-1111-111111111111",
2581
+ * "identity_data": {
2582
+ * "email": "example@email.com",
2583
+ * "email_verified": false,
2584
+ * "phone_verified": false,
2585
+ * "sub": "11111111-1111-1111-1111-111111111111"
2586
+ * },
2587
+ * "provider": "email",
2588
+ * "last_sign_in_at": "2024-01-01T00:00:00Z",
2589
+ * "created_at": "2024-01-01T00:00:00Z",
2590
+ * "updated_at": "2024-01-01T00:00:00Z",
2591
+ * "email": "example@email.com"
2592
+ * }
2593
+ * ],
2594
+ * "created_at": "2024-01-01T00:00:00Z",
2595
+ * "updated_at": "2024-01-01T00:00:00Z",
2596
+ * "is_anonymous": false
2597
+ * }
2598
+ * }
2599
+ * },
2600
+ * "error": null
2601
+ * }
2602
+ * ```
1650
2603
  */
1651
2604
  async getSession() {
1652
2605
  await this.initializePromise
@@ -1889,6 +2842,75 @@ export default class GoTrueClient {
1889
2842
  * value is authentic and can be used to base authorization rules on.
1890
2843
  *
1891
2844
  * @param jwt Takes in an optional access token JWT. If no JWT is provided, the JWT from the current session is used.
2845
+ *
2846
+ * @category Auth
2847
+ *
2848
+ * @remarks
2849
+ * - This method fetches the user object from the database instead of local session.
2850
+ * - This method is useful for checking if the user is authorized because it validates the user's access token JWT on the server.
2851
+ * - 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.
2852
+ *
2853
+ * @example Get the logged in user with the current existing session
2854
+ * ```js
2855
+ * const { data: { user } } = await supabase.auth.getUser()
2856
+ * ```
2857
+ *
2858
+ * @exampleResponse Get the logged in user with the current existing session
2859
+ * ```json
2860
+ * {
2861
+ * "data": {
2862
+ * "user": {
2863
+ * "id": "11111111-1111-1111-1111-111111111111",
2864
+ * "aud": "authenticated",
2865
+ * "role": "authenticated",
2866
+ * "email": "example@email.com",
2867
+ * "email_confirmed_at": "2024-01-01T00:00:00Z",
2868
+ * "phone": "",
2869
+ * "confirmed_at": "2024-01-01T00:00:00Z",
2870
+ * "last_sign_in_at": "2024-01-01T00:00:00Z",
2871
+ * "app_metadata": {
2872
+ * "provider": "email",
2873
+ * "providers": [
2874
+ * "email"
2875
+ * ]
2876
+ * },
2877
+ * "user_metadata": {
2878
+ * "email": "example@email.com",
2879
+ * "email_verified": false,
2880
+ * "phone_verified": false,
2881
+ * "sub": "11111111-1111-1111-1111-111111111111"
2882
+ * },
2883
+ * "identities": [
2884
+ * {
2885
+ * "identity_id": "22222222-2222-2222-2222-222222222222",
2886
+ * "id": "11111111-1111-1111-1111-111111111111",
2887
+ * "user_id": "11111111-1111-1111-1111-111111111111",
2888
+ * "identity_data": {
2889
+ * "email": "example@email.com",
2890
+ * "email_verified": false,
2891
+ * "phone_verified": false,
2892
+ * "sub": "11111111-1111-1111-1111-111111111111"
2893
+ * },
2894
+ * "provider": "email",
2895
+ * "last_sign_in_at": "2024-01-01T00:00:00Z",
2896
+ * "created_at": "2024-01-01T00:00:00Z",
2897
+ * "updated_at": "2024-01-01T00:00:00Z",
2898
+ * "email": "example@email.com"
2899
+ * }
2900
+ * ],
2901
+ * "created_at": "2024-01-01T00:00:00Z",
2902
+ * "updated_at": "2024-01-01T00:00:00Z",
2903
+ * "is_anonymous": false
2904
+ * }
2905
+ * },
2906
+ * "error": null
2907
+ * }
2908
+ * ```
2909
+ *
2910
+ * @example Get the logged in user with a custom access token jwt
2911
+ * ```js
2912
+ * const { data: { user } } = await supabase.auth.getUser(jwt)
2913
+ * ```
1892
2914
  */
1893
2915
  async getUser(jwt?: string): Promise<UserResponse> {
1894
2916
  if (jwt) {
@@ -1954,6 +2976,117 @@ export default class GoTrueClient {
1954
2976
 
1955
2977
  /**
1956
2978
  * Updates user data for a logged in user.
2979
+ *
2980
+ * @category Auth
2981
+ *
2982
+ * @remarks
2983
+ * - In order to use the `updateUser()` method, the user needs to be signed in first.
2984
+ * - By default, email updates sends a confirmation link to both the user's current and new email.
2985
+ * 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).
2986
+ *
2987
+ * @exampleDescription Update the email for an authenticated user
2988
+ * 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).
2989
+ *
2990
+ * @example Update the email for an authenticated user
2991
+ * ```js
2992
+ * const { data, error } = await supabase.auth.updateUser({
2993
+ * email: 'new@email.com'
2994
+ * })
2995
+ * ```
2996
+ *
2997
+ * @exampleResponse Update the email for an authenticated user
2998
+ * ```json
2999
+ * {
3000
+ * "data": {
3001
+ * "user": {
3002
+ * "id": "11111111-1111-1111-1111-111111111111",
3003
+ * "aud": "authenticated",
3004
+ * "role": "authenticated",
3005
+ * "email": "example@email.com",
3006
+ * "email_confirmed_at": "2024-01-01T00:00:00Z",
3007
+ * "phone": "",
3008
+ * "confirmed_at": "2024-01-01T00:00:00Z",
3009
+ * "new_email": "new@email.com",
3010
+ * "email_change_sent_at": "2024-01-01T00:00:00Z",
3011
+ * "last_sign_in_at": "2024-01-01T00:00:00Z",
3012
+ * "app_metadata": {
3013
+ * "provider": "email",
3014
+ * "providers": [
3015
+ * "email"
3016
+ * ]
3017
+ * },
3018
+ * "user_metadata": {
3019
+ * "email": "example@email.com",
3020
+ * "email_verified": false,
3021
+ * "phone_verified": false,
3022
+ * "sub": "11111111-1111-1111-1111-111111111111"
3023
+ * },
3024
+ * "identities": [
3025
+ * {
3026
+ * "identity_id": "22222222-2222-2222-2222-222222222222",
3027
+ * "id": "11111111-1111-1111-1111-111111111111",
3028
+ * "user_id": "11111111-1111-1111-1111-111111111111",
3029
+ * "identity_data": {
3030
+ * "email": "example@email.com",
3031
+ * "email_verified": false,
3032
+ * "phone_verified": false,
3033
+ * "sub": "11111111-1111-1111-1111-111111111111"
3034
+ * },
3035
+ * "provider": "email",
3036
+ * "last_sign_in_at": "2024-01-01T00:00:00Z",
3037
+ * "created_at": "2024-01-01T00:00:00Z",
3038
+ * "updated_at": "2024-01-01T00:00:00Z",
3039
+ * "email": "example@email.com"
3040
+ * }
3041
+ * ],
3042
+ * "created_at": "2024-01-01T00:00:00Z",
3043
+ * "updated_at": "2024-01-01T00:00:00Z",
3044
+ * "is_anonymous": false
3045
+ * }
3046
+ * },
3047
+ * "error": null
3048
+ * }
3049
+ * ```
3050
+ *
3051
+ * @exampleDescription Update the phone number for an authenticated user
3052
+ * Sends a one-time password (OTP) to the new phone number.
3053
+ *
3054
+ * @example Update the phone number for an authenticated user
3055
+ * ```js
3056
+ * const { data, error } = await supabase.auth.updateUser({
3057
+ * phone: '123456789'
3058
+ * })
3059
+ * ```
3060
+ *
3061
+ * @example Update the password for an authenticated user
3062
+ * ```js
3063
+ * const { data, error } = await supabase.auth.updateUser({
3064
+ * password: 'new password'
3065
+ * })
3066
+ * ```
3067
+ *
3068
+ * @exampleDescription Update the user's metadata
3069
+ * Updates the user's custom metadata.
3070
+ *
3071
+ * **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`.
3072
+ *
3073
+ * @example Update the user's metadata
3074
+ * ```js
3075
+ * const { data, error } = await supabase.auth.updateUser({
3076
+ * data: { hello: 'world' }
3077
+ * })
3078
+ * ```
3079
+ *
3080
+ * @exampleDescription Update the user's password with a nonce
3081
+ * 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.
3082
+ *
3083
+ * @example Update the user's password with a nonce
3084
+ * ```js
3085
+ * const { data, error } = await supabase.auth.updateUser({
3086
+ * password: 'new password',
3087
+ * nonce: '123456'
3088
+ * })
3089
+ * ```
1957
3090
  */
1958
3091
  async updateUser(
1959
3092
  attributes: UserAttributes,
@@ -2026,6 +3159,125 @@ export default class GoTrueClient {
2026
3159
  * 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.
2027
3160
  * If the refresh token or access token in the current session is invalid, an error will be thrown.
2028
3161
  * @param currentSession The current session that minimally contains an access token and refresh token.
3162
+ *
3163
+ * @category Auth
3164
+ *
3165
+ * @remarks
3166
+ * - This method sets the session using an `access_token` and `refresh_token`.
3167
+ * - If successful, a `SIGNED_IN` event is emitted.
3168
+ *
3169
+ * @exampleDescription Set the session
3170
+ * Sets the session data from an access_token and refresh_token, then returns an auth response or error.
3171
+ *
3172
+ * @example Set the session
3173
+ * ```js
3174
+ * const { data, error } = await supabase.auth.setSession({
3175
+ * access_token,
3176
+ * refresh_token
3177
+ * })
3178
+ * ```
3179
+ *
3180
+ * @exampleResponse Set the session
3181
+ * ```json
3182
+ * {
3183
+ * "data": {
3184
+ * "user": {
3185
+ * "id": "11111111-1111-1111-1111-111111111111",
3186
+ * "aud": "authenticated",
3187
+ * "role": "authenticated",
3188
+ * "email": "example@email.com",
3189
+ * "email_confirmed_at": "2024-01-01T00:00:00Z",
3190
+ * "phone": "",
3191
+ * "confirmed_at": "2024-01-01T00:00:00Z",
3192
+ * "last_sign_in_at": "2024-01-01T00:00:00Z",
3193
+ * "app_metadata": {
3194
+ * "provider": "email",
3195
+ * "providers": [
3196
+ * "email"
3197
+ * ]
3198
+ * },
3199
+ * "user_metadata": {
3200
+ * "email": "example@email.com",
3201
+ * "email_verified": false,
3202
+ * "phone_verified": false,
3203
+ * "sub": "11111111-1111-1111-1111-111111111111"
3204
+ * },
3205
+ * "identities": [
3206
+ * {
3207
+ * "identity_id": "22222222-2222-2222-2222-222222222222",
3208
+ * "id": "11111111-1111-1111-1111-111111111111",
3209
+ * "user_id": "11111111-1111-1111-1111-111111111111",
3210
+ * "identity_data": {
3211
+ * "email": "example@email.com",
3212
+ * "email_verified": false,
3213
+ * "phone_verified": false,
3214
+ * "sub": "11111111-1111-1111-1111-111111111111"
3215
+ * },
3216
+ * "provider": "email",
3217
+ * "last_sign_in_at": "2024-01-01T00:00:00Z",
3218
+ * "created_at": "2024-01-01T00:00:00Z",
3219
+ * "updated_at": "2024-01-01T00:00:00Z",
3220
+ * "email": "example@email.com"
3221
+ * }
3222
+ * ],
3223
+ * "created_at": "2024-01-01T00:00:00Z",
3224
+ * "updated_at": "2024-01-01T00:00:00Z",
3225
+ * "is_anonymous": false
3226
+ * },
3227
+ * "session": {
3228
+ * "access_token": "<ACCESS_TOKEN>",
3229
+ * "refresh_token": "<REFRESH_TOKEN>",
3230
+ * "user": {
3231
+ * "id": "11111111-1111-1111-1111-111111111111",
3232
+ * "aud": "authenticated",
3233
+ * "role": "authenticated",
3234
+ * "email": "example@email.com",
3235
+ * "email_confirmed_at": "2024-01-01T00:00:00Z",
3236
+ * "phone": "",
3237
+ * "confirmed_at": "2024-01-01T00:00:00Z",
3238
+ * "last_sign_in_at": "11111111-1111-1111-1111-111111111111",
3239
+ * "app_metadata": {
3240
+ * "provider": "email",
3241
+ * "providers": [
3242
+ * "email"
3243
+ * ]
3244
+ * },
3245
+ * "user_metadata": {
3246
+ * "email": "example@email.com",
3247
+ * "email_verified": false,
3248
+ * "phone_verified": false,
3249
+ * "sub": "11111111-1111-1111-1111-111111111111"
3250
+ * },
3251
+ * "identities": [
3252
+ * {
3253
+ * "identity_id": "2024-01-01T00:00:00Z",
3254
+ * "id": "11111111-1111-1111-1111-111111111111",
3255
+ * "user_id": "11111111-1111-1111-1111-111111111111",
3256
+ * "identity_data": {
3257
+ * "email": "example@email.com",
3258
+ * "email_verified": false,
3259
+ * "phone_verified": false,
3260
+ * "sub": "11111111-1111-1111-1111-111111111111"
3261
+ * },
3262
+ * "provider": "email",
3263
+ * "last_sign_in_at": "2024-01-01T00:00:00Z",
3264
+ * "created_at": "2024-01-01T00:00:00Z",
3265
+ * "updated_at": "2024-01-01T00:00:00Z",
3266
+ * "email": "example@email.com"
3267
+ * }
3268
+ * ],
3269
+ * "created_at": "2024-01-01T00:00:00Z",
3270
+ * "updated_at": "2024-01-01T00:00:00Z",
3271
+ * "is_anonymous": false
3272
+ * },
3273
+ * "token_type": "bearer",
3274
+ * "expires_in": 3500,
3275
+ * "expires_at": 1700000000
3276
+ * }
3277
+ * },
3278
+ * "error": null
3279
+ * }
3280
+ * ```
2029
3281
  */
2030
3282
  async setSession(currentSession: {
2031
3283
  access_token: string
@@ -2101,6 +3353,125 @@ export default class GoTrueClient {
2101
3353
  * Takes in an optional current session. If not passed in, then refreshSession() will attempt to retrieve it from getSession().
2102
3354
  * If the current session's refresh token is invalid, an error will be thrown.
2103
3355
  * @param currentSession The current session. If passed in, it must contain a refresh token.
3356
+ *
3357
+ * @category Auth
3358
+ *
3359
+ * @remarks
3360
+ * - This method will refresh and return a new session whether the current one is expired or not.
3361
+ *
3362
+ * @example Refresh session using the current session
3363
+ * ```js
3364
+ * const { data, error } = await supabase.auth.refreshSession()
3365
+ * const { session, user } = data
3366
+ * ```
3367
+ *
3368
+ * @exampleResponse Refresh session using the current session
3369
+ * ```json
3370
+ * {
3371
+ * "data": {
3372
+ * "user": {
3373
+ * "id": "11111111-1111-1111-1111-111111111111",
3374
+ * "aud": "authenticated",
3375
+ * "role": "authenticated",
3376
+ * "email": "example@email.com",
3377
+ * "email_confirmed_at": "2024-01-01T00:00:00Z",
3378
+ * "phone": "",
3379
+ * "confirmed_at": "2024-01-01T00:00:00Z",
3380
+ * "last_sign_in_at": "2024-01-01T00:00:00Z",
3381
+ * "app_metadata": {
3382
+ * "provider": "email",
3383
+ * "providers": [
3384
+ * "email"
3385
+ * ]
3386
+ * },
3387
+ * "user_metadata": {
3388
+ * "email": "example@email.com",
3389
+ * "email_verified": false,
3390
+ * "phone_verified": false,
3391
+ * "sub": "11111111-1111-1111-1111-111111111111"
3392
+ * },
3393
+ * "identities": [
3394
+ * {
3395
+ * "identity_id": "22222222-2222-2222-2222-222222222222",
3396
+ * "id": "11111111-1111-1111-1111-111111111111",
3397
+ * "user_id": "11111111-1111-1111-1111-111111111111",
3398
+ * "identity_data": {
3399
+ * "email": "example@email.com",
3400
+ * "email_verified": false,
3401
+ * "phone_verified": false,
3402
+ * "sub": "11111111-1111-1111-1111-111111111111"
3403
+ * },
3404
+ * "provider": "email",
3405
+ * "last_sign_in_at": "2024-01-01T00:00:00Z",
3406
+ * "created_at": "2024-01-01T00:00:00Z",
3407
+ * "updated_at": "2024-01-01T00:00:00Z",
3408
+ * "email": "example@email.com"
3409
+ * }
3410
+ * ],
3411
+ * "created_at": "2024-01-01T00:00:00Z",
3412
+ * "updated_at": "2024-01-01T00:00:00Z",
3413
+ * "is_anonymous": false
3414
+ * },
3415
+ * "session": {
3416
+ * "access_token": "<ACCESS_TOKEN>",
3417
+ * "token_type": "bearer",
3418
+ * "expires_in": 3600,
3419
+ * "expires_at": 1700000000,
3420
+ * "refresh_token": "<REFRESH_TOKEN>",
3421
+ * "user": {
3422
+ * "id": "11111111-1111-1111-1111-111111111111",
3423
+ * "aud": "authenticated",
3424
+ * "role": "authenticated",
3425
+ * "email": "example@email.com",
3426
+ * "email_confirmed_at": "2024-01-01T00:00:00Z",
3427
+ * "phone": "",
3428
+ * "confirmed_at": "2024-01-01T00:00:00Z",
3429
+ * "last_sign_in_at": "2024-01-01T00:00:00Z",
3430
+ * "app_metadata": {
3431
+ * "provider": "email",
3432
+ * "providers": [
3433
+ * "email"
3434
+ * ]
3435
+ * },
3436
+ * "user_metadata": {
3437
+ * "email": "example@email.com",
3438
+ * "email_verified": false,
3439
+ * "phone_verified": false,
3440
+ * "sub": "11111111-1111-1111-1111-111111111111"
3441
+ * },
3442
+ * "identities": [
3443
+ * {
3444
+ * "identity_id": "22222222-2222-2222-2222-222222222222",
3445
+ * "id": "11111111-1111-1111-1111-111111111111",
3446
+ * "user_id": "11111111-1111-1111-1111-111111111111",
3447
+ * "identity_data": {
3448
+ * "email": "example@email.com",
3449
+ * "email_verified": false,
3450
+ * "phone_verified": false,
3451
+ * "sub": "11111111-1111-1111-1111-111111111111"
3452
+ * },
3453
+ * "provider": "email",
3454
+ * "last_sign_in_at": "2024-01-01T00:00:00Z",
3455
+ * "created_at": "2024-01-01T00:00:00Z",
3456
+ * "updated_at": "2024-01-01T00:00:00Z",
3457
+ * "email": "example@email.com"
3458
+ * }
3459
+ * ],
3460
+ * "created_at": "2024-01-01T00:00:00Z",
3461
+ * "updated_at": "2024-01-01T00:00:00Z",
3462
+ * "is_anonymous": false
3463
+ * }
3464
+ * }
3465
+ * },
3466
+ * "error": null
3467
+ * }
3468
+ * ```
3469
+ *
3470
+ * @example Refresh session using a refresh token
3471
+ * ```js
3472
+ * const { data, error } = await supabase.auth.refreshSession({ refresh_token })
3473
+ * const { session, user } = data
3474
+ * ```
2104
3475
  */
2105
3476
  async refreshSession(currentSession?: { refresh_token: string }): Promise<AuthResponse> {
2106
3477
  await this.initializePromise
@@ -2315,6 +3686,28 @@ export default class GoTrueClient {
2315
3686
  * 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.
2316
3687
  *
2317
3688
  * If using `others` scope, no `SIGNED_OUT` event is fired!
3689
+ *
3690
+ * @category Auth
3691
+ *
3692
+ * @remarks
3693
+ * - In order to use the `signOut()` method, the user needs to be signed in first.
3694
+ * - 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.
3695
+ * - 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.
3696
+ *
3697
+ * @example Sign out (all sessions)
3698
+ * ```js
3699
+ * const { error } = await supabase.auth.signOut()
3700
+ * ```
3701
+ *
3702
+ * @example Sign out (current session)
3703
+ * ```js
3704
+ * const { error } = await supabase.auth.signOut({ scope: 'local' })
3705
+ * ```
3706
+ *
3707
+ * @example Sign out (other sessions)
3708
+ * ```js
3709
+ * const { error } = await supabase.auth.signOut({ scope: 'others' })
3710
+ * ```
2318
3711
  */
2319
3712
  async signOut(options: SignOut = { scope: 'global' }): Promise<{ error: AuthError | null }> {
2320
3713
  await this.initializePromise
@@ -2383,6 +3776,193 @@ export default class GoTrueClient {
2383
3776
  data: { subscription: Subscription }
2384
3777
  }
2385
3778
 
3779
+ /** *
3780
+ * @category Auth
3781
+ *
3782
+ * @remarks
3783
+ * - Subscribes to important events occurring on the user's session.
3784
+ * - Use on the frontend/client. It is less useful on the server.
3785
+ * - Events are emitted across tabs to keep your application's UI up-to-date. Some events can fire very frequently, based on the number of tabs open. Use a quick and efficient callback function, and defer or debounce as many operations as you can to be performed outside of the callback.
3786
+ * - **Important:** A callback can be an `async` function and it runs synchronously during the processing of the changes causing the event. You can easily create a dead-lock by using `await` on a call to another method of the Supabase library.
3787
+ * - Avoid using `async` functions as callbacks.
3788
+ * - Limit the number of `await` calls in `async` callbacks.
3789
+ * - Do not use other Supabase functions in the callback function. If you must, dispatch the functions once the callback has finished executing. Use this as a quick way to achieve this:
3790
+ * ```js
3791
+ * supabase.auth.onAuthStateChange((event, session) => {
3792
+ * setTimeout(async () => {
3793
+ * // await on other Supabase function here
3794
+ * // this runs right after the callback has finished
3795
+ * }, 0)
3796
+ * })
3797
+ * ```
3798
+ * - Emitted events:
3799
+ * - `INITIAL_SESSION`
3800
+ * - Emitted right after the Supabase client is constructed and the initial session from storage is loaded.
3801
+ * - `SIGNED_IN`
3802
+ * - Emitted each time a user session is confirmed or re-established, including on user sign in and when refocusing a tab.
3803
+ * - Avoid making assumptions as to when this event is fired, this may occur even when the user is already signed in. Instead, check the user object attached to the event to see if a new user has signed in and update your application's UI.
3804
+ * - This event can fire very frequently depending on the number of tabs open in your application.
3805
+ * - `SIGNED_OUT`
3806
+ * - Emitted when the user signs out. This can be after:
3807
+ * - A call to `supabase.auth.signOut()`.
3808
+ * - After the user's session has expired for any reason:
3809
+ * - User has signed out on another device.
3810
+ * - The session has reached its timebox limit or inactivity timeout.
3811
+ * - User has signed in on another device with single session per user enabled.
3812
+ * - Check the [User Sessions](/docs/guides/auth/sessions) docs for more information.
3813
+ * - Use this to clean up any local storage your application has associated with the user.
3814
+ * - `TOKEN_REFRESHED`
3815
+ * - Emitted each time a new access and refresh token are fetched for the signed in user.
3816
+ * - It's best practice and highly recommended to extract the access token (JWT) and store it in memory for further use in your application.
3817
+ * - Avoid frequent calls to `supabase.auth.getSession()` for the same purpose.
3818
+ * - There is a background process that keeps track of when the session should be refreshed so you will always receive valid tokens by listening to this event.
3819
+ * - The frequency of this event is related to the JWT expiry limit configured on your project.
3820
+ * - `USER_UPDATED`
3821
+ * - Emitted each time the `supabase.auth.updateUser()` method finishes successfully. Listen to it to update your application's UI based on new profile information.
3822
+ * - `PASSWORD_RECOVERY`
3823
+ * - Emitted instead of the `SIGNED_IN` event when the user lands on a page that includes a password recovery link in the URL.
3824
+ * - Use it to show a UI to the user where they can [reset their password](/docs/guides/auth/passwords#resetting-a-users-password-forgot-password).
3825
+ *
3826
+ * @example Listen to auth changes
3827
+ * ```js
3828
+ * const { data } = supabase.auth.onAuthStateChange((event, session) => {
3829
+ * console.log(event, session)
3830
+ *
3831
+ * if (event === 'INITIAL_SESSION') {
3832
+ * // handle initial session
3833
+ * } else if (event === 'SIGNED_IN') {
3834
+ * // handle sign in event
3835
+ * } else if (event === 'SIGNED_OUT') {
3836
+ * // handle sign out event
3837
+ * } else if (event === 'PASSWORD_RECOVERY') {
3838
+ * // handle password recovery event
3839
+ * } else if (event === 'TOKEN_REFRESHED') {
3840
+ * // handle token refreshed event
3841
+ * } else if (event === 'USER_UPDATED') {
3842
+ * // handle user updated event
3843
+ * }
3844
+ * })
3845
+ *
3846
+ * // call unsubscribe to remove the callback
3847
+ * data.subscription.unsubscribe()
3848
+ * ```
3849
+ *
3850
+ * @exampleDescription Listen to sign out
3851
+ * Make sure you clear out any local data, such as local and session storage, after the client library has detected the user's sign out.
3852
+ *
3853
+ * @example Listen to sign out
3854
+ * ```js
3855
+ * supabase.auth.onAuthStateChange((event, session) => {
3856
+ * if (event === 'SIGNED_OUT') {
3857
+ * console.log('SIGNED_OUT', session)
3858
+ *
3859
+ * // clear local and session storage
3860
+ * [
3861
+ * window.localStorage,
3862
+ * window.sessionStorage,
3863
+ * ].forEach((storage) => {
3864
+ * Object.entries(storage)
3865
+ * .forEach(([key]) => {
3866
+ * storage.removeItem(key)
3867
+ * })
3868
+ * })
3869
+ * }
3870
+ * })
3871
+ * ```
3872
+ *
3873
+ * @exampleDescription Store OAuth provider tokens on sign in
3874
+ * When using [OAuth (Social Login)](/docs/guides/auth/social-login) you sometimes wish to get access to the provider's access token and refresh token, in order to call provider APIs in the name of the user.
3875
+ *
3876
+ * For example, if you are using [Sign in with Google](/docs/guides/auth/social-login/auth-google) you may want to use the provider token to call Google APIs on behalf of the user. Supabase Auth does not keep track of the provider access and refresh token, but does return them for you once, immediately after sign in. You can use the `onAuthStateChange` method to listen for the presence of the provider tokens and store them in local storage. You can further send them to your server's APIs for use on the backend.
3877
+ *
3878
+ * 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.
3879
+ *
3880
+ * @example Store OAuth provider tokens on sign in
3881
+ * ```js
3882
+ * // Register this immediately after calling createClient!
3883
+ * // Because signInWithOAuth causes a redirect, you need to fetch the
3884
+ * // provider tokens from the callback.
3885
+ * supabase.auth.onAuthStateChange((event, session) => {
3886
+ * if (session && session.provider_token) {
3887
+ * window.localStorage.setItem('oauth_provider_token', session.provider_token)
3888
+ * }
3889
+ *
3890
+ * if (session && session.provider_refresh_token) {
3891
+ * window.localStorage.setItem('oauth_provider_refresh_token', session.provider_refresh_token)
3892
+ * }
3893
+ *
3894
+ * if (event === 'SIGNED_OUT') {
3895
+ * window.localStorage.removeItem('oauth_provider_token')
3896
+ * window.localStorage.removeItem('oauth_provider_refresh_token')
3897
+ * }
3898
+ * })
3899
+ * ```
3900
+ *
3901
+ * @exampleDescription Use React Context for the User's session
3902
+ * Instead of relying on `supabase.auth.getSession()` within your React components, you can use a [React Context](https://react.dev/reference/react/createContext) to store the latest session information from the `onAuthStateChange` callback and access it that way.
3903
+ *
3904
+ * @example Use React Context for the User's session
3905
+ * ```js
3906
+ * const SessionContext = React.createContext(null)
3907
+ *
3908
+ * function main() {
3909
+ * const [session, setSession] = React.useState(null)
3910
+ *
3911
+ * React.useEffect(() => {
3912
+ * const {data: { subscription }} = supabase.auth.onAuthStateChange(
3913
+ * (event, session) => {
3914
+ * if (event === 'SIGNED_OUT') {
3915
+ * setSession(null)
3916
+ * } else if (session) {
3917
+ * setSession(session)
3918
+ * }
3919
+ * })
3920
+ *
3921
+ * return () => {
3922
+ * subscription.unsubscribe()
3923
+ * }
3924
+ * }, [])
3925
+ *
3926
+ * return (
3927
+ * <SessionContext.Provider value={session}>
3928
+ * <App />
3929
+ * </SessionContext.Provider>
3930
+ * )
3931
+ * }
3932
+ * ```
3933
+ *
3934
+ * @example Listen to password recovery events
3935
+ * ```js
3936
+ * supabase.auth.onAuthStateChange((event, session) => {
3937
+ * if (event === 'PASSWORD_RECOVERY') {
3938
+ * console.log('PASSWORD_RECOVERY', session)
3939
+ * // show screen to update user's password
3940
+ * showPasswordResetScreen(true)
3941
+ * }
3942
+ * })
3943
+ * ```
3944
+ *
3945
+ * @example Listen to sign in
3946
+ * ```js
3947
+ * supabase.auth.onAuthStateChange((event, session) => {
3948
+ * if (event === 'SIGNED_IN') console.log('SIGNED_IN', session)
3949
+ * })
3950
+ * ```
3951
+ *
3952
+ * @example Listen to token refresh
3953
+ * ```js
3954
+ * supabase.auth.onAuthStateChange((event, session) => {
3955
+ * if (event === 'TOKEN_REFRESHED') console.log('TOKEN_REFRESHED', session)
3956
+ * })
3957
+ * ```
3958
+ *
3959
+ * @example Listen to user updates
3960
+ * ```js
3961
+ * supabase.auth.onAuthStateChange((event, session) => {
3962
+ * if (event === 'USER_UPDATED') console.log('USER_UPDATED', session)
3963
+ * })
3964
+ * ```
3965
+ */
2386
3966
  onAuthStateChange(
2387
3967
  callback: (event: AuthChangeEvent, session: Session | null) => void | Promise<void>
2388
3968
  ): {
@@ -2438,6 +4018,66 @@ export default class GoTrueClient {
2438
4018
  * @param email The email address of the user.
2439
4019
  * @param options.redirectTo The URL to send the user to after they click the password reset link.
2440
4020
  * @param options.captchaToken Verification token received when the user completes the captcha on the site.
4021
+ *
4022
+ * @category Auth
4023
+ *
4024
+ * @remarks
4025
+ * - 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.
4026
+ * - The `resetPasswordForEmail()` only sends a password reset link to the user's email.
4027
+ * To update the user's password, see [`updateUser()`](/docs/reference/javascript/auth-updateuser).
4028
+ * - A `PASSWORD_RECOVERY` event will be emitted when the password recovery link is clicked.
4029
+ * You can use [`onAuthStateChange()`](/docs/reference/javascript/auth-onauthstatechange) to listen and invoke a callback function on these events.
4030
+ * - When the user clicks the reset link in the email they are redirected back to your application.
4031
+ * You can configure the URL that the user is redirected to with the `redirectTo` parameter.
4032
+ * See [redirect URLs and wildcards](/docs/guides/auth/redirect-urls#use-wildcards-in-redirect-urls) to add additional redirect URLs to your project.
4033
+ * - After the user has been redirected successfully, prompt them for a new password and call `updateUser()`:
4034
+ * ```js
4035
+ * const { data, error } = await supabase.auth.updateUser({
4036
+ * password: new_password
4037
+ * })
4038
+ * ```
4039
+ *
4040
+ * @example Reset password
4041
+ * ```js
4042
+ * const { data, error } = await supabase.auth.resetPasswordForEmail(email, {
4043
+ * redirectTo: 'https://example.com/update-password',
4044
+ * })
4045
+ * ```
4046
+ *
4047
+ * @exampleResponse Reset password
4048
+ * ```json
4049
+ * {
4050
+ * data: {}
4051
+ * error: null
4052
+ * }
4053
+ * ```
4054
+ *
4055
+ * @example Reset password (React)
4056
+ * ```js
4057
+ * /**
4058
+ * * Step 1: Send the user an email to get a password reset token.
4059
+ * * This email contains a link which sends the user back to your application.
4060
+ * *\/
4061
+ * const { data, error } = await supabase.auth
4062
+ * .resetPasswordForEmail('user@email.com')
4063
+ *
4064
+ * /**
4065
+ * * Step 2: Once the user is redirected back to your application,
4066
+ * * ask the user to reset their password.
4067
+ * *\/
4068
+ * useEffect(() => {
4069
+ * supabase.auth.onAuthStateChange(async (event, session) => {
4070
+ * if (event == "PASSWORD_RECOVERY") {
4071
+ * const newPassword = prompt("What would you like your new password to be?");
4072
+ * const { data, error } = await supabase.auth
4073
+ * .updateUser({ password: newPassword })
4074
+ *
4075
+ * if (data) alert("Password updated successfully!")
4076
+ * if (error) alert("There was an error updating your password.")
4077
+ * }
4078
+ * })
4079
+ * }, [])
4080
+ * ```
2441
4081
  */
2442
4082
  async resetPasswordForEmail(
2443
4083
  email: string,
@@ -2485,6 +4125,43 @@ export default class GoTrueClient {
2485
4125
 
2486
4126
  /**
2487
4127
  * Gets all the identities linked to a user.
4128
+ *
4129
+ * @category Auth
4130
+ *
4131
+ * @remarks
4132
+ * - The user needs to be signed in to call `getUserIdentities()`.
4133
+ *
4134
+ * @example Returns a list of identities linked to the user
4135
+ * ```js
4136
+ * const { data, error } = await supabase.auth.getUserIdentities()
4137
+ * ```
4138
+ *
4139
+ * @exampleResponse Returns a list of identities linked to the user
4140
+ * ```json
4141
+ * {
4142
+ * "data": {
4143
+ * "identities": [
4144
+ * {
4145
+ * "identity_id": "22222222-2222-2222-2222-222222222222",
4146
+ * "id": "2024-01-01T00:00:00Z",
4147
+ * "user_id": "2024-01-01T00:00:00Z",
4148
+ * "identity_data": {
4149
+ * "email": "example@email.com",
4150
+ * "email_verified": false,
4151
+ * "phone_verified": false,
4152
+ * "sub": "11111111-1111-1111-1111-111111111111"
4153
+ * },
4154
+ * "provider": "email",
4155
+ * "last_sign_in_at": "2024-01-01T00:00:00Z",
4156
+ * "created_at": "2024-01-01T00:00:00Z",
4157
+ * "updated_at": "2024-01-01T00:00:00Z",
4158
+ * "email": "example@email.com"
4159
+ * }
4160
+ * ]
4161
+ * },
4162
+ * "error": null
4163
+ * }
4164
+ * ```
2488
4165
  */
2489
4166
  async getUserIdentities(): Promise<
2490
4167
  | {
@@ -2518,6 +4195,33 @@ export default class GoTrueClient {
2518
4195
  */
2519
4196
  async linkIdentity(credentials: SignInWithIdTokenCredentials): Promise<AuthTokenResponse>
2520
4197
 
4198
+ /** *
4199
+ * @category Auth
4200
+ *
4201
+ * @remarks
4202
+ * - The **Enable Manual Linking** option must be enabled from your [project's authentication settings](/dashboard/project/_/auth/providers).
4203
+ * - The user needs to be signed in to call `linkIdentity()`.
4204
+ * - If the candidate identity is already linked to the existing user or another user, `linkIdentity()` will fail.
4205
+ * - If `linkIdentity` is run in the browser, the user is automatically redirected to the returned URL. On the server, you should handle the redirect.
4206
+ *
4207
+ * @example Link an identity to a user
4208
+ * ```js
4209
+ * const { data, error } = await supabase.auth.linkIdentity({
4210
+ * provider: 'github'
4211
+ * })
4212
+ * ```
4213
+ *
4214
+ * @exampleResponse Link an identity to a user
4215
+ * ```json
4216
+ * {
4217
+ * data: {
4218
+ * provider: 'github',
4219
+ * url: <PROVIDER_URL_TO_REDIRECT_TO>
4220
+ * },
4221
+ * error: null
4222
+ * }
4223
+ * ```
4224
+ */
2521
4225
  async linkIdentity(credentials: any): Promise<any> {
2522
4226
  if ('token' in credentials) {
2523
4227
  return this.linkIdentityIdToken(credentials)
@@ -2615,6 +4319,28 @@ export default class GoTrueClient {
2615
4319
 
2616
4320
  /**
2617
4321
  * 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.
4322
+ *
4323
+ * @category Auth
4324
+ *
4325
+ * @remarks
4326
+ * - The **Enable Manual Linking** option must be enabled from your [project's authentication settings](/dashboard/project/_/auth/providers).
4327
+ * - The user needs to be signed in to call `unlinkIdentity()`.
4328
+ * - The user must have at least 2 identities in order to unlink an identity.
4329
+ * - The identity to be unlinked must belong to the user.
4330
+ *
4331
+ * @example Unlink an identity
4332
+ * ```js
4333
+ * // retrieve all identities linked to a user
4334
+ * const identities = await supabase.auth.getUserIdentities()
4335
+ *
4336
+ * // find the google identity
4337
+ * const googleIdentity = identities.find(
4338
+ * identity => identity.provider === 'google'
4339
+ * )
4340
+ *
4341
+ * // unlink the google identity
4342
+ * const { error } = await supabase.auth.unlinkIdentity(googleIdentity)
4343
+ * ```
2618
4344
  */
2619
4345
  async unlinkIdentity(identity: UserIdentity): Promise<
2620
4346
  | {
@@ -3114,6 +4840,28 @@ export default class GoTrueClient {
3114
4840
  * appropriately to conserve resources.
3115
4841
  *
3116
4842
  * {@see #stopAutoRefresh}
4843
+ *
4844
+ * @category Auth
4845
+ *
4846
+ * @remarks
4847
+ * - Only useful in non-browser environments such as React Native or Electron.
4848
+ * - The Supabase Auth library automatically starts and stops proactively refreshing the session when a tab is focused or not.
4849
+ * - 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.
4850
+ * - 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.
4851
+ *
4852
+ * @example Start and stop auto refresh in React Native
4853
+ * ```js
4854
+ * import { AppState } from 'react-native'
4855
+ *
4856
+ * // make sure you register this only once!
4857
+ * AppState.addEventListener('change', (state) => {
4858
+ * if (state === 'active') {
4859
+ * supabase.auth.startAutoRefresh()
4860
+ * } else {
4861
+ * supabase.auth.stopAutoRefresh()
4862
+ * }
4863
+ * })
4864
+ * ```
3117
4865
  */
3118
4866
  async startAutoRefresh() {
3119
4867
  this._removeVisibilityChangedCallback()
@@ -3127,6 +4875,28 @@ export default class GoTrueClient {
3127
4875
  * removed and you must manage visibility changes on your own.
3128
4876
  *
3129
4877
  * See {@link #startAutoRefresh} for more details.
4878
+ *
4879
+ * @category Auth
4880
+ *
4881
+ * @remarks
4882
+ * - Only useful in non-browser environments such as React Native or Electron.
4883
+ * - The Supabase Auth library automatically starts and stops proactively refreshing the session when a tab is focused or not.
4884
+ * - 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.
4885
+ * - When your application goes in the background or out of focus, call this method to stop the proactive refreshing of the session.
4886
+ *
4887
+ * @example Start and stop auto refresh in React Native
4888
+ * ```js
4889
+ * import { AppState } from 'react-native'
4890
+ *
4891
+ * // make sure you register this only once!
4892
+ * AppState.addEventListener('change', (state) => {
4893
+ * if (state === 'active') {
4894
+ * supabase.auth.startAutoRefresh()
4895
+ * } else {
4896
+ * supabase.auth.stopAutoRefresh()
4897
+ * }
4898
+ * })
4899
+ * ```
3130
4900
  */
3131
4901
  async stopAutoRefresh() {
3132
4902
  this._removeVisibilityChangedCallback()
@@ -3970,6 +5740,55 @@ export default class GoTrueClient {
3970
5740
  * can obtain from {@link #getSession}.
3971
5741
  * @param options Various additional options that allow you to customize the
3972
5742
  * behavior of this method.
5743
+ *
5744
+ * @category Auth
5745
+ *
5746
+ * @remarks
5747
+ * - 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.
5748
+ * - 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).
5749
+ * - 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.
5750
+ * - 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.
5751
+ * - 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.
5752
+ * - The returned claims can be customized per project using the [Custom Access Token Hook](/docs/guides/auth/auth-hooks/custom-access-token-hook).
5753
+ *
5754
+ * @example Get JWT claims, header and signature
5755
+ * ```js
5756
+ * const { data, error } = await supabase.auth.getClaims()
5757
+ * ```
5758
+ *
5759
+ * @exampleResponse Get JWT claims, header and signature
5760
+ * ```json
5761
+ * {
5762
+ * "data": {
5763
+ * "claims": {
5764
+ * "aal": "aal1",
5765
+ * "amr": [{
5766
+ * "method": "email",
5767
+ * "timestamp": 1715766000
5768
+ * }],
5769
+ * "app_metadata": {},
5770
+ * "aud": "authenticated",
5771
+ * "email": "example@email.com",
5772
+ * "exp": 1715769600,
5773
+ * "iat": 1715766000,
5774
+ * "is_anonymous": false,
5775
+ * "iss": "https://project-id.supabase.co/auth/v1",
5776
+ * "phone": "+13334445555",
5777
+ * "role": "authenticated",
5778
+ * "session_id": "11111111-1111-1111-1111-111111111111",
5779
+ * "sub": "11111111-1111-1111-1111-111111111111",
5780
+ * "user_metadata": {}
5781
+ * },
5782
+ * "header": {
5783
+ * "alg": "RS256",
5784
+ * "typ": "JWT",
5785
+ * "kid": "11111111-1111-1111-1111-111111111111"
5786
+ * },
5787
+ * "signature": [/** Uint8Array *\/],
5788
+ * },
5789
+ * "error": null
5790
+ * }
5791
+ * ```
3973
5792
  */
3974
5793
  async getClaims(
3975
5794
  jwt?: string,