@supabase/gotrue-js 1.23.1 → 2.0.0-rc.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main/GoTrueAdminApi.d.ts +88 -0
- package/dist/main/GoTrueAdminApi.d.ts.map +1 -0
- package/dist/main/GoTrueAdminApi.js +233 -0
- package/dist/main/GoTrueAdminApi.js.map +1 -0
- package/dist/main/GoTrueClient.d.ts +126 -138
- package/dist/main/GoTrueClient.d.ts.map +1 -1
- package/dist/main/GoTrueClient.js +581 -408
- package/dist/main/GoTrueClient.js.map +1 -1
- package/dist/main/index.d.ts +3 -2
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +9 -4
- package/dist/main/index.js.map +1 -1
- package/dist/main/lib/constants.d.ts +1 -9
- package/dist/main/lib/constants.d.ts.map +1 -1
- package/dist/main/lib/constants.js +2 -10
- package/dist/main/lib/constants.js.map +1 -1
- package/dist/main/lib/errors.d.ts +57 -0
- package/dist/main/lib/errors.d.ts.map +1 -0
- package/dist/main/lib/errors.js +88 -0
- package/dist/main/lib/errors.js.map +1 -0
- package/dist/main/lib/fetch.d.ts +22 -5
- package/dist/main/lib/fetch.d.ts.map +1 -1
- package/dist/main/lib/fetch.js +96 -39
- package/dist/main/lib/fetch.js.map +1 -1
- package/dist/main/lib/helpers.d.ts +16 -3
- package/dist/main/lib/helpers.d.ts.map +1 -1
- package/dist/main/lib/helpers.js +59 -19
- package/dist/main/lib/helpers.js.map +1 -1
- package/dist/main/lib/local-storage.d.ts +4 -0
- package/dist/main/lib/local-storage.d.ts.map +1 -0
- package/dist/main/lib/local-storage.js +25 -0
- package/dist/main/lib/local-storage.js.map +1 -0
- package/dist/main/lib/types.d.ts +307 -57
- 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 +2 -2
- package/dist/main/lib/version.js.map +1 -1
- package/dist/module/GoTrueAdminApi.d.ts +88 -0
- package/dist/module/GoTrueAdminApi.d.ts.map +1 -0
- package/dist/module/GoTrueAdminApi.js +230 -0
- package/dist/module/GoTrueAdminApi.js.map +1 -0
- package/dist/module/GoTrueClient.d.ts +126 -138
- package/dist/module/GoTrueClient.d.ts.map +1 -1
- package/dist/module/GoTrueClient.js +582 -409
- package/dist/module/GoTrueClient.js.map +1 -1
- package/dist/module/index.d.ts +3 -2
- package/dist/module/index.d.ts.map +1 -1
- package/dist/module/index.js +3 -2
- package/dist/module/index.js.map +1 -1
- package/dist/module/lib/constants.d.ts +1 -9
- package/dist/module/lib/constants.d.ts.map +1 -1
- package/dist/module/lib/constants.js +1 -9
- package/dist/module/lib/constants.js.map +1 -1
- package/dist/module/lib/errors.d.ts +57 -0
- package/dist/module/lib/errors.d.ts.map +1 -0
- package/dist/module/lib/errors.js +76 -0
- package/dist/module/lib/errors.js.map +1 -0
- package/dist/module/lib/fetch.d.ts +22 -5
- package/dist/module/lib/fetch.d.ts.map +1 -1
- package/dist/module/lib/fetch.js +91 -34
- package/dist/module/lib/fetch.js.map +1 -1
- package/dist/module/lib/helpers.d.ts +16 -3
- package/dist/module/lib/helpers.d.ts.map +1 -1
- package/dist/module/lib/helpers.js +49 -15
- package/dist/module/lib/helpers.js.map +1 -1
- package/dist/module/lib/local-storage.d.ts +4 -0
- package/dist/module/lib/local-storage.d.ts.map +1 -0
- package/dist/module/lib/local-storage.js +23 -0
- package/dist/module/lib/local-storage.js.map +1 -0
- package/dist/module/lib/types.d.ts +307 -57
- 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 +2 -2
- package/dist/module/lib/version.js.map +1 -1
- package/package.json +24 -23
- package/src/GoTrueAdminApi.ts +230 -0
- package/src/GoTrueClient.ts +693 -502
- package/src/index.ts +3 -2
- package/src/lib/constants.ts +1 -9
- package/src/lib/errors.ts +93 -0
- package/src/lib/fetch.ts +116 -42
- package/src/lib/helpers.ts +61 -15
- package/src/lib/local-storage.ts +28 -0
- package/src/lib/types.ts +352 -61
- package/src/lib/version.ts +2 -2
- package/dist/main/GoTrueApi.d.ts +0 -345
- package/dist/main/GoTrueApi.d.ts.map +0 -1
- package/dist/main/GoTrueApi.js +0 -678
- package/dist/main/GoTrueApi.js.map +0 -1
- package/dist/main/lib/cookies.d.ts +0 -23
- package/dist/main/lib/cookies.d.ts.map +0 -1
- package/dist/main/lib/cookies.js +0 -139
- package/dist/main/lib/cookies.js.map +0 -1
- package/dist/module/GoTrueApi.d.ts +0 -345
- package/dist/module/GoTrueApi.d.ts.map +0 -1
- package/dist/module/GoTrueApi.js +0 -675
- package/dist/module/GoTrueApi.js.map +0 -1
- package/dist/module/lib/cookies.d.ts +0 -23
- package/dist/module/lib/cookies.d.ts.map +0 -1
- package/dist/module/lib/cookies.js +0 -132
- package/dist/module/lib/cookies.js.map +0 -1
- package/src/GoTrueApi.ts +0 -857
- package/src/lib/cookies.ts +0 -178
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Fetch } from './lib/fetch';
|
|
2
|
+
import { AdminUserAttributes, GenerateLinkParams, GenerateLinkResponse, 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 deeplink 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 email links and OTPs to be sent via a custom email provider.
|
|
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(params: GenerateLinkParams): Promise<GenerateLinkResponse>;
|
|
42
|
+
/**
|
|
43
|
+
* Creates a new user.
|
|
44
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
45
|
+
*/
|
|
46
|
+
createUser(attributes: AdminUserAttributes): Promise<UserResponse>;
|
|
47
|
+
/**
|
|
48
|
+
* Get a list of users.
|
|
49
|
+
*
|
|
50
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
51
|
+
*/
|
|
52
|
+
listUsers(): Promise<{
|
|
53
|
+
data: {
|
|
54
|
+
users: User[];
|
|
55
|
+
};
|
|
56
|
+
error: null;
|
|
57
|
+
} | {
|
|
58
|
+
data: {
|
|
59
|
+
users: [];
|
|
60
|
+
};
|
|
61
|
+
error: AuthError;
|
|
62
|
+
}>;
|
|
63
|
+
/**
|
|
64
|
+
* Get user by id.
|
|
65
|
+
*
|
|
66
|
+
* @param uid The user's unique identifier
|
|
67
|
+
*
|
|
68
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
69
|
+
*/
|
|
70
|
+
getUserById(uid: string): Promise<UserResponse>;
|
|
71
|
+
/**
|
|
72
|
+
* Updates the user data.
|
|
73
|
+
*
|
|
74
|
+
* @param attributes The data you want to update.
|
|
75
|
+
*
|
|
76
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
77
|
+
*/
|
|
78
|
+
updateUserById(uid: string, attributes: AdminUserAttributes): Promise<UserResponse>;
|
|
79
|
+
/**
|
|
80
|
+
* Delete a user. Requires a `service_role` key.
|
|
81
|
+
*
|
|
82
|
+
* @param id The user id you want to remove.
|
|
83
|
+
*
|
|
84
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
85
|
+
*/
|
|
86
|
+
deleteUser(id: string): Promise<UserResponse>;
|
|
87
|
+
}
|
|
88
|
+
//# 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,EAAkD,MAAM,aAAa,CAAA;AAEnF,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,IAAI,EACJ,YAAY,EACb,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,SAAS,EAAe,MAAM,cAAc,CAAA;AAErD,MAAM,CAAC,OAAO,OAAO,cAAc;IACjC,SAAS,CAAC,GAAG,EAAE,MAAM,CAAA;IACrB,SAAS,CAAC,OAAO,EAAE;QACjB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KACtB,CAAA;IACD,SAAS,CAAC,KAAK,EAAE,KAAK,CAAA;gBAEV,EACV,GAAQ,EACR,OAAY,EACZ,KAAK,GACN,EAAE;QACD,GAAG,EAAE,MAAM,CAAA;QACX,OAAO,CAAC,EAAE;YACR,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;SACtB,CAAA;QACD,KAAK,CAAC,EAAE,KAAK,CAAA;KACd;IAMD;;;OAGG;IACG,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,SAAS,GAAG,IAAI,CAAA;KAAE,CAAC;IAiBhE;;;;;OAKG;IACG,iBAAiB,CACrB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE;QACP,UAAU,CAAC,EAAE,MAAM,CAAA;QACnB,IAAI,CAAC,EAAE,MAAM,CAAA;KACT,GACL,OAAO,CAAC,YAAY,CAAC;IAiBxB;;;;;;OAMG;IACG,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IA8B7E;;;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,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;CAcpD"}
|
|
@@ -0,0 +1,233 @@
|
|
|
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
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
const fetch_1 = require("./lib/fetch");
|
|
24
|
+
const helpers_1 = require("./lib/helpers");
|
|
25
|
+
const errors_1 = require("./lib/errors");
|
|
26
|
+
class GoTrueAdminApi {
|
|
27
|
+
constructor({ url = '', headers = {}, fetch, }) {
|
|
28
|
+
this.url = url;
|
|
29
|
+
this.headers = headers;
|
|
30
|
+
this.fetch = (0, helpers_1.resolveFetch)(fetch);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Removes a logged-in session.
|
|
34
|
+
* @param jwt A valid, logged-in JWT.
|
|
35
|
+
*/
|
|
36
|
+
signOut(jwt) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
try {
|
|
39
|
+
yield (0, fetch_1._request)(this.fetch, 'POST', `${this.url}/logout`, {
|
|
40
|
+
headers: this.headers,
|
|
41
|
+
jwt,
|
|
42
|
+
noResolveJson: true,
|
|
43
|
+
});
|
|
44
|
+
return { error: null };
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if ((0, errors_1.isAuthError)(error)) {
|
|
48
|
+
return { error };
|
|
49
|
+
}
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Sends an invite link to an email address.
|
|
56
|
+
* @param email The email address of the user.
|
|
57
|
+
* @param options.redirectTo A URL or mobile deeplink to send the user to after they are confirmed.
|
|
58
|
+
* @param options.data Optional user metadata
|
|
59
|
+
*/
|
|
60
|
+
inviteUserByEmail(email, options = {}) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
try {
|
|
63
|
+
return yield (0, fetch_1._request)(this.fetch, 'POST', `${this.url}/invite`, {
|
|
64
|
+
body: { email, data: options.data },
|
|
65
|
+
headers: this.headers,
|
|
66
|
+
redirectTo: options.redirectTo,
|
|
67
|
+
xform: fetch_1._userResponse,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
if ((0, errors_1.isAuthError)(error)) {
|
|
72
|
+
return { data: { user: null }, error };
|
|
73
|
+
}
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Generates email links and OTPs to be sent via a custom email provider.
|
|
80
|
+
* @param email The user's email.
|
|
81
|
+
* @param options.password User password. For signup only.
|
|
82
|
+
* @param options.data Optional user metadata. For signup only.
|
|
83
|
+
* @param options.redirectTo The redirect url which should be appended to the generated link
|
|
84
|
+
*/
|
|
85
|
+
generateLink(params) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
try {
|
|
88
|
+
const { options } = params, rest = __rest(params, ["options"]);
|
|
89
|
+
const body = Object.assign(Object.assign({}, rest), options);
|
|
90
|
+
if ('newEmail' in rest) {
|
|
91
|
+
// replace newEmail with new_email in request body
|
|
92
|
+
body.new_email = rest === null || rest === void 0 ? void 0 : rest.newEmail;
|
|
93
|
+
delete body['newEmail'];
|
|
94
|
+
}
|
|
95
|
+
return yield (0, fetch_1._request)(this.fetch, 'POST', `${this.url}/admin/generate_link`, {
|
|
96
|
+
body: body,
|
|
97
|
+
headers: this.headers,
|
|
98
|
+
xform: fetch_1._generateLinkResponse,
|
|
99
|
+
redirectTo: options === null || options === void 0 ? void 0 : options.redirectTo,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
if ((0, errors_1.isAuthError)(error)) {
|
|
104
|
+
return {
|
|
105
|
+
data: {
|
|
106
|
+
properties: null,
|
|
107
|
+
user: null,
|
|
108
|
+
},
|
|
109
|
+
error,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
// User Admin API
|
|
117
|
+
/**
|
|
118
|
+
* Creates a new user.
|
|
119
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
120
|
+
*/
|
|
121
|
+
createUser(attributes) {
|
|
122
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
+
try {
|
|
124
|
+
return yield (0, fetch_1._request)(this.fetch, 'POST', `${this.url}/admin/users`, {
|
|
125
|
+
body: attributes,
|
|
126
|
+
headers: this.headers,
|
|
127
|
+
xform: fetch_1._userResponse,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
if ((0, errors_1.isAuthError)(error)) {
|
|
132
|
+
return { data: { user: null }, error };
|
|
133
|
+
}
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Get a list of users.
|
|
140
|
+
*
|
|
141
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
142
|
+
*/
|
|
143
|
+
listUsers() {
|
|
144
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
+
try {
|
|
146
|
+
const { data, error } = yield (0, fetch_1._request)(this.fetch, 'GET', `${this.url}/admin/users`, {
|
|
147
|
+
headers: this.headers,
|
|
148
|
+
});
|
|
149
|
+
if (error)
|
|
150
|
+
throw error;
|
|
151
|
+
return { data: Object.assign({}, data), error: null };
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
if ((0, errors_1.isAuthError)(error)) {
|
|
155
|
+
return { data: { users: [] }, error };
|
|
156
|
+
}
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Get user by id.
|
|
163
|
+
*
|
|
164
|
+
* @param uid The user's unique identifier
|
|
165
|
+
*
|
|
166
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
167
|
+
*/
|
|
168
|
+
getUserById(uid) {
|
|
169
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
170
|
+
try {
|
|
171
|
+
return yield (0, fetch_1._request)(this.fetch, 'GET', `${this.url}/admin/users/${uid}`, {
|
|
172
|
+
headers: this.headers,
|
|
173
|
+
xform: fetch_1._userResponse,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
if ((0, errors_1.isAuthError)(error)) {
|
|
178
|
+
return { data: { user: null }, error };
|
|
179
|
+
}
|
|
180
|
+
throw error;
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Updates the user data.
|
|
186
|
+
*
|
|
187
|
+
* @param attributes The data you want to update.
|
|
188
|
+
*
|
|
189
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
190
|
+
*/
|
|
191
|
+
updateUserById(uid, attributes) {
|
|
192
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
193
|
+
try {
|
|
194
|
+
return yield (0, fetch_1._request)(this.fetch, 'PUT', `${this.url}/admin/users/${uid}`, {
|
|
195
|
+
body: attributes,
|
|
196
|
+
headers: this.headers,
|
|
197
|
+
xform: fetch_1._userResponse,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
if ((0, errors_1.isAuthError)(error)) {
|
|
202
|
+
return { data: { user: null }, error };
|
|
203
|
+
}
|
|
204
|
+
throw error;
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Delete a user. Requires a `service_role` key.
|
|
210
|
+
*
|
|
211
|
+
* @param id The user id you want to remove.
|
|
212
|
+
*
|
|
213
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
214
|
+
*/
|
|
215
|
+
deleteUser(id) {
|
|
216
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
217
|
+
try {
|
|
218
|
+
return yield (0, fetch_1._request)(this.fetch, 'DELETE', `${this.url}/admin/users/${id}`, {
|
|
219
|
+
headers: this.headers,
|
|
220
|
+
xform: fetch_1._userResponse,
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
if ((0, errors_1.isAuthError)(error)) {
|
|
225
|
+
return { data: { user: null }, error };
|
|
226
|
+
}
|
|
227
|
+
throw error;
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
exports.default = GoTrueAdminApi;
|
|
233
|
+
//# sourceMappingURL=GoTrueAdminApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GoTrueAdminApi.js","sourceRoot":"","sources":["../../src/GoTrueAdminApi.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAmF;AACnF,2CAA4C;AAQ5C,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;QACt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,OAAO,MAAM,IAAA,gBAAQ,EAAC,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,GAAG,gBAAgB,GAAG,EAAE,EAAE;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,EAAU;;YACzB,IAAI;gBACF,OAAO,MAAM,IAAA,gBAAQ,EAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,GAAG,gBAAgB,EAAE,EAAE,EAAE;oBAC3E,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;AA1ND,iCA0NC"}
|
|
@@ -1,187 +1,171 @@
|
|
|
1
|
-
import
|
|
1
|
+
import GoTrueAdminApi from './GoTrueAdminApi';
|
|
2
|
+
import { AuthError } from './lib/errors';
|
|
2
3
|
import { Fetch } from './lib/fetch';
|
|
3
|
-
import
|
|
4
|
+
import { Deferred } from './lib/helpers';
|
|
5
|
+
import type { AuthChangeEvent, AuthResponse, CallRefreshTokenResult, GoTrueClientOptions, InitializeResult, OAuthResponse, Session, SignInWithOAuthCredentials, SignInWithPasswordCredentials, SignInWithPasswordlessCredentials, SignUpWithPasswordCredentials, Subscription, SupportedStorage, UserAttributes, UserResponse, VerifyOtpParams } from './lib/types';
|
|
4
6
|
export default class GoTrueClient {
|
|
5
7
|
/**
|
|
6
|
-
* Namespace for the GoTrue
|
|
7
|
-
* These
|
|
8
|
+
* Namespace for the GoTrue admin methods.
|
|
9
|
+
* These methods should only be used in a trusted server-side environment.
|
|
8
10
|
*/
|
|
9
|
-
|
|
11
|
+
admin: GoTrueAdminApi;
|
|
10
12
|
/**
|
|
11
|
-
* The
|
|
13
|
+
* The storage key used to identify the values saved in localStorage
|
|
12
14
|
*/
|
|
13
|
-
protected
|
|
15
|
+
protected storageKey: string;
|
|
14
16
|
/**
|
|
15
|
-
* The session object for the currently logged in user
|
|
17
|
+
* The session object for the currently logged in user. If null, it means there isn't a logged-in user.
|
|
18
|
+
* Only used if persistSession is false.
|
|
16
19
|
*/
|
|
17
|
-
protected
|
|
20
|
+
protected inMemorySession: Session | null;
|
|
18
21
|
protected autoRefreshToken: boolean;
|
|
19
22
|
protected persistSession: boolean;
|
|
20
|
-
protected
|
|
21
|
-
protected multiTab: boolean;
|
|
23
|
+
protected storage: SupportedStorage;
|
|
22
24
|
protected stateChangeEmitters: Map<string, Subscription>;
|
|
23
25
|
protected refreshTokenTimer?: ReturnType<typeof setTimeout>;
|
|
24
26
|
protected networkRetries: number;
|
|
27
|
+
protected refreshingDeferred: Deferred<CallRefreshTokenResult> | null;
|
|
28
|
+
/**
|
|
29
|
+
* Keeps track of the async client initialization.
|
|
30
|
+
* When null or not yet resolved the auth state is `unknown`
|
|
31
|
+
* Once resolved the the auth state is known and it's save to call any further client methods.
|
|
32
|
+
* Keep extra care to never reject or throw uncaught errors
|
|
33
|
+
*/
|
|
34
|
+
protected initializePromise: Promise<InitializeResult> | null;
|
|
35
|
+
protected detectSessionInUrl: boolean;
|
|
36
|
+
protected url: string;
|
|
37
|
+
protected headers: {
|
|
38
|
+
[key: string]: string;
|
|
39
|
+
};
|
|
40
|
+
protected fetch: Fetch;
|
|
25
41
|
/**
|
|
26
42
|
* Create a new client for use in the browser.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
detectSessionInUrl?: boolean;
|
|
43
|
-
autoRefreshToken?: boolean;
|
|
44
|
-
persistSession?: boolean;
|
|
45
|
-
localStorage?: SupportedStorage;
|
|
46
|
-
multiTab?: boolean;
|
|
47
|
-
cookieOptions?: CookieOptions;
|
|
48
|
-
fetch?: Fetch;
|
|
49
|
-
});
|
|
43
|
+
*/
|
|
44
|
+
constructor(options: GoTrueClientOptions);
|
|
45
|
+
/**
|
|
46
|
+
* Initializes the client session either from the url or from storage.
|
|
47
|
+
* This method is automatically called when instantiating the client, but should also be called
|
|
48
|
+
* manually when checking for an error from an auth redirect (oauth, magiclink, password recovery, etc).
|
|
49
|
+
*/
|
|
50
|
+
initialize(): Promise<InitializeResult>;
|
|
51
|
+
/**
|
|
52
|
+
* IMPORTANT:
|
|
53
|
+
* 1. Never throw in this method, as it is called from the constructor
|
|
54
|
+
* 2. Never return a session from this method as it would be cached over
|
|
55
|
+
* the whole lifetime of the client
|
|
56
|
+
*/
|
|
57
|
+
private _initialize;
|
|
50
58
|
/**
|
|
51
59
|
* Creates a new user.
|
|
52
|
-
* @
|
|
53
|
-
* @
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
* @param redirectTo The redirect URL attached to the signup confirmation link. Does not redirect the user if it's a mobile signup.
|
|
57
|
-
* @param data Optional user metadata.
|
|
58
|
-
*/
|
|
59
|
-
signUp({ email, password, phone }: UserCredentials, options?: {
|
|
60
|
-
redirectTo?: string;
|
|
61
|
-
data?: object;
|
|
62
|
-
captchaToken?: string;
|
|
63
|
-
}): Promise<{
|
|
64
|
-
user: User | null;
|
|
65
|
-
session: Session | null;
|
|
66
|
-
error: ApiError | null;
|
|
67
|
-
}>;
|
|
60
|
+
* @returns A logged-in session if the server has "autoconfirm" ON
|
|
61
|
+
* @returns A user if the server has "autoconfirm" OFF
|
|
62
|
+
*/
|
|
63
|
+
signUp(credentials: SignUpWithPasswordCredentials): Promise<AuthResponse>;
|
|
68
64
|
/**
|
|
69
|
-
* Log in an existing user
|
|
70
|
-
* @type UserCredentials
|
|
71
|
-
* @param email The user's email address.
|
|
72
|
-
* @param phone The user's phone number.
|
|
73
|
-
* @param password The user's password.
|
|
74
|
-
* @param refreshToken A valid refresh token that was returned on login.
|
|
75
|
-
* @param provider One of the providers supported by GoTrue.
|
|
76
|
-
* @param redirectTo A URL to send the user to after they are confirmed (OAuth logins only).
|
|
77
|
-
* @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.
|
|
78
|
-
* @param scopes A space-separated list of scopes granted to the OAuth application.
|
|
65
|
+
* Log in an existing user with an email and password or phone and password.
|
|
79
66
|
*/
|
|
80
|
-
|
|
81
|
-
redirectTo?: string;
|
|
82
|
-
shouldCreateUser?: boolean;
|
|
83
|
-
scopes?: string;
|
|
84
|
-
captchaToken?: string;
|
|
85
|
-
queryParams?: {
|
|
86
|
-
[key: string]: string;
|
|
87
|
-
};
|
|
88
|
-
}): Promise<{
|
|
89
|
-
session: Session | null;
|
|
90
|
-
user: User | null;
|
|
91
|
-
provider?: Provider;
|
|
92
|
-
url?: string | null;
|
|
93
|
-
error: ApiError | null;
|
|
94
|
-
}>;
|
|
67
|
+
signInWithPassword(credentials: SignInWithPasswordCredentials): Promise<AuthResponse>;
|
|
95
68
|
/**
|
|
96
|
-
* Log in
|
|
97
|
-
* @param email The user's email address.
|
|
98
|
-
* @param phone The user's phone number.
|
|
99
|
-
* @param token The user's password.
|
|
100
|
-
* @param type The user's verification type.
|
|
101
|
-
* @param redirectTo A URL or mobile address to send the user to after they are confirmed.
|
|
69
|
+
* Log in an existing user via a third-party provider.
|
|
102
70
|
*/
|
|
103
|
-
|
|
104
|
-
redirectTo?: string;
|
|
105
|
-
}): Promise<{
|
|
106
|
-
user: User | null;
|
|
107
|
-
session: Session | null;
|
|
108
|
-
error: ApiError | null;
|
|
109
|
-
}>;
|
|
71
|
+
signInWithOAuth(credentials: SignInWithOAuthCredentials): Promise<OAuthResponse>;
|
|
110
72
|
/**
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
73
|
+
* Log in a user using magiclink or a one-time password (OTP).
|
|
74
|
+
* If the `{{ .ConfirmationURL }}` variable is specified in the email template, a magiclink will be sent.
|
|
75
|
+
* If the `{{ .Token }}` variable is specified in the email template, an OTP will be sent.
|
|
76
|
+
* If you're using phone sign-ins, only an OTP will be sent. You won't be able to send a magiclink for phone sign-ins.
|
|
114
77
|
*/
|
|
115
|
-
|
|
78
|
+
signInWithOtp(credentials: SignInWithPasswordlessCredentials): Promise<AuthResponse>;
|
|
116
79
|
/**
|
|
117
|
-
*
|
|
80
|
+
* Log in a user given a User supplied OTP received via mobile.
|
|
118
81
|
*/
|
|
119
|
-
|
|
82
|
+
verifyOtp(params: VerifyOtpParams): Promise<AuthResponse>;
|
|
120
83
|
/**
|
|
121
|
-
*
|
|
84
|
+
* Returns the session, refreshing it if necessary.
|
|
85
|
+
* The session returned can be null if the session is not detected which can happen in the event a user is not signed-in or has logged out.
|
|
122
86
|
*/
|
|
123
|
-
|
|
124
|
-
data:
|
|
125
|
-
|
|
126
|
-
|
|
87
|
+
getSession(): Promise<{
|
|
88
|
+
data: {
|
|
89
|
+
session: Session;
|
|
90
|
+
};
|
|
91
|
+
error: null;
|
|
92
|
+
} | {
|
|
93
|
+
data: {
|
|
94
|
+
session: null;
|
|
95
|
+
};
|
|
96
|
+
error: AuthError;
|
|
97
|
+
} | {
|
|
98
|
+
data: {
|
|
99
|
+
session: null;
|
|
100
|
+
};
|
|
101
|
+
error: null;
|
|
127
102
|
}>;
|
|
128
103
|
/**
|
|
129
|
-
*
|
|
104
|
+
* Gets the current user details if there is an existing session.
|
|
105
|
+
* @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.
|
|
130
106
|
*/
|
|
131
|
-
|
|
132
|
-
data: User | null;
|
|
133
|
-
user: User | null;
|
|
134
|
-
error: ApiError | null;
|
|
135
|
-
}>;
|
|
107
|
+
getUser(jwt?: string): Promise<UserResponse>;
|
|
136
108
|
/**
|
|
137
|
-
*
|
|
138
|
-
* @param refresh_token a JWT token
|
|
109
|
+
* Updates user data, if there is a logged in user.
|
|
139
110
|
*/
|
|
140
|
-
|
|
141
|
-
session: Session | null;
|
|
142
|
-
error: ApiError | null;
|
|
143
|
-
}>;
|
|
111
|
+
updateUser(attributes: UserAttributes): Promise<UserResponse>;
|
|
144
112
|
/**
|
|
145
|
-
*
|
|
146
|
-
*
|
|
113
|
+
* Sets the session data from the current session. If the current session is expired, setSession will take care of refreshing it to obtain a new session.
|
|
114
|
+
* If the refresh token in the current session is invalid and the current session has expired, an error will be thrown.
|
|
115
|
+
* If the current session does not contain at expires_at field, setSession will use the exp claim defined in the access token.
|
|
116
|
+
* @param currentSession The current session that minimally contains an access token, refresh token and a user.
|
|
147
117
|
*/
|
|
148
|
-
|
|
118
|
+
setSession(currentSession: Pick<Session, 'access_token' | 'refresh_token'>): Promise<AuthResponse>;
|
|
149
119
|
/**
|
|
150
120
|
* Gets the session data from a URL string
|
|
151
|
-
* @param options.storeSession Optionally store the session in the browser
|
|
152
121
|
*/
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}>;
|
|
122
|
+
private _getSessionFromUrl;
|
|
123
|
+
/**
|
|
124
|
+
* Checks if the current URL contains parameters given by an implicit oauth grant flow (https://www.rfc-editor.org/rfc/rfc6749.html#section-4.2)
|
|
125
|
+
*/
|
|
126
|
+
private _isImplicitGrantFlow;
|
|
159
127
|
/**
|
|
160
128
|
* Inside a browser context, `signOut()` will remove the logged in user from the browser session
|
|
161
|
-
* and log them out - removing all items from localstorage and then trigger a "SIGNED_OUT" event.
|
|
129
|
+
* and log them out - removing all items from localstorage and then trigger a `"SIGNED_OUT"` event.
|
|
162
130
|
*
|
|
163
|
-
* 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)`.
|
|
131
|
+
* 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)`.
|
|
132
|
+
* 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.
|
|
164
133
|
*/
|
|
165
134
|
signOut(): Promise<{
|
|
166
|
-
error:
|
|
135
|
+
error: AuthError | null;
|
|
167
136
|
}>;
|
|
168
137
|
/**
|
|
169
138
|
* Receive a notification every time an auth event happens.
|
|
170
|
-
* @
|
|
139
|
+
* @param callback A callback function to be invoked when an auth event happens.
|
|
171
140
|
*/
|
|
172
141
|
onAuthStateChange(callback: (event: AuthChangeEvent, session: Session | null) => void): {
|
|
173
|
-
data:
|
|
174
|
-
|
|
142
|
+
data: {
|
|
143
|
+
subscription: Subscription;
|
|
144
|
+
};
|
|
175
145
|
};
|
|
176
|
-
private _handleEmailSignIn;
|
|
177
|
-
private _handlePhoneSignIn;
|
|
178
|
-
private _handleProviderSignIn;
|
|
179
|
-
private _handleOpenIDConnectSignIn;
|
|
180
146
|
/**
|
|
181
|
-
*
|
|
182
|
-
*
|
|
147
|
+
* Sends a password reset request to an email address.
|
|
148
|
+
* @param email The email address of the user.
|
|
149
|
+
* @param options.redirectTo The URL to send the user to after they click the password reset link.
|
|
150
|
+
* @param options.captchaToken Verification token received when the user completes the captcha on the site.
|
|
183
151
|
*/
|
|
184
|
-
|
|
152
|
+
resetPasswordForEmail(email: string, options?: {
|
|
153
|
+
redirectTo?: string;
|
|
154
|
+
captchaToken?: string;
|
|
155
|
+
}): Promise<{
|
|
156
|
+
data: {};
|
|
157
|
+
error: null;
|
|
158
|
+
} | {
|
|
159
|
+
data: null;
|
|
160
|
+
error: AuthError;
|
|
161
|
+
}>;
|
|
162
|
+
/**
|
|
163
|
+
* Generates a new JWT.
|
|
164
|
+
* @param refreshToken A valid refresh token that was returned on login.
|
|
165
|
+
*/
|
|
166
|
+
private _refreshAccessToken;
|
|
167
|
+
private _isValidSession;
|
|
168
|
+
private _handleProviderSignIn;
|
|
185
169
|
/**
|
|
186
170
|
* Recovers the session from LocalStorage and refreshes
|
|
187
171
|
* Note: this method is async to accommodate for AsyncStorage e.g. in React native.
|
|
@@ -198,13 +182,17 @@ export default class GoTrueClient {
|
|
|
198
182
|
private _removeSession;
|
|
199
183
|
/**
|
|
200
184
|
* Clear and re-create refresh token timer
|
|
201
|
-
* @param value time intervals in milliseconds
|
|
185
|
+
* @param value time intervals in milliseconds.
|
|
186
|
+
* @param session The current session.
|
|
202
187
|
*/
|
|
203
188
|
private _startAutoRefreshToken;
|
|
189
|
+
private _handleVisibilityChange;
|
|
204
190
|
/**
|
|
205
|
-
*
|
|
191
|
+
* Generates the relevant login URL for a third-party provider.
|
|
192
|
+
* @param options.redirectTo A URL or mobile address to send the user to after they are confirmed.
|
|
193
|
+
* @param options.scopes A space-separated list of scopes granted to the OAuth application.
|
|
194
|
+
* @param options.queryParams An object of key-value pairs containing query parameters granted to the OAuth application.
|
|
206
195
|
*/
|
|
207
|
-
private
|
|
208
|
-
private _handleVisibilityChange;
|
|
196
|
+
private _getUrlForProvider;
|
|
209
197
|
}
|
|
210
198
|
//# sourceMappingURL=GoTrueClient.d.ts.map
|