@supabase/gotrue-js 1.23.0-next.2 → 1.23.0-next.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/dist/main/GoTrueAdminApi.d.ts +101 -0
  2. package/dist/main/GoTrueAdminApi.d.ts.map +1 -0
  3. package/dist/main/GoTrueAdminApi.js +212 -0
  4. package/dist/main/GoTrueAdminApi.js.map +1 -0
  5. package/dist/main/GoTrueClient.d.ts +96 -142
  6. package/dist/main/GoTrueClient.d.ts.map +1 -1
  7. package/dist/main/GoTrueClient.js +384 -377
  8. package/dist/main/GoTrueClient.js.map +1 -1
  9. package/dist/main/index.d.ts +3 -2
  10. package/dist/main/index.d.ts.map +1 -1
  11. package/dist/main/index.js +9 -4
  12. package/dist/main/index.js.map +1 -1
  13. package/dist/main/lib/constants.d.ts +1 -9
  14. package/dist/main/lib/constants.d.ts.map +1 -1
  15. package/dist/main/lib/constants.js +2 -10
  16. package/dist/main/lib/constants.js.map +1 -1
  17. package/dist/main/lib/errors.d.ts +38 -0
  18. package/dist/main/lib/errors.d.ts.map +1 -0
  19. package/dist/main/lib/errors.js +72 -0
  20. package/dist/main/lib/errors.js.map +1 -0
  21. package/dist/main/lib/fetch.d.ts +21 -5
  22. package/dist/main/lib/fetch.d.ts.map +1 -1
  23. package/dist/main/lib/fetch.js +67 -40
  24. package/dist/main/lib/fetch.js.map +1 -1
  25. package/dist/main/lib/helpers.d.ts +8 -3
  26. package/dist/main/lib/helpers.d.ts.map +1 -1
  27. package/dist/main/lib/helpers.js +32 -19
  28. package/dist/main/lib/helpers.js.map +1 -1
  29. package/dist/main/lib/types.d.ts +118 -29
  30. package/dist/main/lib/types.d.ts.map +1 -1
  31. package/dist/main/lib/version.d.ts +1 -1
  32. package/dist/main/lib/version.js +2 -2
  33. package/dist/main/lib/version.js.map +1 -1
  34. package/dist/module/GoTrueAdminApi.d.ts +101 -0
  35. package/dist/module/GoTrueAdminApi.d.ts.map +1 -0
  36. package/dist/module/GoTrueAdminApi.js +209 -0
  37. package/dist/module/GoTrueAdminApi.js.map +1 -0
  38. package/dist/module/GoTrueClient.d.ts +96 -142
  39. package/dist/module/GoTrueClient.d.ts.map +1 -1
  40. package/dist/module/GoTrueClient.js +385 -378
  41. package/dist/module/GoTrueClient.js.map +1 -1
  42. package/dist/module/index.d.ts +3 -2
  43. package/dist/module/index.d.ts.map +1 -1
  44. package/dist/module/index.js +3 -2
  45. package/dist/module/index.js.map +1 -1
  46. package/dist/module/lib/constants.d.ts +1 -9
  47. package/dist/module/lib/constants.d.ts.map +1 -1
  48. package/dist/module/lib/constants.js +1 -9
  49. package/dist/module/lib/constants.js.map +1 -1
  50. package/dist/module/lib/errors.d.ts +38 -0
  51. package/dist/module/lib/errors.d.ts.map +1 -0
  52. package/dist/module/lib/errors.js +61 -0
  53. package/dist/module/lib/errors.js.map +1 -0
  54. package/dist/module/lib/fetch.d.ts +21 -5
  55. package/dist/module/lib/fetch.d.ts.map +1 -1
  56. package/dist/module/lib/fetch.js +63 -35
  57. package/dist/module/lib/fetch.js.map +1 -1
  58. package/dist/module/lib/helpers.d.ts +8 -3
  59. package/dist/module/lib/helpers.d.ts.map +1 -1
  60. package/dist/module/lib/helpers.js +7 -14
  61. package/dist/module/lib/helpers.js.map +1 -1
  62. package/dist/module/lib/types.d.ts +118 -29
  63. package/dist/module/lib/types.d.ts.map +1 -1
  64. package/dist/module/lib/version.d.ts +1 -1
  65. package/dist/module/lib/version.js +2 -2
  66. package/dist/module/lib/version.js.map +1 -1
  67. package/package.json +25 -22
  68. package/src/GoTrueAdminApi.ts +232 -0
  69. package/src/GoTrueClient.ts +485 -496
  70. package/src/index.ts +3 -2
  71. package/src/lib/constants.ts +1 -9
  72. package/src/lib/errors.ts +76 -0
  73. package/src/lib/fetch.ts +92 -44
  74. package/src/lib/helpers.ts +10 -15
  75. package/src/lib/types.ts +139 -35
  76. package/src/lib/version.ts +2 -2
  77. package/dist/main/GoTrueApi.d.ts +0 -335
  78. package/dist/main/GoTrueApi.d.ts.map +0 -1
  79. package/dist/main/GoTrueApi.js +0 -671
  80. package/dist/main/GoTrueApi.js.map +0 -1
  81. package/dist/main/lib/cookies.d.ts +0 -23
  82. package/dist/main/lib/cookies.d.ts.map +0 -1
  83. package/dist/main/lib/cookies.js +0 -139
  84. package/dist/main/lib/cookies.js.map +0 -1
  85. package/dist/module/GoTrueApi.d.ts +0 -335
  86. package/dist/module/GoTrueApi.d.ts.map +0 -1
  87. package/dist/module/GoTrueApi.js +0 -668
  88. package/dist/module/GoTrueApi.js.map +0 -1
  89. package/dist/module/lib/cookies.d.ts +0 -23
  90. package/dist/module/lib/cookies.d.ts.map +0 -1
  91. package/dist/module/lib/cookies.js +0 -132
  92. package/dist/module/lib/cookies.js.map +0 -1
  93. package/src/GoTrueApi.ts +0 -840
  94. package/src/lib/cookies.ts +0 -178
@@ -0,0 +1,101 @@
1
+ import { Fetch } from './lib/fetch';
2
+ import { AdminUserAttributes, GenerateLinkTypes, Session, User, UserResponse } from './lib/types';
3
+ import { AuthError } from './lib/errors';
4
+ export default class GoTrueAdminApi {
5
+ protected url: string;
6
+ protected headers: {
7
+ [key: string]: string;
8
+ };
9
+ protected fetch: Fetch;
10
+ constructor({ url, headers, fetch, }: {
11
+ url: string;
12
+ headers?: {
13
+ [key: string]: string;
14
+ };
15
+ fetch?: Fetch;
16
+ });
17
+ /**
18
+ * Removes a logged-in session.
19
+ * @param jwt A valid, logged-in JWT.
20
+ */
21
+ signOut(jwt: string): Promise<{
22
+ error: AuthError | null;
23
+ }>;
24
+ /**
25
+ * Sends an invite link to an email address.
26
+ * @param email The email address of the user.
27
+ * @param options.redirectTo A URL or mobile address to send the user to after they are confirmed.
28
+ * @param options.data Optional user metadata
29
+ */
30
+ inviteUserByEmail(email: string, options?: {
31
+ redirectTo?: string;
32
+ data?: object;
33
+ }): Promise<UserResponse>;
34
+ /**
35
+ * Generates links to be sent via email or other.
36
+ * @param email The user's email.
37
+ * @param options.password User password. For signup only.
38
+ * @param options.data Optional user metadata. For signup only.
39
+ * @param options.redirectTo The redirect url which should be appended to the generated link
40
+ */
41
+ generateLink(type: GenerateLinkTypes, email: string, options?: {
42
+ password?: string;
43
+ data?: object;
44
+ redirectTo?: string;
45
+ }): Promise<{
46
+ data: User;
47
+ error: null;
48
+ } | {
49
+ data: Session;
50
+ error: null;
51
+ } | {
52
+ data: null;
53
+ error: AuthError;
54
+ }>;
55
+ /**
56
+ * Creates a new user.
57
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
58
+ */
59
+ createUser(attributes: AdminUserAttributes): Promise<UserResponse>;
60
+ /**
61
+ * Get a list of users.
62
+ *
63
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
64
+ */
65
+ listUsers(): Promise<{
66
+ data: {
67
+ users: User[];
68
+ };
69
+ error: null;
70
+ } | {
71
+ data: {
72
+ users: [];
73
+ };
74
+ error: AuthError;
75
+ }>;
76
+ /**
77
+ * Get user by id.
78
+ *
79
+ * @param uid The user's unique identifier
80
+ *
81
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
82
+ */
83
+ getUserById(uid: string): Promise<UserResponse>;
84
+ /**
85
+ * Updates the user data.
86
+ *
87
+ * @param attributes The data you want to update.
88
+ *
89
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
90
+ */
91
+ updateUserById(uid: string, attributes: AdminUserAttributes): Promise<UserResponse>;
92
+ /**
93
+ * Delete a user. Requires a `service_role` key.
94
+ *
95
+ * @param uid The user uid you want to remove.
96
+ *
97
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
98
+ */
99
+ deleteUser(uid: string): Promise<UserResponse>;
100
+ }
101
+ //# sourceMappingURL=GoTrueAdminApi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GoTrueAdminApi.d.ts","sourceRoot":"","sources":["../../src/GoTrueAdminApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAA2B,MAAM,aAAa,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QAAE,IAAI,EAAE,IAAI,CAAC;QAAC,KAAK,EAAE,SAAS,CAAA;KAAE,CACnC;IAqBD;;;OAGG;IACG,UAAU,CAAC,UAAU,EAAE,mBAAmB,GAAG,OAAO,CAAC,YAAY,CAAC;IAgBxE;;;;OAIG;IACG,SAAS,IAAI,OAAO,CACxB;QAAE,IAAI,EAAE;YAAE,KAAK,EAAE,IAAI,EAAE,CAAA;SAAE,CAAC;QAAC,KAAK,EAAE,IAAI,CAAA;KAAE,GAAG;QAAE,IAAI,EAAE;YAAE,KAAK,EAAE,EAAE,CAAA;SAAE,CAAC;QAAC,KAAK,EAAE,SAAS,CAAA;KAAE,CACrF;IAeD;;;;;;OAMG;IACG,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAerD;;;;;;OAMG;IACG,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,mBAAmB,GAAG,OAAO,CAAC,YAAY,CAAC;IAgBzF;;;;;;OAMG;IACG,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;CAcrD"}
@@ -0,0 +1,212 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const fetch_1 = require("./lib/fetch");
13
+ const helpers_1 = require("./lib/helpers");
14
+ const errors_1 = require("./lib/errors");
15
+ class GoTrueAdminApi {
16
+ constructor({ url = '', headers = {}, fetch, }) {
17
+ this.url = url;
18
+ this.headers = headers;
19
+ this.fetch = (0, helpers_1.resolveFetch)(fetch);
20
+ }
21
+ /**
22
+ * Removes a logged-in session.
23
+ * @param jwt A valid, logged-in JWT.
24
+ */
25
+ signOut(jwt) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ try {
28
+ yield (0, fetch_1._request)(this.fetch, 'POST', `${this.url}/logout`, {
29
+ jwt,
30
+ noResolveJson: true,
31
+ });
32
+ return { error: null };
33
+ }
34
+ catch (error) {
35
+ if ((0, errors_1.isAuthError)(error)) {
36
+ return { error };
37
+ }
38
+ throw error;
39
+ }
40
+ });
41
+ }
42
+ /**
43
+ * Sends an invite link to an email address.
44
+ * @param email The email address of the user.
45
+ * @param options.redirectTo A URL or mobile address to send the user to after they are confirmed.
46
+ * @param options.data Optional user metadata
47
+ */
48
+ inviteUserByEmail(email, options = {}) {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ try {
51
+ return yield (0, fetch_1._request)(this.fetch, 'POST', `${this.url}/invite`, {
52
+ body: { email, data: options.data },
53
+ headers: this.headers,
54
+ redirectTo: options.redirectTo,
55
+ xform: fetch_1._userResponse,
56
+ });
57
+ }
58
+ catch (error) {
59
+ if ((0, errors_1.isAuthError)(error)) {
60
+ return { data: { user: null }, error };
61
+ }
62
+ throw error;
63
+ }
64
+ });
65
+ }
66
+ /**
67
+ * Generates links to be sent via email or other.
68
+ * @param email The user's email.
69
+ * @param options.password User password. For signup only.
70
+ * @param options.data Optional user metadata. For signup only.
71
+ * @param options.redirectTo The redirect url which should be appended to the generated link
72
+ */
73
+ generateLink(type, email, options = {}) {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ try {
76
+ return yield (0, fetch_1._request)(this.fetch, 'POST', `${this.url}/admin/generate_link`, {
77
+ body: {
78
+ type,
79
+ email,
80
+ password: options.password,
81
+ data: options.data,
82
+ redirect_to: options.redirectTo,
83
+ },
84
+ headers: this.headers,
85
+ });
86
+ }
87
+ catch (error) {
88
+ if ((0, errors_1.isAuthError)(error)) {
89
+ return { data: null, error };
90
+ }
91
+ throw error;
92
+ }
93
+ });
94
+ }
95
+ // User Admin API
96
+ /**
97
+ * Creates a new user.
98
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
99
+ */
100
+ createUser(attributes) {
101
+ return __awaiter(this, void 0, void 0, function* () {
102
+ try {
103
+ return yield (0, fetch_1._request)(this.fetch, 'POST', `${this.url}/admin/users`, {
104
+ body: attributes,
105
+ headers: this.headers,
106
+ xform: fetch_1._userResponse,
107
+ });
108
+ }
109
+ catch (error) {
110
+ if ((0, errors_1.isAuthError)(error)) {
111
+ return { data: { user: null }, error };
112
+ }
113
+ throw error;
114
+ }
115
+ });
116
+ }
117
+ /**
118
+ * Get a list of users.
119
+ *
120
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
121
+ */
122
+ listUsers() {
123
+ return __awaiter(this, void 0, void 0, function* () {
124
+ try {
125
+ const { data, error } = yield (0, fetch_1._request)(this.fetch, 'GET', `${this.url}/admin/users`, {
126
+ headers: this.headers,
127
+ });
128
+ if (error)
129
+ throw error;
130
+ return { data: Object.assign({}, data), error: null };
131
+ }
132
+ catch (error) {
133
+ if ((0, errors_1.isAuthError)(error)) {
134
+ return { data: { users: [] }, error };
135
+ }
136
+ throw error;
137
+ }
138
+ });
139
+ }
140
+ /**
141
+ * Get user by id.
142
+ *
143
+ * @param uid The user's unique identifier
144
+ *
145
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
146
+ */
147
+ getUserById(uid) {
148
+ return __awaiter(this, void 0, void 0, function* () {
149
+ try {
150
+ return yield (0, fetch_1._request)(this.fetch, 'GET', `${this.url}/admin/users/${uid}`, {
151
+ headers: this.headers,
152
+ xform: fetch_1._userResponse,
153
+ });
154
+ }
155
+ catch (error) {
156
+ if ((0, errors_1.isAuthError)(error)) {
157
+ return { data: { user: null }, error };
158
+ }
159
+ throw error;
160
+ }
161
+ });
162
+ }
163
+ /**
164
+ * Updates the user data.
165
+ *
166
+ * @param attributes The data you want to update.
167
+ *
168
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
169
+ */
170
+ updateUserById(uid, attributes) {
171
+ return __awaiter(this, void 0, void 0, function* () {
172
+ try {
173
+ return yield (0, fetch_1._request)(this.fetch, 'PUT', `${this.url}/admin/users/${uid}`, {
174
+ body: attributes,
175
+ headers: this.headers,
176
+ xform: fetch_1._userResponse,
177
+ });
178
+ }
179
+ catch (error) {
180
+ if ((0, errors_1.isAuthError)(error)) {
181
+ return { data: { user: null }, error };
182
+ }
183
+ throw error;
184
+ }
185
+ });
186
+ }
187
+ /**
188
+ * Delete a user. Requires a `service_role` key.
189
+ *
190
+ * @param uid The user uid you want to remove.
191
+ *
192
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
193
+ */
194
+ deleteUser(uid) {
195
+ return __awaiter(this, void 0, void 0, function* () {
196
+ try {
197
+ return yield (0, fetch_1._request)(this.fetch, 'DELETE', `${this.url}/admin/users/${uid}`, {
198
+ headers: this.headers,
199
+ xform: fetch_1._userResponse,
200
+ });
201
+ }
202
+ catch (error) {
203
+ if ((0, errors_1.isAuthError)(error)) {
204
+ return { data: { user: null }, error };
205
+ }
206
+ throw error;
207
+ }
208
+ });
209
+ }
210
+ }
211
+ exports.default = GoTrueAdminApi;
212
+ //# sourceMappingURL=GoTrueAdminApi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GoTrueAdminApi.js","sourceRoot":"","sources":["../../src/GoTrueAdminApi.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,uCAA4D;AAC5D,2CAA4C;AAE5C,yCAAqD;AAErD,MAAqB,cAAc;IAOjC,YAAY,EACV,GAAG,GAAG,EAAE,EACR,OAAO,GAAG,EAAE,EACZ,KAAK,GAON;QACC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,KAAK,GAAG,IAAA,sBAAY,EAAC,KA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AA;iBACvC;gBAED,MAAM,KAAK,CAAA;aACZ;QACH,CAAC;KAAA;IAED;;;;;;OAMG;IACG,UAAU,CAAC,GAAW;;YAC1B,IAAI;gBACF,OAAO,MAAM,IAAA,gBAAQ,EAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,GAAG,gBAAgB,GAAG,EAAE,EAAE;oBAC5E,OAAO,EAAE,IAAI,CAAC,OAAO;oBACrB,KAAK,EAAE,qBAAa;iBACrB,CAAC,CAAA;aACH;YAAC,OAAO,KAAK,EAAE;gBACd,IAAI,IAAA,oBAAW,EAAC,KAAK,CAAC,EAAE;oBACtB,OAAO,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,CAAA;iBACvC;gBAED,MAAM,KAAK,CAAA;aACZ;QACH,CAAC;KAAA;CACF;AAlOD,iCAkOC"}
@@ -1,49 +1,45 @@
1
- import GoTrueApi from './GoTrueApi';
2
- import { Deferred } from './lib/helpers';
1
+ import GoTrueAdminApi from './GoTrueAdminApi';
2
+ import { AuthError } from './lib/errors';
3
3
  import { Fetch } from './lib/fetch';
4
- import type { ApiError, Session, User, UserAttributes, Provider, Subscription, AuthChangeEvent, CookieOptions, UserCredentials, VerifyOTPParams, SupportedStorage } from './lib/types';
4
+ import { Deferred } from './lib/helpers';
5
+ import type { AuthChangeEvent, AuthResponse, CallRefreshTokenResult, OAuthResponse, Session, SignInWithOAuthCredentials, SignInWithPasswordCredentials, SignInWithPasswordlessCredentials, Subscription, SupportedStorage, UserAttributes, UserCredentials, UserResponse, VerifyOtpParams } from './lib/types';
5
6
  export default class GoTrueClient {
6
7
  /**
7
- * Namespace for the GoTrue API methods.
8
- * These can be used for example to get a user from a JWT in a server environment or reset a user's password.
9
- */
10
- api: GoTrueApi;
11
- /**
12
- * The currently logged in user or null.
13
- * @deprecated use `getUser()` instead
8
+ * Namespace for the GoTrue admin methods.
9
+ * These methods should only be used in a trusted server-side environment.
14
10
  */
15
- protected currentUser: User | null;
11
+ admin: GoTrueAdminApi;
16
12
  /**
17
- * The session object for the currently logged in user or null.
18
- * @deprecated use `getSession()` instead
13
+ * The storage key used to identify the values saved in localStorage
19
14
  */
20
- protected currentSession: Session | null;
15
+ protected storageKey: string;
21
16
  /**
22
- * The session object for the currently logged in user or null.
17
+ * The session object for the currently logged in user. If null, it means there isn't a logged-in user.
23
18
  * Only used if persistSession is false.
24
19
  */
25
20
  protected inMemorySession: Session | null;
26
21
  protected autoRefreshToken: boolean;
27
22
  protected persistSession: boolean;
28
- protected localStorage: SupportedStorage;
29
- protected multiTab: boolean;
23
+ protected storage: SupportedStorage;
30
24
  protected stateChangeEmitters: Map<string, Subscription>;
31
25
  protected refreshTokenTimer?: ReturnType<typeof setTimeout>;
32
26
  protected networkRetries: number;
33
- protected refreshingDeferred: Deferred<{
34
- data: Session;
35
- error: null;
36
- }> | null;
27
+ protected refreshingDeferred: Deferred<CallRefreshTokenResult> | null;
28
+ protected url: string;
29
+ protected headers: {
30
+ [key: string]: string;
31
+ };
32
+ protected fetch: Fetch;
37
33
  /**
38
34
  * Create a new client for use in the browser.
39
35
  * @param options.url The URL of the GoTrue server.
40
36
  * @param options.headers Any additional headers to send to the GoTrue server.
37
+ * @param options.storageKey Optional key name used for storing tokens in local storage
41
38
  * @param options.detectSessionInUrl Set to "true" if you want to automatically detects OAuth grants in the URL and signs in the user.
42
39
  * @param options.autoRefreshToken Set to "true" if you want to automatically refresh the token before expiring.
43
- * @param options.persistSession Set to "true" if you want to automatically save the user session into local storage.
40
+ * @param options.persistSession Set to "true" if you want to automatically save the user session into local storage. If set to false, session will just be saved in memory.
44
41
  * @param options.localStorage Provide your own local storage implementation to use instead of the browser's local storage.
45
42
  * @param options.multiTab Set to "false" if you want to disable multi-tab/window events.
46
- * @param options.cookieOptions
47
43
  * @param options.fetch A custom fetch implementation.
48
44
  */
49
45
  constructor(options: {
@@ -51,178 +47,132 @@ export default class GoTrueClient {
51
47
  headers?: {
52
48
  [key: string]: string;
53
49
  };
50
+ storageKey?: string;
54
51
  detectSessionInUrl?: boolean;
55
52
  autoRefreshToken?: boolean;
56
53
  persistSession?: boolean;
57
- localStorage?: SupportedStorage;
54
+ storage?: SupportedStorage;
58
55
  multiTab?: boolean;
59
- cookieOptions?: CookieOptions;
60
56
  fetch?: Fetch;
61
57
  });
62
58
  /**
63
59
  * Creates a new user.
64
60
  * @type UserCredentials
65
- * @param email The user's email address.
66
- * @param password The user's password.
67
- * @param phone The user's phone number.
68
- * @param redirectTo The redirect URL attached to the signup confirmation link. Does not redirect the user if it's a mobile signup.
69
- * @param data Optional user metadata.
61
+ * @param options.redirectTo The redirect URL attached to the signup confirmation link. Does not redirect the user if it's a mobile signup.
62
+ * @param options.data Optional user metadata.
63
+ * @param options.captchaToken Verification token received when the user completes the captcha on the site.
64
+ * @returns A logged-in session if the server has "autoconfirm" ON
65
+ * @returns A user if the server has "autoconfirm" OFF
70
66
  */
71
67
  signUp({ email, password, phone }: UserCredentials, options?: {
72
68
  redirectTo?: string;
73
69
  data?: object;
74
70
  captchaToken?: string;
75
- }): Promise<{
76
- user: User | null;
77
- session: Session | null;
78
- error: ApiError | null;
79
- }>;
71
+ }): Promise<AuthResponse>;
80
72
  /**
81
73
  * Log in an existing user, or login via a third-party provider.
82
- * @type UserCredentials
83
- * @param email The user's email address.
84
- * @param phone The user's phone number.
85
- * @param password The user's password.
86
- * @param refreshToken A valid refresh token that was returned on login.
87
- * @param provider One of the providers supported by GoTrue.
88
- * @param redirectTo A URL to send the user to after they are confirmed (OAuth logins only).
89
- * @param shouldCreateUser A boolean flag to indicate whether to automatically create a user on magiclink / otp sign-ins if the user doesn't exist. Defaults to true.
90
- * @param scopes A space-separated list of scopes granted to the OAuth application.
91
74
  */
92
- signIn({ email, phone, password, refreshToken, provider, oidc }: UserCredentials, options?: {
93
- redirectTo?: string;
94
- shouldCreateUser?: boolean;
95
- scopes?: string;
96
- captchaToken?: string;
97
- queryParams?: {
98
- [key: string]: string;
99
- };
100
- }): Promise<{
101
- session: Session | null;
102
- user: User | null;
103
- provider?: Provider;
104
- url?: string | null;
105
- error: ApiError | null;
106
- }>;
75
+ signInWithPassword(credentials: SignInWithPasswordCredentials): Promise<AuthResponse>;
107
76
  /**
108
- * Log in a user given a User supplied OTP received via mobile.
109
- * @param email The user's email address.
110
- * @param phone The user's phone number.
111
- * @param token The user's password.
112
- * @param type The user's verification type.
113
- * @param redirectTo A URL or mobile address to send the user to after they are confirmed.
77
+ * Log in an existing user via a third-party provider.
114
78
  */
115
- verifyOTP(params: VerifyOTPParams, options?: {
116
- redirectTo?: string;
117
- }): Promise<{
118
- user: User | null;
119
- session: Session | null;
120
- error: ApiError | null;
121
- }>;
79
+ signInWithOAuth(credentials: SignInWithOAuthCredentials): Promise<OAuthResponse>;
122
80
  /**
123
- * Inside a browser context, `user()` will return the user data, if there is a logged in user.
124
- *
125
- * For server-side management, you can get a user through `auth.api.getUserByCookie()`
126
- * @deprecated use `getUser()` instead
81
+ * Passwordless method for logging in an existing user.
127
82
  */
128
- user(): User | null;
83
+ signInWithOtp(credentials: SignInWithPasswordlessCredentials): Promise<AuthResponse>;
129
84
  /**
130
- * Returns the session data, if there is an active session.
131
- * @deprecated use `getSession()` instead
85
+ * Log in a user given a User supplied OTP received via mobile.
86
+ * @param options.redirectTo A URL to send the user to after they are confirmed.
87
+ * @param options.captchaToken Verification token received when the user completes the captcha on the site.
132
88
  */
133
- session(): Session | null;
89
+ verifyOtp(params: VerifyOtpParams, options?: {
90
+ redirectTo?: string;
91
+ captchaToken?: string;
92
+ }): Promise<AuthResponse>;
134
93
  /**
135
94
  * Returns the session data, refreshing it if necessary.
95
+ * If no session is detected, the session returned will be null.
136
96
  */
137
97
  getSession(): Promise<{
138
- session: Session;
139
- error: null;
140
- } | {
141
- session: null;
142
- error: ApiError;
143
- } | {
144
- session: null;
145
- error: null;
146
- }>;
147
- /**
148
- * Returns the user data, refreshing the session if necessary.
149
- */
150
- getUser(): Promise<{
151
- user: User;
98
+ data: {
99
+ session: Session;
100
+ };
152
101
  error: null;
153
102
  } | {
154
- user: null;
155
- error: ApiError;
103
+ data: {
104
+ session: null;
105
+ };
106
+ error: AuthError;
156
107
  } | {
157
- user: null;
108
+ data: {
109
+ session: null;
110
+ };
158
111
  error: null;
159
112
  }>;
160
113
  /**
161
- * Force refreshes the session including the user data in case it was updated in a different session.
114
+ * Gets the current user details if there is an existing session.
115
+ * @param jwt Takes in an optional access token jwt. If no jwt is provided, getUser() will attempt to get the jwt from the current session.
162
116
  */
163
- refreshSession(): Promise<{
164
- data: Session | null;
165
- user: User | null;
166
- error: ApiError | null;
167
- }>;
117
+ getUser(jwt?: string): Promise<UserResponse>;
168
118
  /**
169
119
  * Updates user data, if there is a logged in user.
170
120
  */
171
- update(attributes: UserAttributes): Promise<{
172
- data: User | null;
173
- user: User | null;
174
- error: ApiError | null;
175
- }>;
176
- /**
177
- * Sets the session data from refresh_token and returns current Session and Error
178
- * @param refresh_token a JWT token
179
- */
180
- setSession(refresh_token: string): Promise<{
181
- session: Session | null;
182
- error: ApiError | null;
183
- }>;
121
+ updateUser(attributes: UserAttributes): Promise<UserResponse>;
184
122
  /**
185
- * Overrides the JWT on the current client. The JWT will then be sent in all subsequent network requests.
186
- * @param access_token a jwt access token
187
- * @deprecated you can use `getSession()` instead as it reads from storage every time (always fresh)
123
+ * Sets the session data from refresh_token and returns current session or an error if the refresh_token is invalid.
124
+ * @param refresh_token The refresh token returned by gotrue.
188
125
  */
189
- setAuth(access_token: string): Session;
126
+ setSession(refresh_token: string): Promise<AuthResponse>;
190
127
  /**
191
128
  * Gets the session data from a URL string
192
- * @param options.storeSession Optionally store the session in the browser
193
129
  */
194
- getSessionFromUrl(options?: {
195
- storeSession?: boolean;
196
- }): Promise<{
197
- data: Session | null;
198
- error: ApiError | null;
199
- }>;
130
+ private _getSessionFromUrl;
200
131
  /**
201
132
  * Inside a browser context, `signOut()` will remove the logged in user from the browser session
202
133
  * and log them out - removing all items from localstorage and then trigger a "SIGNED_OUT" event.
203
134
  *
204
- * For server-side management, you can disable sessions by passing a JWT through to `auth.api.signOut(JWT: string)`
135
+ * For server-side management, you can revoke all refresh tokens for a user by passing a user's JWT through to `auth.api.signOut(JWT: string)`.
136
+ * 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.
205
137
  */
206
138
  signOut(): Promise<{
207
- error: ApiError | null;
139
+ error: AuthError | null;
208
140
  }>;
209
141
  /**
210
142
  * Receive a notification every time an auth event happens.
143
+ * @param callback A callback function to be invoked when an auth event happens.
211
144
  * @returns {Subscription} A subscription object which can be used to unsubscribe itself.
212
145
  */
213
146
  onAuthStateChange(callback: (event: AuthChangeEvent, session: Session | null) => void): {
214
- data: Subscription | null;
215
- error: ApiError | null;
147
+ subscription: Subscription;
148
+ error: null;
149
+ } | {
150
+ subscription: null;
151
+ error: AuthError;
216
152
  };
217
- private _handleEmailSignIn;
218
- private _handlePhoneSignIn;
219
- private _handleProviderSignIn;
220
- private _handleOpenIDConnectSignIn;
221
153
  /**
222
- * Attempts to get the session from LocalStorage
223
- * Note: this should never be async (even for React Native), as we need it to return immediately in the constructor.
154
+ * Sends a reset request to an email address.
155
+ * @param email The email address of the user.
156
+ * @param options.redirectTo A URL to send the user to after they are confirmed.
157
+ * @param options.captchaToken Verification token received when the user completes the captcha on the site.
158
+ */
159
+ resetPasswordForEmail(email: string, options?: {
160
+ redirectTo?: string;
161
+ captchaToken?: string;
162
+ }): Promise<{
163
+ data: {};
164
+ error: null;
165
+ } | {
166
+ data: null;
167
+ error: AuthError;
168
+ }>;
169
+ /**
170
+ * Generates a new JWT.
171
+ * @param refreshToken A valid refresh token that was returned on login.
224
172
  */
225
- private _recoverSession;
173
+ private _refreshAccessToken;
174
+ private _doesSessionExist;
175
+ private _handleProviderSignIn;
226
176
  /**
227
177
  * Recovers the session from LocalStorage and refreshes
228
178
  * Note: this method is async to accommodate for AsyncStorage e.g. in React native.
@@ -239,13 +189,17 @@ export default class GoTrueClient {
239
189
  private _removeSession;
240
190
  /**
241
191
  * Clear and re-create refresh token timer
242
- * @param value time intervals in milliseconds
192
+ * @param value time intervals in milliseconds.
193
+ * @param session The current session.
243
194
  */
244
195
  private _startAutoRefreshToken;
196
+ private _handleVisibilityChange;
245
197
  /**
246
- * Listens for changes to LocalStorage and updates the current session.
198
+ * Generates the relevant login URL for a third-party provider.
199
+ * @param options.redirectTo A URL or mobile address to send the user to after they are confirmed.
200
+ * @param options.scopes A space-separated list of scopes granted to the OAuth application.
201
+ * @param options.queryParams An object of key-value pairs containing query parameters granted to the OAuth application.
247
202
  */
248
- private _listenForMultiTabEvents;
249
- private _handleVisibilityChange;
203
+ private _getUrlForProvider;
250
204
  }
251
205
  //# sourceMappingURL=GoTrueClient.d.ts.map