@supabase/gotrue-js 1.18.0 → 1.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -1
- package/dist/main/GoTrueApi.d.ts +52 -17
- package/dist/main/GoTrueApi.d.ts.map +1 -1
- package/dist/main/GoTrueApi.js +118 -74
- package/dist/main/GoTrueApi.js.map +1 -1
- package/dist/main/GoTrueClient.d.ts +13 -10
- package/dist/main/GoTrueClient.d.ts.map +1 -1
- package/dist/main/GoTrueClient.js +49 -55
- package/dist/main/GoTrueClient.js.map +1 -1
- package/dist/main/lib/cookies.d.ts.map +1 -1
- package/dist/main/lib/cookies.js +1 -0
- package/dist/main/lib/cookies.js.map +1 -1
- package/dist/main/lib/fetch.d.ts +5 -4
- package/dist/main/lib/fetch.d.ts.map +1 -1
- package/dist/main/lib/fetch.js +10 -10
- package/dist/main/lib/fetch.js.map +1 -1
- package/dist/main/lib/helpers.d.ts.map +1 -1
- package/dist/main/lib/helpers.js +7 -4
- package/dist/main/lib/helpers.js.map +1 -1
- package/dist/main/lib/polyfills.d.ts.map +1 -1
- package/dist/main/lib/polyfills.js +3 -1
- package/dist/main/lib/polyfills.js.map +1 -1
- package/dist/main/lib/types.d.ts +2 -1
- package/dist/main/lib/types.d.ts.map +1 -1
- package/dist/main/lib/version.d.ts +1 -1
- package/dist/main/lib/version.js +1 -1
- package/dist/module/GoTrueApi.d.ts +52 -17
- package/dist/module/GoTrueApi.d.ts.map +1 -1
- package/dist/module/GoTrueApi.js +111 -67
- package/dist/module/GoTrueApi.js.map +1 -1
- package/dist/module/GoTrueClient.d.ts +13 -10
- package/dist/module/GoTrueClient.d.ts.map +1 -1
- package/dist/module/GoTrueClient.js +34 -40
- package/dist/module/GoTrueClient.js.map +1 -1
- package/dist/module/lib/cookies.d.ts.map +1 -1
- package/dist/module/lib/cookies.js +1 -0
- package/dist/module/lib/cookies.js.map +1 -1
- package/dist/module/lib/fetch.d.ts +5 -4
- package/dist/module/lib/fetch.d.ts.map +1 -1
- package/dist/module/lib/fetch.js +11 -11
- package/dist/module/lib/fetch.js.map +1 -1
- package/dist/module/lib/helpers.d.ts.map +1 -1
- package/dist/module/lib/helpers.js +5 -3
- package/dist/module/lib/helpers.js.map +1 -1
- package/dist/module/lib/polyfills.d.ts.map +1 -1
- package/dist/module/lib/polyfills.js +3 -1
- package/dist/module/lib/polyfills.js.map +1 -1
- package/dist/module/lib/types.d.ts +2 -1
- package/dist/module/lib/types.d.ts.map +1 -1
- package/dist/module/lib/version.d.ts +1 -1
- package/dist/module/lib/version.js +1 -1
- package/package.json +18 -9
- package/src/GoTrueApi.ts +159 -77
- package/src/GoTrueClient.ts +50 -52
- package/src/lib/cookies.ts +1 -0
- package/src/lib/fetch.ts +32 -10
- package/src/lib/helpers.ts +4 -3
- package/src/lib/polyfills.ts +3 -2
- package/src/lib/types.ts +3 -0
- package/src/lib/version.ts +1 -1
package/README.md
CHANGED
|
@@ -29,10 +29,22 @@ const auth = new GoTrueClient({ url: GOTRUE_URL })
|
|
|
29
29
|
- `signIn()`: https://supabase.io/docs/reference/javascript/auth-signin
|
|
30
30
|
- `signOut()`: https://supabase.io/docs/reference/javascript/auth-signout
|
|
31
31
|
|
|
32
|
+
### Custom `fetch` implementation
|
|
33
|
+
|
|
34
|
+
`gotrue-js` uses the [`cross-fetch`](https://www.npmjs.com/package/cross-fetch) library to make HTTP requests, but an alternative `fetch` implementation can be provided as an option. This is most useful in environments where `cross-fetch` is not compatible, for instance Cloudflare Workers:
|
|
35
|
+
|
|
36
|
+
```js
|
|
37
|
+
import { GoTrueClient } from '@supabase/gotrue-js'
|
|
38
|
+
|
|
39
|
+
const GOTRUE_URL = 'http://localhost:9999'
|
|
40
|
+
|
|
41
|
+
const auth = new GoTrueClient({ url: GOTRUE_URL, fetch: fetch })
|
|
42
|
+
```
|
|
43
|
+
|
|
32
44
|
## Sponsors
|
|
33
45
|
|
|
34
46
|
We are building the features of Firebase using enterprise-grade, open source products. We support existing communities wherever possible, and if the products don’t exist we build them and open source them ourselves.
|
|
35
47
|
|
|
36
48
|
[](https://github.com/sponsors/supabase)
|
|
37
49
|
|
|
38
|
-

|
package/dist/main/GoTrueApi.d.ts
CHANGED
|
@@ -1,17 +1,51 @@
|
|
|
1
|
+
import { Fetch } from './lib/fetch';
|
|
1
2
|
import { Session, Provider, UserAttributes, CookieOptions, User } from './lib/types';
|
|
3
|
+
export interface ApiError {
|
|
4
|
+
message: string;
|
|
5
|
+
status: number;
|
|
6
|
+
}
|
|
2
7
|
export default class GoTrueApi {
|
|
3
8
|
protected url: string;
|
|
4
9
|
protected headers: {
|
|
5
10
|
[key: string]: string;
|
|
6
11
|
};
|
|
7
12
|
protected cookieOptions: CookieOptions;
|
|
8
|
-
|
|
13
|
+
protected fetch?: Fetch;
|
|
14
|
+
constructor({ url, headers, cookieOptions, fetch, }: {
|
|
9
15
|
url: string;
|
|
10
16
|
headers?: {
|
|
11
17
|
[key: string]: string;
|
|
12
18
|
};
|
|
13
19
|
cookieOptions?: CookieOptions;
|
|
20
|
+
fetch?: Fetch;
|
|
14
21
|
});
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new user.
|
|
24
|
+
*
|
|
25
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
26
|
+
*
|
|
27
|
+
* @param attributes The data you want to create the user with.
|
|
28
|
+
* @param jwt A valid JWT. Must be a full-access API key (e.g. service_role key).
|
|
29
|
+
*/
|
|
30
|
+
createUser(attributes: UserAttributes): Promise<{
|
|
31
|
+
data: null;
|
|
32
|
+
error: ApiError;
|
|
33
|
+
} | {
|
|
34
|
+
data: User;
|
|
35
|
+
error: null;
|
|
36
|
+
}>;
|
|
37
|
+
/**
|
|
38
|
+
* Get a list of users.
|
|
39
|
+
*
|
|
40
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
41
|
+
*/
|
|
42
|
+
listUsers(): Promise<{
|
|
43
|
+
data: null;
|
|
44
|
+
error: ApiError;
|
|
45
|
+
} | {
|
|
46
|
+
data: User[];
|
|
47
|
+
error: null;
|
|
48
|
+
}>;
|
|
15
49
|
/**
|
|
16
50
|
* Creates a new user using their email address.
|
|
17
51
|
* @param email The email address of the user.
|
|
@@ -27,7 +61,7 @@ export default class GoTrueApi {
|
|
|
27
61
|
data?: object;
|
|
28
62
|
}): Promise<{
|
|
29
63
|
data: Session | User | null;
|
|
30
|
-
error:
|
|
64
|
+
error: ApiError | null;
|
|
31
65
|
}>;
|
|
32
66
|
/**
|
|
33
67
|
* Logs in an existing user using their email address.
|
|
@@ -39,7 +73,7 @@ export default class GoTrueApi {
|
|
|
39
73
|
redirectTo?: string;
|
|
40
74
|
}): Promise<{
|
|
41
75
|
data: Session | null;
|
|
42
|
-
error:
|
|
76
|
+
error: ApiError | null;
|
|
43
77
|
}>;
|
|
44
78
|
/**
|
|
45
79
|
* Signs up a new user using their phone number and a password.
|
|
@@ -51,7 +85,7 @@ export default class GoTrueApi {
|
|
|
51
85
|
data?: object;
|
|
52
86
|
}): Promise<{
|
|
53
87
|
data: Session | User | null;
|
|
54
|
-
error:
|
|
88
|
+
error: ApiError | null;
|
|
55
89
|
}>;
|
|
56
90
|
/**
|
|
57
91
|
* Logs in an existing user using their phone number and password.
|
|
@@ -60,7 +94,7 @@ export default class GoTrueApi {
|
|
|
60
94
|
*/
|
|
61
95
|
signInWithPhone(phone: string, password: string): Promise<{
|
|
62
96
|
data: Session | null;
|
|
63
|
-
error:
|
|
97
|
+
error: ApiError | null;
|
|
64
98
|
}>;
|
|
65
99
|
/**
|
|
66
100
|
* Sends a magic login link to an email address.
|
|
@@ -71,7 +105,7 @@ export default class GoTrueApi {
|
|
|
71
105
|
redirectTo?: string;
|
|
72
106
|
}): Promise<{
|
|
73
107
|
data: {} | null;
|
|
74
|
-
error:
|
|
108
|
+
error: ApiError | null;
|
|
75
109
|
}>;
|
|
76
110
|
/**
|
|
77
111
|
* Sends a mobile OTP via SMS. Will register the account if it doesn't already exist
|
|
@@ -79,7 +113,7 @@ export default class GoTrueApi {
|
|
|
79
113
|
*/
|
|
80
114
|
sendMobileOTP(phone: string): Promise<{
|
|
81
115
|
data: {} | null;
|
|
82
|
-
error:
|
|
116
|
+
error: ApiError | null;
|
|
83
117
|
}>;
|
|
84
118
|
/**
|
|
85
119
|
* Send User supplied Mobile OTP to be verified
|
|
@@ -91,7 +125,7 @@ export default class GoTrueApi {
|
|
|
91
125
|
redirectTo?: string;
|
|
92
126
|
}): Promise<{
|
|
93
127
|
data: Session | User | null;
|
|
94
|
-
error:
|
|
128
|
+
error: ApiError | null;
|
|
95
129
|
}>;
|
|
96
130
|
/**
|
|
97
131
|
* Sends an invite link to an email address.
|
|
@@ -104,7 +138,7 @@ export default class GoTrueApi {
|
|
|
104
138
|
data?: object;
|
|
105
139
|
}): Promise<{
|
|
106
140
|
data: User | null;
|
|
107
|
-
error:
|
|
141
|
+
error: ApiError | null;
|
|
108
142
|
}>;
|
|
109
143
|
/**
|
|
110
144
|
* Sends a reset request to an email address.
|
|
@@ -115,7 +149,7 @@ export default class GoTrueApi {
|
|
|
115
149
|
redirectTo?: string;
|
|
116
150
|
}): Promise<{
|
|
117
151
|
data: {} | null;
|
|
118
|
-
error:
|
|
152
|
+
error: ApiError | null;
|
|
119
153
|
}>;
|
|
120
154
|
/**
|
|
121
155
|
* Create a temporary object with all configured headers and
|
|
@@ -128,7 +162,7 @@ export default class GoTrueApi {
|
|
|
128
162
|
* @param jwt A valid, logged-in JWT.
|
|
129
163
|
*/
|
|
130
164
|
signOut(jwt: string): Promise<{
|
|
131
|
-
error:
|
|
165
|
+
error: ApiError | null;
|
|
132
166
|
}>;
|
|
133
167
|
/**
|
|
134
168
|
* Generates the relevant login URL for a third-party provider.
|
|
@@ -147,7 +181,7 @@ export default class GoTrueApi {
|
|
|
147
181
|
getUser(jwt: string): Promise<{
|
|
148
182
|
user: User | null;
|
|
149
183
|
data: User | null;
|
|
150
|
-
error:
|
|
184
|
+
error: ApiError | null;
|
|
151
185
|
}>;
|
|
152
186
|
/**
|
|
153
187
|
* Updates the user data.
|
|
@@ -157,7 +191,7 @@ export default class GoTrueApi {
|
|
|
157
191
|
updateUser(jwt: string, attributes: UserAttributes): Promise<{
|
|
158
192
|
user: User | null;
|
|
159
193
|
data: User | null;
|
|
160
|
-
error:
|
|
194
|
+
error: ApiError | null;
|
|
161
195
|
}>;
|
|
162
196
|
/**
|
|
163
197
|
* Delete a user. Requires a `service_role` key.
|
|
@@ -170,7 +204,7 @@ export default class GoTrueApi {
|
|
|
170
204
|
deleteUser(uid: string, jwt: string): Promise<{
|
|
171
205
|
user: User | null;
|
|
172
206
|
data: User | null;
|
|
173
|
-
error:
|
|
207
|
+
error: ApiError | null;
|
|
174
208
|
}>;
|
|
175
209
|
/**
|
|
176
210
|
* Generates a new JWT.
|
|
@@ -178,7 +212,7 @@ export default class GoTrueApi {
|
|
|
178
212
|
*/
|
|
179
213
|
refreshAccessToken(refreshToken: string): Promise<{
|
|
180
214
|
data: Session | null;
|
|
181
|
-
error:
|
|
215
|
+
error: ApiError | null;
|
|
182
216
|
}>;
|
|
183
217
|
/**
|
|
184
218
|
* Set/delete the auth cookie based on the AuthChangeEvent.
|
|
@@ -190,9 +224,10 @@ export default class GoTrueApi {
|
|
|
190
224
|
* Works for Next.js & Express (requires cookie-parser middleware).
|
|
191
225
|
*/
|
|
192
226
|
getUserByCookie(req: any): Promise<{
|
|
227
|
+
token: string | null;
|
|
193
228
|
user: User | null;
|
|
194
229
|
data: User | null;
|
|
195
|
-
error:
|
|
230
|
+
error: ApiError | null;
|
|
196
231
|
}>;
|
|
197
232
|
/**
|
|
198
233
|
* Generates links to be sent via email or other.
|
|
@@ -208,7 +243,7 @@ export default class GoTrueApi {
|
|
|
208
243
|
redirectTo?: string;
|
|
209
244
|
}): Promise<{
|
|
210
245
|
data: Session | User | null;
|
|
211
|
-
error:
|
|
246
|
+
error: ApiError | null;
|
|
212
247
|
}>;
|
|
213
248
|
}
|
|
214
249
|
//# sourceMappingURL=GoTrueApi.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GoTrueApi.d.ts","sourceRoot":"","sources":["../../src/GoTrueApi.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"GoTrueApi.d.ts","sourceRoot":"","sources":["../../src/GoTrueApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAA0B,MAAM,aAAa,CAAA;AAC3D,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAKpF,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,CAAC,OAAO,OAAO,SAAS;IAC5B,SAAS,CAAC,GAAG,EAAE,MAAM,CAAA;IACrB,SAAS,CAAC,OAAO,EAAE;QACjB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KACtB,CAAA;IACD,SAAS,CAAC,aAAa,EAAE,aAAa,CAAA;IACtC,SAAS,CAAC,KAAK,CAAC,EAAE,KAAK,CAAA;gBAEX,EACV,GAAQ,EACR,OAAY,EACZ,aAAa,EACb,KAAK,GACN,EAAE;QACD,GAAG,EAAE,MAAM,CAAA;QACX,OAAO,CAAC,EAAE;YACR,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;SACtB,CAAA;QACD,aAAa,CAAC,EAAE,aAAa,CAAA;QAC7B,KAAK,CAAC,EAAE,KAAK,CAAA;KACd;IAOD;;;;;;;OAOG;IACG,UAAU,CACd,UAAU,EAAE,cAAc,GACzB,OAAO,CAAC;QAAE,IAAI,EAAE,IAAI,CAAC;QAAC,KAAK,EAAE,QAAQ,CAAA;KAAE,GAAG;QAAE,IAAI,EAAE,IAAI,CAAC;QAAC,KAAK,EAAE,IAAI,CAAA;KAAE,CAAC;IAWzE;;;;OAIG;IACG,SAAS,IAAI,OAAO,CAA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,EAAE,IAAI,GAAG,IAAI,CAAA;QACjB,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAA;KACvB,CAAC;IAmBF;;;;;;;OAOG;IACG,YAAY,CAChB,IAAI,EAAE,QAAQ,GAAG,WAAW,GAAG,UAAU,GAAG,QAAQ,EACpD,KAAK,EAAE,MAAM,EACb,OAAO,GAAE;QACP,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,UAAU,CAAC,EAAE,MAAM,CAAA;KACf,GACL,OAAO,CAAC;QAAE,IAAI,EAAE,OAAO,GAAG,IAAI,GAAG,IAAI,CAAC;QAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAA;KAAE,CAAC;CAmBpE"}
|
package/dist/main/GoTrueApi.js
CHANGED
|
@@ -14,10 +14,50 @@ const constants_1 = require("./lib/constants");
|
|
|
14
14
|
const cookies_1 = require("./lib/cookies");
|
|
15
15
|
const helpers_1 = require("./lib/helpers");
|
|
16
16
|
class GoTrueApi {
|
|
17
|
-
constructor({ url = '', headers = {}, cookieOptions, }) {
|
|
17
|
+
constructor({ url = '', headers = {}, cookieOptions, fetch, }) {
|
|
18
18
|
this.url = url;
|
|
19
19
|
this.headers = headers;
|
|
20
20
|
this.cookieOptions = Object.assign(Object.assign({}, constants_1.COOKIE_OPTIONS), cookieOptions);
|
|
21
|
+
this.fetch = fetch;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new user.
|
|
25
|
+
*
|
|
26
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
27
|
+
*
|
|
28
|
+
* @param attributes The data you want to create the user with.
|
|
29
|
+
* @param jwt A valid JWT. Must be a full-access API key (e.g. service_role key).
|
|
30
|
+
*/
|
|
31
|
+
createUser(attributes) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
try {
|
|
34
|
+
const data = yield (0, fetch_1.post)(this.fetch, `${this.url}/admin/users`, attributes, {
|
|
35
|
+
headers: this.headers,
|
|
36
|
+
});
|
|
37
|
+
return { data, error: null };
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
return { data: null, error: e };
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get a list of users.
|
|
46
|
+
*
|
|
47
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
48
|
+
*/
|
|
49
|
+
listUsers() {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
try {
|
|
52
|
+
const data = yield (0, fetch_1.get)(this.fetch, `${this.url}/admin/users`, {
|
|
53
|
+
headers: this.headers,
|
|
54
|
+
});
|
|
55
|
+
return { data: data.users, error: null };
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
return { data: null, error: e };
|
|
59
|
+
}
|
|
60
|
+
});
|
|
21
61
|
}
|
|
22
62
|
/**
|
|
23
63
|
* Creates a new user using their email address.
|
|
@@ -32,19 +72,19 @@ class GoTrueApi {
|
|
|
32
72
|
signUpWithEmail(email, password, options = {}) {
|
|
33
73
|
return __awaiter(this, void 0, void 0, function* () {
|
|
34
74
|
try {
|
|
35
|
-
|
|
75
|
+
const headers = Object.assign({}, this.headers);
|
|
36
76
|
let queryString = '';
|
|
37
77
|
if (options.redirectTo) {
|
|
38
78
|
queryString = '?redirect_to=' + encodeURIComponent(options.redirectTo);
|
|
39
79
|
}
|
|
40
|
-
const data = yield fetch_1.post(`${this.url}/signup${queryString}`, { email, password, data: options.data }, { headers });
|
|
41
|
-
|
|
80
|
+
const data = yield (0, fetch_1.post)(this.fetch, `${this.url}/signup${queryString}`, { email, password, data: options.data }, { headers });
|
|
81
|
+
const session = Object.assign({}, data);
|
|
42
82
|
if (session.expires_in)
|
|
43
|
-
session.expires_at = helpers_1.expiresAt(data.expires_in);
|
|
83
|
+
session.expires_at = (0, helpers_1.expiresAt)(data.expires_in);
|
|
44
84
|
return { data: session, error: null };
|
|
45
85
|
}
|
|
46
|
-
catch (
|
|
47
|
-
return { data: null, error };
|
|
86
|
+
catch (e) {
|
|
87
|
+
return { data: null, error: e };
|
|
48
88
|
}
|
|
49
89
|
});
|
|
50
90
|
}
|
|
@@ -57,19 +97,19 @@ class GoTrueApi {
|
|
|
57
97
|
signInWithEmail(email, password, options = {}) {
|
|
58
98
|
return __awaiter(this, void 0, void 0, function* () {
|
|
59
99
|
try {
|
|
60
|
-
|
|
100
|
+
const headers = Object.assign({}, this.headers);
|
|
61
101
|
let queryString = '?grant_type=password';
|
|
62
102
|
if (options.redirectTo) {
|
|
63
103
|
queryString += '&redirect_to=' + encodeURIComponent(options.redirectTo);
|
|
64
104
|
}
|
|
65
|
-
const data = yield fetch_1.post(`${this.url}/token${queryString}`, { email, password }, { headers });
|
|
66
|
-
|
|
105
|
+
const data = yield (0, fetch_1.post)(this.fetch, `${this.url}/token${queryString}`, { email, password }, { headers });
|
|
106
|
+
const session = Object.assign({}, data);
|
|
67
107
|
if (session.expires_in)
|
|
68
|
-
session.expires_at = helpers_1.expiresAt(data.expires_in);
|
|
108
|
+
session.expires_at = (0, helpers_1.expiresAt)(data.expires_in);
|
|
69
109
|
return { data: session, error: null };
|
|
70
110
|
}
|
|
71
|
-
catch (
|
|
72
|
-
return { data: null, error };
|
|
111
|
+
catch (e) {
|
|
112
|
+
return { data: null, error: e };
|
|
73
113
|
}
|
|
74
114
|
});
|
|
75
115
|
}
|
|
@@ -82,15 +122,15 @@ class GoTrueApi {
|
|
|
82
122
|
signUpWithPhone(phone, password, options = {}) {
|
|
83
123
|
return __awaiter(this, void 0, void 0, function* () {
|
|
84
124
|
try {
|
|
85
|
-
|
|
86
|
-
const data = yield fetch_1.post(`${this.url}/signup`, { phone, password, data: options.data }, { headers });
|
|
87
|
-
|
|
125
|
+
const headers = Object.assign({}, this.headers);
|
|
126
|
+
const data = yield (0, fetch_1.post)(this.fetch, `${this.url}/signup`, { phone, password, data: options.data }, { headers });
|
|
127
|
+
const session = Object.assign({}, data);
|
|
88
128
|
if (session.expires_in)
|
|
89
|
-
session.expires_at = helpers_1.expiresAt(data.expires_in);
|
|
129
|
+
session.expires_at = (0, helpers_1.expiresAt)(data.expires_in);
|
|
90
130
|
return { data: session, error: null };
|
|
91
131
|
}
|
|
92
|
-
catch (
|
|
93
|
-
return { data: null, error };
|
|
132
|
+
catch (e) {
|
|
133
|
+
return { data: null, error: e };
|
|
94
134
|
}
|
|
95
135
|
});
|
|
96
136
|
}
|
|
@@ -102,16 +142,16 @@ class GoTrueApi {
|
|
|
102
142
|
signInWithPhone(phone, password) {
|
|
103
143
|
return __awaiter(this, void 0, void 0, function* () {
|
|
104
144
|
try {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const data = yield fetch_1.post(`${this.url}/token${queryString}`, { phone, password }, { headers });
|
|
108
|
-
|
|
145
|
+
const headers = Object.assign({}, this.headers);
|
|
146
|
+
const queryString = '?grant_type=password';
|
|
147
|
+
const data = yield (0, fetch_1.post)(this.fetch, `${this.url}/token${queryString}`, { phone, password }, { headers });
|
|
148
|
+
const session = Object.assign({}, data);
|
|
109
149
|
if (session.expires_in)
|
|
110
|
-
session.expires_at = helpers_1.expiresAt(data.expires_in);
|
|
150
|
+
session.expires_at = (0, helpers_1.expiresAt)(data.expires_in);
|
|
111
151
|
return { data: session, error: null };
|
|
112
152
|
}
|
|
113
|
-
catch (
|
|
114
|
-
return { data: null, error };
|
|
153
|
+
catch (e) {
|
|
154
|
+
return { data: null, error: e };
|
|
115
155
|
}
|
|
116
156
|
});
|
|
117
157
|
}
|
|
@@ -123,16 +163,16 @@ class GoTrueApi {
|
|
|
123
163
|
sendMagicLinkEmail(email, options = {}) {
|
|
124
164
|
return __awaiter(this, void 0, void 0, function* () {
|
|
125
165
|
try {
|
|
126
|
-
|
|
166
|
+
const headers = Object.assign({}, this.headers);
|
|
127
167
|
let queryString = '';
|
|
128
168
|
if (options.redirectTo) {
|
|
129
169
|
queryString += '?redirect_to=' + encodeURIComponent(options.redirectTo);
|
|
130
170
|
}
|
|
131
|
-
const data = yield fetch_1.post(`${this.url}/magiclink${queryString}`, { email }, { headers });
|
|
171
|
+
const data = yield (0, fetch_1.post)(this.fetch, `${this.url}/magiclink${queryString}`, { email }, { headers });
|
|
132
172
|
return { data, error: null };
|
|
133
173
|
}
|
|
134
|
-
catch (
|
|
135
|
-
return { data: null, error };
|
|
174
|
+
catch (e) {
|
|
175
|
+
return { data: null, error: e };
|
|
136
176
|
}
|
|
137
177
|
});
|
|
138
178
|
}
|
|
@@ -143,12 +183,12 @@ class GoTrueApi {
|
|
|
143
183
|
sendMobileOTP(phone) {
|
|
144
184
|
return __awaiter(this, void 0, void 0, function* () {
|
|
145
185
|
try {
|
|
146
|
-
|
|
147
|
-
const data = yield fetch_1.post(`${this.url}/otp`, { phone }, { headers });
|
|
186
|
+
const headers = Object.assign({}, this.headers);
|
|
187
|
+
const data = yield (0, fetch_1.post)(this.fetch, `${this.url}/otp`, { phone }, { headers });
|
|
148
188
|
return { data, error: null };
|
|
149
189
|
}
|
|
150
|
-
catch (
|
|
151
|
-
return { data: null, error };
|
|
190
|
+
catch (e) {
|
|
191
|
+
return { data: null, error: e };
|
|
152
192
|
}
|
|
153
193
|
});
|
|
154
194
|
}
|
|
@@ -161,12 +201,12 @@ class GoTrueApi {
|
|
|
161
201
|
verifyMobileOTP(phone, token, options = {}) {
|
|
162
202
|
return __awaiter(this, void 0, void 0, function* () {
|
|
163
203
|
try {
|
|
164
|
-
|
|
165
|
-
const data = yield fetch_1.post(`${this.url}/verify`, { phone, token, type: 'sms', redirect_to: options.redirectTo }, { headers });
|
|
204
|
+
const headers = Object.assign({}, this.headers);
|
|
205
|
+
const data = yield (0, fetch_1.post)(this.fetch, `${this.url}/verify`, { phone, token, type: 'sms', redirect_to: options.redirectTo }, { headers });
|
|
166
206
|
return { data, error: null };
|
|
167
207
|
}
|
|
168
|
-
catch (
|
|
169
|
-
return { data: null, error };
|
|
208
|
+
catch (e) {
|
|
209
|
+
return { data: null, error: e };
|
|
170
210
|
}
|
|
171
211
|
});
|
|
172
212
|
}
|
|
@@ -179,16 +219,16 @@ class GoTrueApi {
|
|
|
179
219
|
inviteUserByEmail(email, options = {}) {
|
|
180
220
|
return __awaiter(this, void 0, void 0, function* () {
|
|
181
221
|
try {
|
|
182
|
-
|
|
222
|
+
const headers = Object.assign({}, this.headers);
|
|
183
223
|
let queryString = '';
|
|
184
224
|
if (options.redirectTo) {
|
|
185
225
|
queryString += '?redirect_to=' + encodeURIComponent(options.redirectTo);
|
|
186
226
|
}
|
|
187
|
-
const data = yield fetch_1.post(`${this.url}/invite${queryString}`, { email, data: options.data }, { headers });
|
|
227
|
+
const data = yield (0, fetch_1.post)(this.fetch, `${this.url}/invite${queryString}`, { email, data: options.data }, { headers });
|
|
188
228
|
return { data, error: null };
|
|
189
229
|
}
|
|
190
|
-
catch (
|
|
191
|
-
return { data: null, error };
|
|
230
|
+
catch (e) {
|
|
231
|
+
return { data: null, error: e };
|
|
192
232
|
}
|
|
193
233
|
});
|
|
194
234
|
}
|
|
@@ -200,16 +240,16 @@ class GoTrueApi {
|
|
|
200
240
|
resetPasswordForEmail(email, options = {}) {
|
|
201
241
|
return __awaiter(this, void 0, void 0, function* () {
|
|
202
242
|
try {
|
|
203
|
-
|
|
243
|
+
const headers = Object.assign({}, this.headers);
|
|
204
244
|
let queryString = '';
|
|
205
245
|
if (options.redirectTo) {
|
|
206
246
|
queryString += '?redirect_to=' + encodeURIComponent(options.redirectTo);
|
|
207
247
|
}
|
|
208
|
-
const data = yield fetch_1.post(`${this.url}/recover${queryString}`, { email }, { headers });
|
|
248
|
+
const data = yield (0, fetch_1.post)(this.fetch, `${this.url}/recover${queryString}`, { email }, { headers });
|
|
209
249
|
return { data, error: null };
|
|
210
250
|
}
|
|
211
|
-
catch (
|
|
212
|
-
return { data: null, error };
|
|
251
|
+
catch (e) {
|
|
252
|
+
return { data: null, error: e };
|
|
213
253
|
}
|
|
214
254
|
});
|
|
215
255
|
}
|
|
@@ -230,11 +270,11 @@ class GoTrueApi {
|
|
|
230
270
|
signOut(jwt) {
|
|
231
271
|
return __awaiter(this, void 0, void 0, function* () {
|
|
232
272
|
try {
|
|
233
|
-
yield fetch_1.post(`${this.url}/logout`, {}, { headers: this._createRequestHeaders(jwt), noResolveJson: true });
|
|
273
|
+
yield (0, fetch_1.post)(this.fetch, `${this.url}/logout`, {}, { headers: this._createRequestHeaders(jwt), noResolveJson: true });
|
|
234
274
|
return { error: null };
|
|
235
275
|
}
|
|
236
|
-
catch (
|
|
237
|
-
return { error };
|
|
276
|
+
catch (e) {
|
|
277
|
+
return { error: e };
|
|
238
278
|
}
|
|
239
279
|
});
|
|
240
280
|
}
|
|
@@ -245,7 +285,7 @@ class GoTrueApi {
|
|
|
245
285
|
* @param scopes A space-separated list of scopes granted to the OAuth application.
|
|
246
286
|
*/
|
|
247
287
|
getUrlForProvider(provider, options) {
|
|
248
|
-
|
|
288
|
+
const urlParams = [`provider=${encodeURIComponent(provider)}`];
|
|
249
289
|
if (options === null || options === void 0 ? void 0 : options.redirectTo) {
|
|
250
290
|
urlParams.push(`redirect_to=${encodeURIComponent(options.redirectTo)}`);
|
|
251
291
|
}
|
|
@@ -261,11 +301,13 @@ class GoTrueApi {
|
|
|
261
301
|
getUser(jwt) {
|
|
262
302
|
return __awaiter(this, void 0, void 0, function* () {
|
|
263
303
|
try {
|
|
264
|
-
const data = yield fetch_1.get(`${this.url}/user`, {
|
|
304
|
+
const data = yield (0, fetch_1.get)(this.fetch, `${this.url}/user`, {
|
|
305
|
+
headers: this._createRequestHeaders(jwt),
|
|
306
|
+
});
|
|
265
307
|
return { user: data, data, error: null };
|
|
266
308
|
}
|
|
267
|
-
catch (
|
|
268
|
-
return { user: null, data: null, error };
|
|
309
|
+
catch (e) {
|
|
310
|
+
return { user: null, data: null, error: e };
|
|
269
311
|
}
|
|
270
312
|
});
|
|
271
313
|
}
|
|
@@ -277,13 +319,13 @@ class GoTrueApi {
|
|
|
277
319
|
updateUser(jwt, attributes) {
|
|
278
320
|
return __awaiter(this, void 0, void 0, function* () {
|
|
279
321
|
try {
|
|
280
|
-
const data = yield fetch_1.put(`${this.url}/user`, attributes, {
|
|
322
|
+
const data = yield (0, fetch_1.put)(this.fetch, `${this.url}/user`, attributes, {
|
|
281
323
|
headers: this._createRequestHeaders(jwt),
|
|
282
324
|
});
|
|
283
325
|
return { user: data, data, error: null };
|
|
284
326
|
}
|
|
285
|
-
catch (
|
|
286
|
-
return { user: null, data: null, error };
|
|
327
|
+
catch (e) {
|
|
328
|
+
return { user: null, data: null, error: e };
|
|
287
329
|
}
|
|
288
330
|
});
|
|
289
331
|
}
|
|
@@ -298,13 +340,13 @@ class GoTrueApi {
|
|
|
298
340
|
deleteUser(uid, jwt) {
|
|
299
341
|
return __awaiter(this, void 0, void 0, function* () {
|
|
300
342
|
try {
|
|
301
|
-
const data = yield fetch_1.remove(`${this.url}/admin/users/${uid}`, {}, {
|
|
343
|
+
const data = yield (0, fetch_1.remove)(this.fetch, `${this.url}/admin/users/${uid}`, {}, {
|
|
302
344
|
headers: this._createRequestHeaders(jwt),
|
|
303
345
|
});
|
|
304
346
|
return { user: data, data, error: null };
|
|
305
347
|
}
|
|
306
|
-
catch (
|
|
307
|
-
return { user: null, data: null, error };
|
|
348
|
+
catch (e) {
|
|
349
|
+
return { user: null, data: null, error: e };
|
|
308
350
|
}
|
|
309
351
|
});
|
|
310
352
|
}
|
|
@@ -315,14 +357,14 @@ class GoTrueApi {
|
|
|
315
357
|
refreshAccessToken(refreshToken) {
|
|
316
358
|
return __awaiter(this, void 0, void 0, function* () {
|
|
317
359
|
try {
|
|
318
|
-
const data = yield fetch_1.post(`${this.url}/token?grant_type=refresh_token`, { refresh_token: refreshToken }, { headers: this.headers });
|
|
319
|
-
|
|
360
|
+
const data = yield (0, fetch_1.post)(this.fetch, `${this.url}/token?grant_type=refresh_token`, { refresh_token: refreshToken }, { headers: this.headers });
|
|
361
|
+
const session = Object.assign({}, data);
|
|
320
362
|
if (session.expires_in)
|
|
321
|
-
session.expires_at = helpers_1.expiresAt(data.expires_in);
|
|
363
|
+
session.expires_at = (0, helpers_1.expiresAt)(data.expires_in);
|
|
322
364
|
return { data: session, error: null };
|
|
323
365
|
}
|
|
324
|
-
catch (
|
|
325
|
-
return { data: null, error };
|
|
366
|
+
catch (e) {
|
|
367
|
+
return { data: null, error: e };
|
|
326
368
|
}
|
|
327
369
|
});
|
|
328
370
|
}
|
|
@@ -341,7 +383,7 @@ class GoTrueApi {
|
|
|
341
383
|
if (event === 'SIGNED_IN') {
|
|
342
384
|
if (!session)
|
|
343
385
|
throw new Error('Auth session missing!');
|
|
344
|
-
cookies_1.setCookie(req, res, {
|
|
386
|
+
(0, cookies_1.setCookie)(req, res, {
|
|
345
387
|
name: this.cookieOptions.name,
|
|
346
388
|
value: session.access_token,
|
|
347
389
|
domain: this.cookieOptions.domain,
|
|
@@ -351,7 +393,7 @@ class GoTrueApi {
|
|
|
351
393
|
});
|
|
352
394
|
}
|
|
353
395
|
if (event === 'SIGNED_OUT')
|
|
354
|
-
cookies_1.deleteCookie(req, res, this.cookieOptions.name);
|
|
396
|
+
(0, cookies_1.deleteCookie)(req, res, this.cookieOptions.name);
|
|
355
397
|
res.status(200).json({});
|
|
356
398
|
}
|
|
357
399
|
/**
|
|
@@ -361,18 +403,20 @@ class GoTrueApi {
|
|
|
361
403
|
getUserByCookie(req) {
|
|
362
404
|
return __awaiter(this, void 0, void 0, function* () {
|
|
363
405
|
try {
|
|
364
|
-
if (!req.cookies)
|
|
406
|
+
if (!req.cookies) {
|
|
365
407
|
throw new Error('Not able to parse cookies! When using Express make sure the cookie-parser middleware is in use!');
|
|
366
|
-
|
|
408
|
+
}
|
|
409
|
+
if (!req.cookies[this.cookieOptions.name]) {
|
|
367
410
|
throw new Error('No cookie found!');
|
|
411
|
+
}
|
|
368
412
|
const token = req.cookies[this.cookieOptions.name];
|
|
369
413
|
const { user, error } = yield this.getUser(token);
|
|
370
414
|
if (error)
|
|
371
415
|
throw error;
|
|
372
|
-
return { user, data: user, error: null };
|
|
416
|
+
return { token, user, data: user, error: null };
|
|
373
417
|
}
|
|
374
|
-
catch (
|
|
375
|
-
return { user: null, data: null, error };
|
|
418
|
+
catch (e) {
|
|
419
|
+
return { token: null, user: null, data: null, error: e };
|
|
376
420
|
}
|
|
377
421
|
});
|
|
378
422
|
}
|
|
@@ -387,7 +431,7 @@ class GoTrueApi {
|
|
|
387
431
|
generateLink(type, email, options = {}) {
|
|
388
432
|
return __awaiter(this, void 0, void 0, function* () {
|
|
389
433
|
try {
|
|
390
|
-
const data = yield fetch_1.post(`${this.url}/admin/generate_link`, {
|
|
434
|
+
const data = yield (0, fetch_1.post)(this.fetch, `${this.url}/admin/generate_link`, {
|
|
391
435
|
type,
|
|
392
436
|
email,
|
|
393
437
|
password: options.password,
|
|
@@ -396,8 +440,8 @@ class GoTrueApi {
|
|
|
396
440
|
}, { headers: this.headers });
|
|
397
441
|
return { data, error: null };
|
|
398
442
|
}
|
|
399
|
-
catch (
|
|
400
|
-
return { data: null, error };
|
|
443
|
+
catch (e) {
|
|
444
|
+
return { data: null, error: e };
|
|
401
445
|
}
|
|
402
446
|
});
|
|
403
447
|
}
|