@supabase/gotrue-js 2.0.0-rc.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 +6 -19
- package/dist/main/GoTrueAdminApi.d.ts.map +1 -1
- package/dist/main/GoTrueAdminApi.js +34 -14
- package/dist/main/GoTrueAdminApi.js.map +1 -1
- package/dist/main/GoTrueClient.d.ts +48 -47
- package/dist/main/GoTrueClient.d.ts.map +1 -1
- package/dist/main/GoTrueClient.js +232 -130
- package/dist/main/GoTrueClient.js.map +1 -1
- package/dist/main/lib/errors.d.ts +19 -0
- package/dist/main/lib/errors.d.ts.map +1 -1
- package/dist/main/lib/errors.js +17 -1
- package/dist/main/lib/errors.js.map +1 -1
- package/dist/main/lib/fetch.d.ts +2 -1
- package/dist/main/lib/fetch.d.ts.map +1 -1
- package/dist/main/lib/fetch.js +34 -4
- package/dist/main/lib/fetch.js.map +1 -1
- package/dist/main/lib/helpers.d.ts +2 -6
- package/dist/main/lib/helpers.d.ts.map +1 -1
- package/dist/main/lib/helpers.js +36 -13
- 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 +164 -24
- 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/GoTrueAdminApi.d.ts +6 -19
- package/dist/module/GoTrueAdminApi.d.ts.map +1 -1
- package/dist/module/GoTrueAdminApi.js +35 -15
- package/dist/module/GoTrueAdminApi.js.map +1 -1
- package/dist/module/GoTrueClient.d.ts +48 -47
- package/dist/module/GoTrueClient.d.ts.map +1 -1
- package/dist/module/GoTrueClient.js +234 -132
- package/dist/module/GoTrueClient.js.map +1 -1
- package/dist/module/lib/errors.d.ts +19 -0
- package/dist/module/lib/errors.d.ts.map +1 -1
- package/dist/module/lib/errors.js +15 -0
- package/dist/module/lib/errors.js.map +1 -1
- package/dist/module/lib/fetch.d.ts +2 -1
- package/dist/module/lib/fetch.d.ts.map +1 -1
- package/dist/module/lib/fetch.js +33 -4
- package/dist/module/lib/fetch.js.map +1 -1
- package/dist/module/lib/helpers.d.ts +2 -6
- package/dist/module/lib/helpers.d.ts.map +1 -1
- package/dist/module/lib/helpers.js +33 -11
- 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 +164 -24
- 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 +1 -1
- package/src/GoTrueAdminApi.ts +31 -34
- package/src/GoTrueClient.ts +245 -144
- package/src/lib/errors.ts +17 -0
- package/src/lib/fetch.ts +32 -6
- package/src/lib/helpers.ts +36 -11
- package/src/lib/local-storage.ts +28 -0
- package/src/lib/types.ts +187 -25
- package/src/lib/version.ts +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Fetch } from './lib/fetch';
|
|
2
|
-
import { AdminUserAttributes,
|
|
2
|
+
import { AdminUserAttributes, GenerateLinkParams, GenerateLinkResponse, User, UserResponse } from './lib/types';
|
|
3
3
|
import { AuthError } from './lib/errors';
|
|
4
4
|
export default class GoTrueAdminApi {
|
|
5
5
|
protected url: string;
|
|
@@ -24,7 +24,7 @@ export default class GoTrueAdminApi {
|
|
|
24
24
|
/**
|
|
25
25
|
* Sends an invite link to an email address.
|
|
26
26
|
* @param email The email address of the user.
|
|
27
|
-
* @param options.redirectTo A URL or mobile
|
|
27
|
+
* @param options.redirectTo A URL or mobile deeplink to send the user to after they are confirmed.
|
|
28
28
|
* @param options.data Optional user metadata
|
|
29
29
|
*/
|
|
30
30
|
inviteUserByEmail(email: string, options?: {
|
|
@@ -32,26 +32,13 @@ export default class GoTrueAdminApi {
|
|
|
32
32
|
data?: object;
|
|
33
33
|
}): Promise<UserResponse>;
|
|
34
34
|
/**
|
|
35
|
-
* Generates links to be sent via email
|
|
35
|
+
* Generates email links and OTPs to be sent via a custom email provider.
|
|
36
36
|
* @param email The user's email.
|
|
37
37
|
* @param options.password User password. For signup only.
|
|
38
38
|
* @param options.data Optional user metadata. For signup only.
|
|
39
39
|
* @param options.redirectTo The redirect url which should be appended to the generated link
|
|
40
40
|
*/
|
|
41
|
-
generateLink(
|
|
42
|
-
password?: string;
|
|
43
|
-
data?: object;
|
|
44
|
-
redirectTo?: string;
|
|
45
|
-
}): Promise<{
|
|
46
|
-
data: User;
|
|
47
|
-
error: null;
|
|
48
|
-
} | {
|
|
49
|
-
data: Session;
|
|
50
|
-
error: null;
|
|
51
|
-
} | {
|
|
52
|
-
data: null;
|
|
53
|
-
error: AuthError;
|
|
54
|
-
}>;
|
|
41
|
+
generateLink(params: GenerateLinkParams): Promise<GenerateLinkResponse>;
|
|
55
42
|
/**
|
|
56
43
|
* Creates a new user.
|
|
57
44
|
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
@@ -92,10 +79,10 @@ export default class GoTrueAdminApi {
|
|
|
92
79
|
/**
|
|
93
80
|
* Delete a user. Requires a `service_role` key.
|
|
94
81
|
*
|
|
95
|
-
* @param
|
|
82
|
+
* @param id The user id you want to remove.
|
|
96
83
|
*
|
|
97
84
|
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
98
85
|
*/
|
|
99
|
-
deleteUser(
|
|
86
|
+
deleteUser(id: string): Promise<UserResponse>;
|
|
100
87
|
}
|
|
101
88
|
//# sourceMappingURL=GoTrueAdminApi.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GoTrueAdminApi.d.ts","sourceRoot":"","sources":["../../src/GoTrueAdminApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,
|
|
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"}
|
|
@@ -8,6 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
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
|
+
};
|
|
11
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
23
|
const fetch_1 = require("./lib/fetch");
|
|
13
24
|
const helpers_1 = require("./lib/helpers");
|
|
@@ -43,7 +54,7 @@ class GoTrueAdminApi {
|
|
|
43
54
|
/**
|
|
44
55
|
* Sends an invite link to an email address.
|
|
45
56
|
* @param email The email address of the user.
|
|
46
|
-
* @param options.redirectTo A URL or mobile
|
|
57
|
+
* @param options.redirectTo A URL or mobile deeplink to send the user to after they are confirmed.
|
|
47
58
|
* @param options.data Optional user metadata
|
|
48
59
|
*/
|
|
49
60
|
inviteUserByEmail(email, options = {}) {
|
|
@@ -65,29 +76,38 @@ class GoTrueAdminApi {
|
|
|
65
76
|
});
|
|
66
77
|
}
|
|
67
78
|
/**
|
|
68
|
-
* Generates links to be sent via email
|
|
79
|
+
* Generates email links and OTPs to be sent via a custom email provider.
|
|
69
80
|
* @param email The user's email.
|
|
70
81
|
* @param options.password User password. For signup only.
|
|
71
82
|
* @param options.data Optional user metadata. For signup only.
|
|
72
83
|
* @param options.redirectTo The redirect url which should be appended to the generated link
|
|
73
84
|
*/
|
|
74
|
-
generateLink(
|
|
85
|
+
generateLink(params) {
|
|
75
86
|
return __awaiter(this, void 0, void 0, function* () {
|
|
76
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
|
+
}
|
|
77
95
|
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
|
-
},
|
|
96
|
+
body: body,
|
|
85
97
|
headers: this.headers,
|
|
98
|
+
xform: fetch_1._generateLinkResponse,
|
|
99
|
+
redirectTo: options === null || options === void 0 ? void 0 : options.redirectTo,
|
|
86
100
|
});
|
|
87
101
|
}
|
|
88
102
|
catch (error) {
|
|
89
103
|
if ((0, errors_1.isAuthError)(error)) {
|
|
90
|
-
return {
|
|
104
|
+
return {
|
|
105
|
+
data: {
|
|
106
|
+
properties: null,
|
|
107
|
+
user: null,
|
|
108
|
+
},
|
|
109
|
+
error,
|
|
110
|
+
};
|
|
91
111
|
}
|
|
92
112
|
throw error;
|
|
93
113
|
}
|
|
@@ -188,14 +208,14 @@ class GoTrueAdminApi {
|
|
|
188
208
|
/**
|
|
189
209
|
* Delete a user. Requires a `service_role` key.
|
|
190
210
|
*
|
|
191
|
-
* @param
|
|
211
|
+
* @param id The user id you want to remove.
|
|
192
212
|
*
|
|
193
213
|
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
194
214
|
*/
|
|
195
|
-
deleteUser(
|
|
215
|
+
deleteUser(id) {
|
|
196
216
|
return __awaiter(this, void 0, void 0, function* () {
|
|
197
217
|
try {
|
|
198
|
-
return yield (0, fetch_1._request)(this.fetch, 'DELETE', `${this.url}/admin/users/${
|
|
218
|
+
return yield (0, fetch_1._request)(this.fetch, 'DELETE', `${this.url}/admin/users/${id}`, {
|
|
199
219
|
headers: this.headers,
|
|
200
220
|
xform: fetch_1._userResponse,
|
|
201
221
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GoTrueAdminApi.js","sourceRoot":"","sources":["../../src/GoTrueAdminApi.ts"],"names":[],"mappings":"
|
|
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;QACtB,I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AO,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"}
|
|
@@ -2,7 +2,7 @@ import GoTrueAdminApi from './GoTrueAdminApi';
|
|
|
2
2
|
import { AuthError } from './lib/errors';
|
|
3
3
|
import { Fetch } from './lib/fetch';
|
|
4
4
|
import { Deferred } from './lib/helpers';
|
|
5
|
-
import type { AuthChangeEvent, AuthResponse, CallRefreshTokenResult, OAuthResponse, Session, SignInWithOAuthCredentials, SignInWithPasswordCredentials, SignInWithPasswordlessCredentials, SignUpWithPasswordCredentials, Subscription, SupportedStorage, UserAttributes, UserResponse, VerifyOtpParams } from './lib/types';
|
|
5
|
+
import type { AuthChangeEvent, AuthResponse, CallRefreshTokenResult, GoTrueClientOptions, InitializeResult, OAuthResponse, Session, SignInWithOAuthCredentials, SignInWithPasswordCredentials, SignInWithPasswordlessCredentials, SignUpWithPasswordCredentials, Subscription, SupportedStorage, UserAttributes, UserResponse, VerifyOtpParams } from './lib/types';
|
|
6
6
|
export default class GoTrueClient {
|
|
7
7
|
/**
|
|
8
8
|
* Namespace for the GoTrue admin methods.
|
|
@@ -25,6 +25,14 @@ export default class GoTrueClient {
|
|
|
25
25
|
protected refreshTokenTimer?: ReturnType<typeof setTimeout>;
|
|
26
26
|
protected networkRetries: number;
|
|
27
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;
|
|
28
36
|
protected url: string;
|
|
29
37
|
protected headers: {
|
|
30
38
|
[key: string]: string;
|
|
@@ -32,29 +40,21 @@ export default class GoTrueClient {
|
|
|
32
40
|
protected fetch: Fetch;
|
|
33
41
|
/**
|
|
34
42
|
* Create a new client for use in the browser.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
storageKey?: string;
|
|
51
|
-
detectSessionInUrl?: boolean;
|
|
52
|
-
autoRefreshToken?: boolean;
|
|
53
|
-
persistSession?: boolean;
|
|
54
|
-
storage?: SupportedStorage;
|
|
55
|
-
multiTab?: boolean;
|
|
56
|
-
fetch?: Fetch;
|
|
57
|
-
});
|
|
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;
|
|
58
58
|
/**
|
|
59
59
|
* Creates a new user.
|
|
60
60
|
* @returns A logged-in session if the server has "autoconfirm" ON
|
|
@@ -62,7 +62,7 @@ export default class GoTrueClient {
|
|
|
62
62
|
*/
|
|
63
63
|
signUp(credentials: SignUpWithPasswordCredentials): Promise<AuthResponse>;
|
|
64
64
|
/**
|
|
65
|
-
* Log in an existing user
|
|
65
|
+
* Log in an existing user with an email and password or phone and password.
|
|
66
66
|
*/
|
|
67
67
|
signInWithPassword(credentials: SignInWithPasswordCredentials): Promise<AuthResponse>;
|
|
68
68
|
/**
|
|
@@ -70,21 +70,19 @@ export default class GoTrueClient {
|
|
|
70
70
|
*/
|
|
71
71
|
signInWithOAuth(credentials: SignInWithOAuthCredentials): Promise<OAuthResponse>;
|
|
72
72
|
/**
|
|
73
|
-
*
|
|
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.
|
|
74
77
|
*/
|
|
75
78
|
signInWithOtp(credentials: SignInWithPasswordlessCredentials): Promise<AuthResponse>;
|
|
76
79
|
/**
|
|
77
80
|
* Log in a user given a User supplied OTP received via mobile.
|
|
78
|
-
* @param options.redirectTo A URL to send the user to after they are confirmed.
|
|
79
|
-
* @param options.captchaToken Verification token received when the user completes the captcha on the site.
|
|
80
81
|
*/
|
|
81
|
-
verifyOtp(params: VerifyOtpParams
|
|
82
|
-
redirectTo?: string;
|
|
83
|
-
captchaToken?: string;
|
|
84
|
-
}): Promise<AuthResponse>;
|
|
82
|
+
verifyOtp(params: VerifyOtpParams): Promise<AuthResponse>;
|
|
85
83
|
/**
|
|
86
|
-
* Returns the session
|
|
87
|
-
*
|
|
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.
|
|
88
86
|
*/
|
|
89
87
|
getSession(): Promise<{
|
|
90
88
|
data: {
|
|
@@ -112,17 +110,23 @@ export default class GoTrueClient {
|
|
|
112
110
|
*/
|
|
113
111
|
updateUser(attributes: UserAttributes): Promise<UserResponse>;
|
|
114
112
|
/**
|
|
115
|
-
* Sets the session data from
|
|
116
|
-
*
|
|
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.
|
|
117
117
|
*/
|
|
118
|
-
setSession(
|
|
118
|
+
setSession(currentSession: Pick<Session, 'access_token' | 'refresh_token'>): Promise<AuthResponse>;
|
|
119
119
|
/**
|
|
120
120
|
* Gets the session data from a URL string
|
|
121
121
|
*/
|
|
122
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;
|
|
123
127
|
/**
|
|
124
128
|
* Inside a browser context, `signOut()` will remove the logged in user from the browser session
|
|
125
|
-
* 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.
|
|
126
130
|
*
|
|
127
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)`.
|
|
128
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.
|
|
@@ -133,19 +137,16 @@ export default class GoTrueClient {
|
|
|
133
137
|
/**
|
|
134
138
|
* Receive a notification every time an auth event happens.
|
|
135
139
|
* @param callback A callback function to be invoked when an auth event happens.
|
|
136
|
-
* @returns {Subscription} A subscription object which can be used to unsubscribe itself.
|
|
137
140
|
*/
|
|
138
141
|
onAuthStateChange(callback: (event: AuthChangeEvent, session: Session | null) => void): {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
subscription: null;
|
|
143
|
-
error: AuthError;
|
|
142
|
+
data: {
|
|
143
|
+
subscription: Subscription;
|
|
144
|
+
};
|
|
144
145
|
};
|
|
145
146
|
/**
|
|
146
|
-
* Sends a reset request to an email address.
|
|
147
|
+
* Sends a password reset request to an email address.
|
|
147
148
|
* @param email The email address of the user.
|
|
148
|
-
* @param options.redirectTo
|
|
149
|
+
* @param options.redirectTo The URL to send the user to after they click the password reset link.
|
|
149
150
|
* @param options.captchaToken Verification token received when the user completes the captcha on the site.
|
|
150
151
|
*/
|
|
151
152
|
resetPasswordForEmail(email: string, options?: {
|
|
@@ -163,7 +164,7 @@ export default class GoTrueClient {
|
|
|
163
164
|
* @param refreshToken A valid refresh token that was returned on login.
|
|
164
165
|
*/
|
|
165
166
|
private _refreshAccessToken;
|
|
166
|
-
private
|
|
167
|
+
private _isValidSession;
|
|
167
168
|
private _handleProviderSignIn;
|
|
168
169
|
/**
|
|
169
170
|
* Recovers the session from LocalStorage and refreshes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GoTrueClient.d.ts","sourceRoot":"","sources":["../../src/GoTrueClient.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAQ7C,OAAO,
|
|
1
|
+
{"version":3,"file":"GoTrueClient.d.ts","sourceRoot":"","sources":["../../src/GoTrueClient.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAQ7C,OAAO,EACL,SAAS,EAOV,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,KAAK,EAA6C,MAAM,aAAa,CAAA;AAC9E,OAAO,EAEL,QAAQ,EAQT,MAAM,eAAe,CAAA;AAGtB,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EACZ,sBAAsB,EACtB,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,EAEb,OAAO,EACP,0BAA0B,EAC1B,6BAA6B,EAC7B,iCAAiC,EACjC,6BAA6B,EAC7B,YAAY,EACZ,gBAAgB,EAEhB,cAAc,EACd,YAAY,EACZ,eAAe,EAChB,MAAM,aAAa,CAAA;AAapB,MAAM,CAAC,OAAO,OAAO,YAAY;IAC/B;;;OAGG;IACH,KAAK,EAAE,cAAc,CAAA;IACrB;;OAEG;IACH,SAAS,CAAC,UAAU,EAAE,MAAM,CAAA;IAE5B;;;OAGG;IACH,SAAS,CAAC,eAAe,EAAE,OAAO,GAAG,IAAI,CAAA;IAEzC,SAAS,CAAC,gBAAgB,EAAE,OAAO,CAAA;IACnC,SAAS,CAAC,cAAc,EAAE,OAAO,CAAA;IACjC,SAAS,CAAC,OAAO,EAAE,gBAAgB,CAAA;IACnC,SAAS,CAAC,mBAAmB,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAY;IACpE,SAAS,CAAC,iBAAiB,CAAC,EAAE,UAAU,CAAC,OAA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