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

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 +105 -0
  2. package/dist/main/GoTrueAdminApi.d.ts.map +1 -0
  3. package/dist/main/GoTrueAdminApi.js +216 -0
  4. package/dist/main/GoTrueAdminApi.js.map +1 -0
  5. package/dist/main/GoTrueClient.d.ts +96 -124
  6. package/dist/main/GoTrueClient.d.ts.map +1 -1
  7. package/dist/main/GoTrueClient.js +378 -357
  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 +86 -15
  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 +105 -0
  35. package/dist/module/GoTrueAdminApi.d.ts.map +1 -0
  36. package/dist/module/GoTrueAdminApi.js +213 -0
  37. package/dist/module/GoTrueAdminApi.js.map +1 -0
  38. package/dist/module/GoTrueClient.d.ts +96 -124
  39. package/dist/module/GoTrueClient.d.ts.map +1 -1
  40. package/dist/module/GoTrueClient.js +379 -358
  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 +86 -15
  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 +23 -20
  68. package/src/GoTrueAdminApi.ts +242 -0
  69. package/src/GoTrueClient.ts +473 -468
  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 +100 -21
  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,105 @@
1
+ import { Fetch } from './lib/fetch';
2
+ import { AdminUserAttributes, 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 type The link type ("signup" or "magiclink" or "recovery" or "invite").
37
+ * @param email The user's email.
38
+ * @param options.password User password. For signup only.
39
+ * @param options.data Optional user metadata. For signup only.
40
+ * @param options.redirectTo The link type ("signup" or "magiclink" or "recovery" or "invite").
41
+ */
42
+ generateLink(type: 'signup' | 'magiclink' | 'recovery' | 'invite' | 'email_change_current' | 'email_change_new', email: string, options?: {
43
+ password?: string;
44
+ data?: object;
45
+ redirectTo?: string;
46
+ }): Promise<{
47
+ data: User;
48
+ error: null;
49
+ } | {
50
+ data: Session;
51
+ error: null;
52
+ } | {
53
+ data: null;
54
+ error: AuthError;
55
+ }>;
56
+ /**
57
+ * Creates a new user.
58
+ *
59
+ * @param attributes The data you want to create the user with.
60
+ *
61
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
62
+ */
63
+ createUser(attributes: AdminUserAttributes): Promise<UserResponse>;
64
+ /**
65
+ * Get a list of users.
66
+ *
67
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
68
+ */
69
+ listUsers(): Promise<{
70
+ data: {
71
+ users: User[];
72
+ };
73
+ error: null;
74
+ } | {
75
+ data: {
76
+ users: [];
77
+ };
78
+ error: AuthError;
79
+ }>;
80
+ /**
81
+ * Get user by id.
82
+ *
83
+ * @param uid The user's unique identifier
84
+ *
85
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
86
+ */
87
+ getUserById(uid: string): Promise<UserResponse>;
88
+ /**
89
+ * Updates the user data.
90
+ *
91
+ * @param attributes The data you want to update.
92
+ *
93
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
94
+ */
95
+ updateUserById(uid: string, attributes: AdminUserAttributes): Promise<UserResponse>;
96
+ /**
97
+ * Delete a user. Requires a `service_role` key.
98
+ *
99
+ * @param uid The user uid you want to remove.
100
+ *
101
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
102
+ */
103
+ deleteUser(uid: string): Promise<UserResponse>;
104
+ }
105
+ //# sourceMappingURL=GoTrueAdminApi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":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AAM,CAAA;KACf,GACL,OAAO,CACN;QACE,IAAI,EAAE,IAAI,CAAA;QACV,KAAK,EAAE,IAAI,CAAA;KACZ,GACD;QACE,IAAI,EAAE,OAAO,CAAA;QACb,KAAK,EAAE,IAAI,CAAA;KACZ,GACD;QAAE,IAAI,EAAE,IAAI,CAAC;QAAC,KAAK,EAAE,SAAS,CAAA;KAAE,CACnC;IAqBD;;;;;;OAMG;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,216 @@
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 type The link type ("signup" or "magiclink" or "recovery" or "invite").
69
+ * @param email The user's email.
70
+ * @param options.password User password. For signup only.
71
+ * @param options.data Optional user metadata. For signup only.
72
+ * @param options.redirectTo The link type ("signup" or "magiclink" or "recovery" or "invite").
73
+ */
74
+ generateLink(type, email, options = {}) {
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ try {
77
+ return yield (0, fetch_1._request)(this.fetch, 'POST', `${this.url}/admin/generate_link`, {
78
+ body: {
79
+ type,
80
+ email,
81
+ password: options.password,
82
+ data: options.data,
83
+ redirect_to: options.redirectTo,
84
+ },
85
+ headers: this.headers,
86
+ });
87
+ }
88
+ catch (error) {
89
+ if ((0, errors_1.isAuthError)(error)) {
90
+ return { data: null, error };
91
+ }
92
+ throw error;
93
+ }
94
+ });
95
+ }
96
+ // User Admin API
97
+ /**
98
+ * Creates a new user.
99
+ *
100
+ * @param attributes The data you want to create the user with.
101
+ *
102
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
103
+ */
104
+ createUser(attributes) {
105
+ return __awaiter(this, void 0, void 0, function* () {
106
+ try {
107
+ return yield (0, fetch_1._request)(this.fetch, 'POST', `${this.url}/admin/users`, {
108
+ body: attributes,
109
+ headers: this.headers,
110
+ xform: fetch_1._userResponse,
111
+ });
112
+ }
113
+ catch (error) {
114
+ if ((0, errors_1.isAuthError)(error)) {
115
+ return { data: { user: null }, error };
116
+ }
117
+ throw error;
118
+ }
119
+ });
120
+ }
121
+ /**
122
+ * Get a list of users.
123
+ *
124
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
125
+ */
126
+ listUsers() {
127
+ return __awaiter(this, void 0, void 0, function* () {
128
+ try {
129
+ const { data, error } = yield (0, fetch_1._request)(this.fetch, 'GET', `${this.url}/admin/users`, {
130
+ headers: this.headers,
131
+ });
132
+ if (error)
133
+ throw error;
134
+ return { data: Object.assign({}, data), error: null };
135
+ }
136
+ catch (error) {
137
+ if ((0, errors_1.isAuthError)(error)) {
138
+ return { data: { users: [] }, error };
139
+ }
140
+ throw error;
141
+ }
142
+ });
143
+ }
144
+ /**
145
+ * Get user by id.
146
+ *
147
+ * @param uid The user's unique identifier
148
+ *
149
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
150
+ */
151
+ getUserById(uid) {
152
+ return __awaiter(this, void 0, void 0, function* () {
153
+ try {
154
+ return yield (0, fetch_1._request)(this.fetch, 'GET', `${this.url}/admin/users/${uid}`, {
155
+ headers: this.headers,
156
+ xform: fetch_1._userResponse,
157
+ });
158
+ }
159
+ catch (error) {
160
+ if ((0, errors_1.isAuthError)(error)) {
161
+ return { data: { user: null }, error };
162
+ }
163
+ throw error;
164
+ }
165
+ });
166
+ }
167
+ /**
168
+ * Updates the user data.
169
+ *
170
+ * @param attributes The data you want to update.
171
+ *
172
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
173
+ */
174
+ updateUserById(uid, attributes) {
175
+ return __awaiter(this, void 0, void 0, function* () {
176
+ try {
177
+ return yield (0, fetch_1._request)(this.fetch, 'PUT', `${this.url}/admin/users/${uid}`, {
178
+ body: attributes,
179
+ headers: this.headers,
180
+ xform: fetch_1._userResponse,
181
+ });
182
+ }
183
+ catch (error) {
184
+ if ((0, errors_1.isAuthError)(error)) {
185
+ return { data: { user: null }, error };
186
+ }
187
+ throw error;
188
+ }
189
+ });
190
+ }
191
+ /**
192
+ * Delete a user. Requires a `service_role` key.
193
+ *
194
+ * @param uid The user uid you want to remove.
195
+ *
196
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
197
+ */
198
+ deleteUser(uid) {
199
+ return __awaiter(this, void 0, void 0, function* () {
200
+ try {
201
+ return yield (0, fetch_1._request)(this.fetch, 'DELETE', `${this.url}/admin/users/${uid}`, {
202
+ headers: this.headers,
203
+ xform: fetch_1._userResponse,
204
+ });
205
+ }
206
+ catch (error) {
207
+ if ((0, errors_1.isAuthError)(error)) {
208
+ return { data: { user: null }, error };
209
+ }
210
+ throw error;
211
+ }
212
+ });
213
+ }
214
+ }
215
+ exports.default = GoTrueAdminApi;
216
+ //# sourceMappingURL=GoTrueAdminApi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GoTrueAdminApi.js","sourceRoot":"","sources":["../../src/GoTrueAdminApi.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,u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AE;oBACzE,IAAI,EAAE,UAAU;oBAChB,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;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;AA5OD,iCA4OC"}
@@ -1,23 +1,19 @@
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.
10
+ * These methods
14
11
  */
15
- protected currentUser: User | null;
12
+ admin: GoTrueAdminApi;
16
13
  /**
17
- * The session object for the currently logged in user or null.
18
- * @deprecated use `getSession()` instead
14
+ * The storage key used to identity the values saved in localStorage
19
15
  */
20
- protected currentSession: Session | null;
16
+ protected storageKey: string;
21
17
  /**
22
18
  * The session object for the currently logged in user or null.
23
19
  * Only used if persistSession is false.
@@ -25,25 +21,26 @@ export default class GoTrueClient {
25
21
  protected inMemorySession: Session | null;
26
22
  protected autoRefreshToken: boolean;
27
23
  protected persistSession: boolean;
28
- protected localStorage: SupportedStorage;
29
- protected multiTab: boolean;
24
+ protected storage: SupportedStorage;
30
25
  protected stateChangeEmitters: Map<string, Subscription>;
31
26
  protected refreshTokenTimer?: ReturnType<typeof setTimeout>;
32
27
  protected networkRetries: number;
33
- protected refreshingDeferred: Deferred<{
34
- data: Session;
35
- error: null;
36
- }> | null;
28
+ protected refreshingDeferred: Deferred<CallRefreshTokenResult> | null;
29
+ protected url: string;
30
+ protected headers: {
31
+ [key: string]: string;
32
+ };
33
+ protected fetch: Fetch;
37
34
  /**
38
35
  * Create a new client for use in the browser.
39
36
  * @param options.url The URL of the GoTrue server.
40
37
  * @param options.headers Any additional headers to send to the GoTrue server.
38
+ * @param options.storageKey Optional key name used for storing tokens in local storage
41
39
  * @param options.detectSessionInUrl Set to "true" if you want to automatically detects OAuth grants in the URL and signs in the user.
42
40
  * @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.
41
+ * @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
42
  * @param options.localStorage Provide your own local storage implementation to use instead of the browser's local storage.
45
43
  * @param options.multiTab Set to "false" if you want to disable multi-tab/window events.
46
- * @param options.cookieOptions
47
44
  * @param options.fetch A custom fetch implementation.
48
45
  */
49
46
  constructor(options: {
@@ -51,12 +48,12 @@ export default class GoTrueClient {
51
48
  headers?: {
52
49
  [key: string]: string;
53
50
  };
51
+ storageKey?: string;
54
52
  detectSessionInUrl?: boolean;
55
53
  autoRefreshToken?: boolean;
56
54
  persistSession?: boolean;
57
- localStorage?: SupportedStorage;
55
+ storage?: SupportedStorage;
58
56
  multiTab?: boolean;
59
- cookieOptions?: CookieOptions;
60
57
  fetch?: Fetch;
61
58
  });
62
59
  /**
@@ -65,72 +62,60 @@ export default class GoTrueClient {
65
62
  * @param email The user's email address.
66
63
  * @param password The user's password.
67
64
  * @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.
65
+ * @param options.redirectTo The redirect URL attached to the signup confirmation link. Does not redirect the user if it's a mobile signup.
66
+ * @param options.data Optional user metadata.
67
+ * @param options.captchaToken Verification token received when the user completes the captcha on the site.
68
+ *
69
+ * @returns A logged-in session if the server has "autoconfirm" ON
70
+ * @returns A user if the server has "autoconfirm" OFF
70
71
  */
71
72
  signUp({ email, password, phone }: UserCredentials, options?: {
72
73
  redirectTo?: string;
73
74
  data?: object;
74
75
  captchaToken?: string;
75
- }): Promise<{
76
- user: User | null;
77
- session: Session | null;
78
- error: ApiError | null;
79
- }>;
76
+ }): Promise<AuthResponse>;
80
77
  /**
81
78
  * Log in an existing user, or login via a third-party provider.
82
- * @type UserCredentials
79
+ * @type SignInWithPasswordCredentials
83
80
  * @param email The user's email address.
84
81
  * @param phone The user's phone number.
85
82
  * @param password The user's password.
86
- * @param refreshToken A valid refresh token that was returned on login.
83
+ * @param options.captchaToken Verification token received when the user completes the captcha on the site.
84
+ */
85
+ signInWithPassword(credentials: SignInWithPasswordCredentials): Promise<AuthResponse>;
86
+ /**
87
+ * Log in an existing user via a third-party provider.
88
+ * @type SignInWithOAuthCredentials
87
89
  * @param provider One of the providers supported by GoTrue.
88
90
  * @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
+ * @param options.scopes A space-separated list of scopes granted to the OAuth application.
92
+ * @param options.queryParams An object of query params
93
+ * @param options.captchaToken Verification token received when the user completes the captcha on the site.
91
94
  */
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
- }>;
95
+ signInWithOAuth(credentials: SignInWithOAuthCredentials): Promise<OAuthResponse>;
96
+ /**
97
+ * Passwordless method for logging in an existing user.
98
+ * @type SignInWithPasswordlessCredentials
99
+ * @param email The user's email address.
100
+ * @param phone The user's phone number.
101
+ * @param options.captchaToken Verification token received when the user completes the captcha on the site.
102
+ * @param options.emailRedirectTo The redirect url sent in the magiclink. The url will be appended to the end of the magiclink url. Does not serve to redirect the user after this method is invoked.
103
+ * @param options.shouldCreateUser If set to false, signInWithOtp will not create a new user if the user does not exist. Defaults to true.
104
+ */
105
+ signInWithOtp(credentials: SignInWithPasswordlessCredentials): Promise<AuthResponse>;
107
106
  /**
108
107
  * Log in a user given a User supplied OTP received via mobile.
109
108
  * @param email The user's email address.
110
109
  * @param phone The user's phone number.
111
110
  * @param token The user's password.
112
111
  * @param type The user's verification type.
113
- * @param redirectTo A URL or mobile address to send the user to after they are confirmed.
112
+ * @param options.redirectTo A URL to send the user to after they are confirmed.
113
+ * @param options.captchaToken An optional captcha verification token.
114
114
  */
115
115
  verifyOTP(params: VerifyOTPParams, options?: {
116
116
  redirectTo?: string;
117
- }): Promise<{
118
- user: User | null;
119
- session: Session | null;
120
- error: ApiError | null;
121
- }>;
122
- /**
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
127
- */
128
- user(): User | null;
129
- /**
130
- * Returns the session data, if there is an active session.
131
- * @deprecated use `getSession()` instead
132
- */
133
- session(): Session | null;
117
+ captchaToken?: string;
118
+ }): Promise<AuthResponse>;
134
119
  /**
135
120
  * Returns the session data, refreshing it if necessary.
136
121
  */
@@ -139,90 +124,73 @@ export default class GoTrueClient {
139
124
  error: null;
140
125
  } | {
141
126
  session: null;
142
- error: ApiError;
127
+ error: AuthError;
143
128
  } | {
144
129
  session: null;
145
130
  error: null;
146
131
  }>;
147
132
  /**
148
- * Returns the user data, refreshing the session if necessary.
149
- */
150
- getUser(): Promise<{
151
- user: User;
152
- error: null;
153
- } | {
154
- user: null;
155
- error: ApiError;
156
- } | {
157
- user: null;
158
- error: null;
159
- }>;
160
- /**
161
- * Force refreshes the session including the user data in case it was updated in a different session.
133
+ * Gets the current user details if there is an existing session.
162
134
  */
163
- refreshSession(): Promise<{
164
- data: Session | null;
165
- user: User | null;
166
- error: ApiError | null;
167
- }>;
135
+ getUser(): Promise<UserResponse>;
168
136
  /**
169
137
  * Updates user data, if there is a logged in user.
138
+ * @param attributes The data you want to update.
170
139
  */
171
- update(attributes: UserAttributes): Promise<{
172
- data: User | null;
173
- user: User | null;
174
- error: ApiError | null;
175
- }>;
140
+ updateUser(attributes: UserAttributes): Promise<UserResponse>;
176
141
  /**
177
142
  * Sets the session data from refresh_token and returns current Session and Error
178
143
  * @param refresh_token a JWT token
179
144
  */
180
- setSession(refresh_token: string): Promise<{
181
- session: Session | null;
182
- error: ApiError | null;
183
- }>;
184
- /**
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)
188
- */
189
- setAuth(access_token: string): Session;
145
+ setSession(refresh_token: string): Promise<AuthResponse>;
190
146
  /**
191
147
  * Gets the session data from a URL string
192
- * @param options.storeSession Optionally store the session in the browser
148
+ * @param options.storeSession Optionally store the session in the browser or in-memory
193
149
  */
194
- getSessionFromUrl(options?: {
195
- storeSession?: boolean;
196
- }): Promise<{
197
- data: Session | null;
198
- error: ApiError | null;
199
- }>;
150
+ private _getSessionFromUrl;
200
151
  /**
201
152
  * Inside a browser context, `signOut()` will remove the logged in user from the browser session
202
153
  * and log them out - removing all items from localstorage and then trigger a "SIGNED_OUT" event.
203
154
  *
204
- * For server-side management, you can disable sessions by passing a JWT through to `auth.api.signOut(JWT: string)`
155
+ * 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)`. There is no way to revoke a user's session JWT before it automatically expires
205
156
  */
206
157
  signOut(): Promise<{
207
- error: ApiError | null;
158
+ error: AuthError | null;
208
159
  }>;
209
160
  /**
210
161
  * Receive a notification every time an auth event happens.
211
162
  * @returns {Subscription} A subscription object which can be used to unsubscribe itself.
212
163
  */
213
164
  onAuthStateChange(callback: (event: AuthChangeEvent, session: Session | null) => void): {
214
- data: Subscription | null;
215
- error: ApiError | null;
165
+ subscription: Subscription;
166
+ error: null;
167
+ } | {
168
+ subscription: null;
169
+ error: AuthError;
216
170
  };
217
- private _handleEmailSignIn;
218
- private _handlePhoneSignIn;
219
- private _handleProviderSignIn;
220
- private _handleOpenIDConnectSignIn;
221
171
  /**
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.
172
+ * Sends a reset request to an email address.
173
+ * @param email The email address of the user.
174
+ * @param options.redirectTo A URL to send the user to after they are confirmed.
175
+ * @param options.captchaToken Verification token received when the user completes the captcha on the site.
224
176
  */
225
- private _recoverSession;
177
+ resetPasswordForEmail(email: string, options?: {
178
+ redirectTo?: string;
179
+ captchaToken?: string;
180
+ }): Promise<{
181
+ data: {};
182
+ error: null;
183
+ } | {
184
+ data: null;
185
+ error: AuthError;
186
+ }>;
187
+ /**
188
+ * Generates a new JWT.
189
+ * @param refreshToken A valid refresh token that was returned on login.
190
+ */
191
+ private _refreshAccessToken;
192
+ private _doesSessionExist;
193
+ private _handleProviderSignIn;
226
194
  /**
227
195
  * Recovers the session from LocalStorage and refreshes
228
196
  * Note: this method is async to accommodate for AsyncStorage e.g. in React native.
@@ -242,10 +210,14 @@ export default class GoTrueClient {
242
210
  * @param value time intervals in milliseconds
243
211
  */
244
212
  private _startAutoRefreshToken;
213
+ private _handleVisibilityChange;
245
214
  /**
246
- * Listens for changes to LocalStorage and updates the current session.
215
+ * Generates the relevant login URL for a third-party provider.
216
+ * @param provider One of the providers supported by GoTrue.
217
+ * @param options.redirectTo A URL or mobile address to send the user to after they are confirmed.
218
+ * @param options.scopes A space-separated list of scopes granted to the OAuth application.
219
+ * @param options.queryParams An object of key-value pairs containing query parameters granted to the OAuth application.
247
220
  */
248
- private _listenForMultiTabEvents;
249
- private _handleVisibilityChange;
221
+ private _getUrlForProvider;
250
222
  }
251
223
  //# sourceMappingURL=GoTrueClient.d.ts.map