@supabase/auth-js 2.61.0
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/LICENSE +21 -0
- package/README.md +50 -0
- package/dist/main/AuthAdminApi.d.ts +4 -0
- package/dist/main/AuthAdminApi.d.ts.map +1 -0
- package/dist/main/AuthAdminApi.js +9 -0
- package/dist/main/AuthAdminApi.js.map +1 -0
- package/dist/main/AuthClient.d.ts +4 -0
- package/dist/main/AuthClient.d.ts.map +1 -0
- package/dist/main/AuthClient.js +9 -0
- package/dist/main/AuthClient.js.map +1 -0
- package/dist/main/GoTrueAdminApi.d.ts +99 -0
- package/dist/main/GoTrueAdminApi.d.ts.map +1 -0
- package/dist/main/GoTrueAdminApi.js +268 -0
- package/dist/main/GoTrueAdminApi.js.map +1 -0
- package/dist/main/GoTrueClient.d.ts +432 -0
- package/dist/main/GoTrueClient.d.ts.map +1 -0
- package/dist/main/GoTrueClient.js +1889 -0
- package/dist/main/GoTrueClient.js.map +1 -0
- package/dist/main/index.d.ts +9 -0
- package/dist/main/index.d.ts.map +1 -0
- package/dist/main/index.js +35 -0
- package/dist/main/index.js.map +1 -0
- package/dist/main/lib/constants.d.ts +12 -0
- package/dist/main/lib/constants.d.ts.map +1 -0
- package/dist/main/lib/constants.js +14 -0
- package/dist/main/lib/constants.js.map +1 -0
- package/dist/main/lib/errors.d.ts +96 -0
- package/dist/main/lib/errors.d.ts.map +1 -0
- package/dist/main/lib/errors.js +135 -0
- package/dist/main/lib/errors.js.map +1 -0
- package/dist/main/lib/fetch.d.ts +33 -0
- package/dist/main/lib/fetch.d.ts.map +1 -0
- package/dist/main/lib/fetch.js +162 -0
- package/dist/main/lib/fetch.js.map +1 -0
- package/dist/main/lib/helpers.d.ts +48 -0
- package/dist/main/lib/helpers.d.ts.map +1 -0
- package/dist/main/lib/helpers.js +292 -0
- package/dist/main/lib/helpers.js.map +1 -0
- package/dist/main/lib/local-storage.d.ts +13 -0
- package/dist/main/lib/local-storage.d.ts.map +1 -0
- package/dist/main/lib/local-storage.js +46 -0
- package/dist/main/lib/local-storage.js.map +1 -0
- package/dist/main/lib/locks.d.ts +44 -0
- package/dist/main/lib/locks.d.ts.map +1 -0
- package/dist/main/lib/locks.js +118 -0
- package/dist/main/lib/locks.js.map +1 -0
- package/dist/main/lib/polyfills.d.ts +5 -0
- package/dist/main/lib/polyfills.d.ts.map +1 -0
- package/dist/main/lib/polyfills.js +30 -0
- package/dist/main/lib/polyfills.js.map +1 -0
- package/dist/main/lib/types.d.ts +948 -0
- package/dist/main/lib/types.d.ts.map +1 -0
- package/dist/main/lib/types.js +3 -0
- package/dist/main/lib/types.js.map +1 -0
- package/dist/main/lib/version.d.ts +2 -0
- package/dist/main/lib/version.d.ts.map +1 -0
- package/dist/main/lib/version.js +6 -0
- package/dist/main/lib/version.js.map +1 -0
- package/dist/module/AuthAdminApi.d.ts +4 -0
- package/dist/module/AuthAdminApi.d.ts.map +1 -0
- package/dist/module/AuthAdminApi.js +4 -0
- package/dist/module/AuthAdminApi.js.map +1 -0
- package/dist/module/AuthClient.d.ts +4 -0
- package/dist/module/AuthClient.d.ts.map +1 -0
- package/dist/module/AuthClient.js +4 -0
- package/dist/module/AuthClient.js.map +1 -0
- package/dist/module/GoTrueAdminApi.d.ts +99 -0
- package/dist/module/GoTrueAdminApi.d.ts.map +1 -0
- package/dist/module/GoTrueAdminApi.js +265 -0
- package/dist/module/GoTrueAdminApi.js.map +1 -0
- package/dist/module/GoTrueClient.d.ts +432 -0
- package/dist/module/GoTrueClient.d.ts.map +1 -0
- package/dist/module/GoTrueClient.js +1883 -0
- package/dist/module/GoTrueClient.js.map +1 -0
- package/dist/module/index.d.ts +9 -0
- package/dist/module/index.d.ts.map +1 -0
- package/dist/module/index.js +9 -0
- package/dist/module/index.js.map +1 -0
- package/dist/module/lib/constants.d.ts +12 -0
- package/dist/module/lib/constants.d.ts.map +1 -0
- package/dist/module/lib/constants.js +11 -0
- package/dist/module/lib/constants.js.map +1 -0
- package/dist/module/lib/errors.d.ts +96 -0
- package/dist/module/lib/errors.d.ts.map +1 -0
- package/dist/module/lib/errors.js +117 -0
- package/dist/module/lib/errors.js.map +1 -0
- package/dist/module/lib/fetch.d.ts +33 -0
- package/dist/module/lib/fetch.d.ts.map +1 -0
- package/dist/module/lib/fetch.js +152 -0
- package/dist/module/lib/fetch.js.map +1 -0
- package/dist/module/lib/helpers.d.ts +48 -0
- package/dist/module/lib/helpers.d.ts.map +1 -0
- package/dist/module/lib/helpers.js +249 -0
- package/dist/module/lib/helpers.js.map +1 -0
- package/dist/module/lib/local-storage.d.ts +13 -0
- package/dist/module/lib/local-storage.d.ts.map +1 -0
- package/dist/module/lib/local-storage.js +42 -0
- package/dist/module/lib/local-storage.js.map +1 -0
- package/dist/module/lib/locks.d.ts +44 -0
- package/dist/module/lib/locks.d.ts.map +1 -0
- package/dist/module/lib/locks.js +112 -0
- package/dist/module/lib/locks.js.map +1 -0
- package/dist/module/lib/polyfills.d.ts +5 -0
- package/dist/module/lib/polyfills.d.ts.map +1 -0
- package/dist/module/lib/polyfills.js +26 -0
- package/dist/module/lib/polyfills.js.map +1 -0
- package/dist/module/lib/types.d.ts +948 -0
- package/dist/module/lib/types.d.ts.map +1 -0
- package/dist/module/lib/types.js +2 -0
- package/dist/module/lib/types.js.map +1 -0
- package/dist/module/lib/version.d.ts +2 -0
- package/dist/module/lib/version.d.ts.map +1 -0
- package/dist/module/lib/version.js +3 -0
- package/dist/module/lib/version.js.map +1 -0
- package/package.json +69 -0
- package/src/AuthAdminApi.ts +5 -0
- package/src/AuthClient.ts +5 -0
- package/src/GoTrueAdminApi.ts +333 -0
- package/src/GoTrueClient.ts +2470 -0
- package/src/index.ts +12 -0
- package/src/lib/constants.ts +10 -0
- package/src/lib/errors.ts +150 -0
- package/src/lib/fetch.ts +238 -0
- package/src/lib/helpers.ts +306 -0
- package/src/lib/local-storage.ts +49 -0
- package/src/lib/locks.ts +140 -0
- package/src/lib/polyfills.ts +23 -0
- package/src/lib/types.ts +1120 -0
- package/src/lib/version.ts +2 -0
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
import GoTrueAdminApi from './GoTrueAdminApi';
|
|
2
|
+
import { AuthError } from './lib/errors';
|
|
3
|
+
import { Fetch } from './lib/fetch';
|
|
4
|
+
import { Deferred } from './lib/helpers';
|
|
5
|
+
import type { AuthChangeEvent, AuthResponse, AuthTokenResponse, AuthTokenResponsePassword, AuthOtpResponse, CallRefreshTokenResult, GoTrueClientOptions, InitializeResult, OAuthResponse, SSOResponse, Session, SignInWithIdTokenCredentials, SignInWithOAuthCredentials, SignInWithPasswordCredentials, SignInWithPasswordlessCredentials, SignUpWithPasswordCredentials, SignInWithSSO, SignOut, Subscription, SupportedStorage, UserAttributes, UserResponse, VerifyOtpParams, GoTrueMFAApi, ResendParams, AuthFlowType, LockFunc, UserIdentity } from './lib/types';
|
|
6
|
+
export default class GoTrueClient {
|
|
7
|
+
private static nextInstanceID;
|
|
8
|
+
private instanceID;
|
|
9
|
+
/**
|
|
10
|
+
* Namespace for the GoTrue admin methods.
|
|
11
|
+
* These methods should only be used in a trusted server-side environment.
|
|
12
|
+
*/
|
|
13
|
+
admin: GoTrueAdminApi;
|
|
14
|
+
/**
|
|
15
|
+
* Namespace for the MFA methods.
|
|
16
|
+
*/
|
|
17
|
+
mfa: GoTrueMFAApi;
|
|
18
|
+
/**
|
|
19
|
+
* The storage key used to identify the values saved in localStorage
|
|
20
|
+
*/
|
|
21
|
+
protected storageKey: string;
|
|
22
|
+
protected flowType: AuthFlowType;
|
|
23
|
+
protected autoRefreshToken: boolean;
|
|
24
|
+
protected persistSession: boolean;
|
|
25
|
+
protected storage: SupportedStorage;
|
|
26
|
+
protected memoryStorage: {
|
|
27
|
+
[key: string]: string;
|
|
28
|
+
} | null;
|
|
29
|
+
protected stateChangeEmitters: Map<string, Subscription>;
|
|
30
|
+
protected autoRefreshTicker: ReturnType<typeof setInterval> | null;
|
|
31
|
+
protected visibilityChangedCallback: (() => Promise<any>) | null;
|
|
32
|
+
protected refreshingDeferred: Deferred<CallRefreshTokenResult> | null;
|
|
33
|
+
/**
|
|
34
|
+
* Keeps track of the async client initialization.
|
|
35
|
+
* When null or not yet resolved the auth state is `unknown`
|
|
36
|
+
* Once resolved the the auth state is known and it's save to call any further client methods.
|
|
37
|
+
* Keep extra care to never reject or throw uncaught errors
|
|
38
|
+
*/
|
|
39
|
+
protected initializePromise: Promise<InitializeResult> | null;
|
|
40
|
+
protected detectSessionInUrl: boolean;
|
|
41
|
+
protected url: string;
|
|
42
|
+
protected headers: {
|
|
43
|
+
[key: string]: string;
|
|
44
|
+
};
|
|
45
|
+
protected fetch: Fetch;
|
|
46
|
+
protected lock: LockFunc;
|
|
47
|
+
protected lockAcquired: boolean;
|
|
48
|
+
protected pendingInLock: Promise<any>[];
|
|
49
|
+
/**
|
|
50
|
+
* Used to broadcast state change events to other tabs listening.
|
|
51
|
+
*/
|
|
52
|
+
protected broadcastChannel: BroadcastChannel | null;
|
|
53
|
+
protected logDebugMessages: boolean;
|
|
54
|
+
protected logger: (message: string, ...args: any[]) => void;
|
|
55
|
+
/**
|
|
56
|
+
* Create a new client for use in the browser.
|
|
57
|
+
*/
|
|
58
|
+
constructor(options: GoTrueClientOptions);
|
|
59
|
+
private _debug;
|
|
60
|
+
/**
|
|
61
|
+
* Initializes the client session either from the url or from storage.
|
|
62
|
+
* This method is automatically called when instantiating the client, but should also be called
|
|
63
|
+
* manually when checking for an error from an auth redirect (oauth, magiclink, password recovery, etc).
|
|
64
|
+
*/
|
|
65
|
+
initialize(): Promise<InitializeResult>;
|
|
66
|
+
/**
|
|
67
|
+
* IMPORTANT:
|
|
68
|
+
* 1. Never throw in this method, as it is called from the constructor
|
|
69
|
+
* 2. Never return a session from this method as it would be cached over
|
|
70
|
+
* the whole lifetime of the client
|
|
71
|
+
*/
|
|
72
|
+
private _initialize;
|
|
73
|
+
/**
|
|
74
|
+
* Creates a new user.
|
|
75
|
+
*
|
|
76
|
+
* Be aware that if a user account exists in the system you may get back an
|
|
77
|
+
* error message that attempts to hide this information from the user.
|
|
78
|
+
* This method has support for PKCE via email signups. The PKCE flow cannot be used when autoconfirm is enabled.
|
|
79
|
+
*
|
|
80
|
+
* @returns A logged-in session if the server has "autoconfirm" ON
|
|
81
|
+
* @returns A user if the server has "autoconfirm" OFF
|
|
82
|
+
*/
|
|
83
|
+
signUp(credentials: SignUpWithPasswordCredentials): Promise<AuthResponse>;
|
|
84
|
+
/**
|
|
85
|
+
* Log in an existing user with an email and password or phone and password.
|
|
86
|
+
*
|
|
87
|
+
* Be aware that you may get back an error message that will not distinguish
|
|
88
|
+
* between the cases where the account does not exist or that the
|
|
89
|
+
* email/phone and password combination is wrong or that the account can only
|
|
90
|
+
* be accessed via social login.
|
|
91
|
+
*/
|
|
92
|
+
signInWithPassword(credentials: SignInWithPasswordCredentials): Promise<AuthTokenResponsePassword>;
|
|
93
|
+
/**
|
|
94
|
+
* Log in an existing user via a third-party provider.
|
|
95
|
+
* This method supports the PKCE flow.
|
|
96
|
+
*/
|
|
97
|
+
signInWithOAuth(credentials: SignInWithOAuthCredentials): Promise<OAuthResponse>;
|
|
98
|
+
/**
|
|
99
|
+
* Log in an existing user by exchanging an Auth Code issued during the PKCE flow.
|
|
100
|
+
*/
|
|
101
|
+
exchangeCodeForSession(authCode: string): Promise<AuthTokenResponse>;
|
|
102
|
+
private _exchangeCodeForSession;
|
|
103
|
+
/**
|
|
104
|
+
* Allows signing in with an OIDC ID token. The authentication provider used
|
|
105
|
+
* should be enabled and configured.
|
|
106
|
+
*/
|
|
107
|
+
signInWithIdToken(credentials: SignInWithIdTokenCredentials): Promise<AuthTokenResponse>;
|
|
108
|
+
/**
|
|
109
|
+
* Log in a user using magiclink or a one-time password (OTP).
|
|
110
|
+
*
|
|
111
|
+
* If the `{{ .ConfirmationURL }}` variable is specified in the email template, a magiclink will be sent.
|
|
112
|
+
* If the `{{ .Token }}` variable is specified in the email template, an OTP will be sent.
|
|
113
|
+
* 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
|
+
*
|
|
115
|
+
* Be aware that you may get back an error message that will not distinguish
|
|
116
|
+
* between the cases where the account does not exist or, that the account
|
|
117
|
+
* can only be accessed via social login.
|
|
118
|
+
*
|
|
119
|
+
* Do note that you will need to configure a Whatsapp sender on Twilio
|
|
120
|
+
* if you are using phone sign in with the 'whatsapp' channel. The whatsapp
|
|
121
|
+
* channel is not supported on other providers
|
|
122
|
+
* at this time.
|
|
123
|
+
* This method supports PKCE when an email is passed.
|
|
124
|
+
*/
|
|
125
|
+
signInWithOtp(credentials: SignInWithPasswordlessCredentials): Promise<AuthOtpResponse>;
|
|
126
|
+
/**
|
|
127
|
+
* Log in a user given a User supplied OTP or TokenHash received through mobile or email.
|
|
128
|
+
*/
|
|
129
|
+
verifyOtp(params: VerifyOtpParams): Promise<AuthResponse>;
|
|
130
|
+
/**
|
|
131
|
+
* Attempts a single-sign on using an enterprise Identity Provider. A
|
|
132
|
+
* successful SSO attempt will redirect the current page to the identity
|
|
133
|
+
* provider authorization page. The redirect URL is implementation and SSO
|
|
134
|
+
* protocol specific.
|
|
135
|
+
*
|
|
136
|
+
* You can use it by providing a SSO domain. Typically you can extract this
|
|
137
|
+
* domain by asking users for their email address. If this domain is
|
|
138
|
+
* registered on the Auth instance the redirect will use that organization's
|
|
139
|
+
* currently active SSO Identity Provider for the login.
|
|
140
|
+
*
|
|
141
|
+
* If you have built an organization-specific login page, you can use the
|
|
142
|
+
* organization's SSO Identity Provider UUID directly instead.
|
|
143
|
+
*/
|
|
144
|
+
signInWithSSO(params: SignInWithSSO): Promise<SSOResponse>;
|
|
145
|
+
/**
|
|
146
|
+
* Sends a reauthentication OTP to the user's email or phone number.
|
|
147
|
+
* Requires the user to be signed-in.
|
|
148
|
+
*/
|
|
149
|
+
reauthenticate(): Promise<AuthResponse>;
|
|
150
|
+
private _reauthenticate;
|
|
151
|
+
/**
|
|
152
|
+
* Resends an existing signup confirmation email, email change email, SMS OTP or phone change OTP.
|
|
153
|
+
*/
|
|
154
|
+
resend(credentials: ResendParams): Promise<AuthOtpResponse>;
|
|
155
|
+
/**
|
|
156
|
+
* Returns the session, refreshing it if necessary.
|
|
157
|
+
* 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.
|
|
158
|
+
*/
|
|
159
|
+
getSession(): Promise<{
|
|
160
|
+
data: {
|
|
161
|
+
session: Session;
|
|
162
|
+
};
|
|
163
|
+
error: null;
|
|
164
|
+
} | {
|
|
165
|
+
data: {
|
|
166
|
+
session: null;
|
|
167
|
+
};
|
|
168
|
+
error: AuthError;
|
|
169
|
+
} | {
|
|
170
|
+
data: {
|
|
171
|
+
session: null;
|
|
172
|
+
};
|
|
173
|
+
error: null;
|
|
174
|
+
}>;
|
|
175
|
+
/**
|
|
176
|
+
* Acquires a global lock based on the storage key.
|
|
177
|
+
*/
|
|
178
|
+
private _acquireLock;
|
|
179
|
+
/**
|
|
180
|
+
* Use instead of {@link #getSession} inside the library. It is
|
|
181
|
+
* semantically usually what you want, as getting a session involves some
|
|
182
|
+
* processing afterwards that requires only one client operating on the
|
|
183
|
+
* session at once across multiple tabs or processes.
|
|
184
|
+
*/
|
|
185
|
+
private _useSession;
|
|
186
|
+
/**
|
|
187
|
+
* NEVER USE DIRECTLY!
|
|
188
|
+
*
|
|
189
|
+
* Always use {@link #_useSession}.
|
|
190
|
+
*/
|
|
191
|
+
private __loadSession;
|
|
192
|
+
/**
|
|
193
|
+
* Gets the current user details if there is an existing session.
|
|
194
|
+
* @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.
|
|
195
|
+
*/
|
|
196
|
+
getUser(jwt?: string): Promise<UserResponse>;
|
|
197
|
+
private _getUser;
|
|
198
|
+
/**
|
|
199
|
+
* Updates user data for a logged in user.
|
|
200
|
+
*/
|
|
201
|
+
updateUser(attributes: UserAttributes, options?: {
|
|
202
|
+
emailRedirectTo?: string | undefined;
|
|
203
|
+
}): Promise<UserResponse>;
|
|
204
|
+
protected _updateUser(attributes: UserAttributes, options?: {
|
|
205
|
+
emailRedirectTo?: string | undefined;
|
|
206
|
+
}): Promise<UserResponse>;
|
|
207
|
+
/**
|
|
208
|
+
* Decodes a JWT (without performing any validation).
|
|
209
|
+
*/
|
|
210
|
+
private _decodeJWT;
|
|
211
|
+
/**
|
|
212
|
+
* 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.
|
|
213
|
+
* If the refresh token or access token in the current session is invalid, an error will be thrown.
|
|
214
|
+
* @param currentSession The current session that minimally contains an access token and refresh token.
|
|
215
|
+
*/
|
|
216
|
+
setSession(currentSession: {
|
|
217
|
+
access_token: string;
|
|
218
|
+
refresh_token: string;
|
|
219
|
+
}): Promise<AuthResponse>;
|
|
220
|
+
protected _setSession(currentSession: {
|
|
221
|
+
access_token: string;
|
|
222
|
+
refresh_token: string;
|
|
223
|
+
}): Promise<AuthResponse>;
|
|
224
|
+
/**
|
|
225
|
+
* Returns a new session, regardless of expiry status.
|
|
226
|
+
* Takes in an optional current session. If not passed in, then refreshSession() will attempt to retrieve it from getSession().
|
|
227
|
+
* If the current session's refresh token is invalid, an error will be thrown.
|
|
228
|
+
* @param currentSession The current session. If passed in, it must contain a refresh token.
|
|
229
|
+
*/
|
|
230
|
+
refreshSession(currentSession?: {
|
|
231
|
+
refresh_token: string;
|
|
232
|
+
}): Promise<AuthResponse>;
|
|
233
|
+
protected _refreshSession(currentSession?: {
|
|
234
|
+
refresh_token: string;
|
|
235
|
+
}): Promise<AuthResponse>;
|
|
236
|
+
/**
|
|
237
|
+
* Gets the session data from a URL string
|
|
238
|
+
*/
|
|
239
|
+
private _getSessionFromURL;
|
|
240
|
+
/**
|
|
241
|
+
* 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)
|
|
242
|
+
*/
|
|
243
|
+
private _isImplicitGrantFlow;
|
|
244
|
+
/**
|
|
245
|
+
* Checks if the current URL and backing storage contain parameters given by a PKCE flow
|
|
246
|
+
*/
|
|
247
|
+
private _isPKCEFlow;
|
|
248
|
+
/**
|
|
249
|
+
* Inside a browser context, `signOut()` will remove the logged in user from the browser session and log them out - removing all items from localstorage and then trigger a `"SIGNED_OUT"` event.
|
|
250
|
+
*
|
|
251
|
+
* 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)`.
|
|
252
|
+
* 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.
|
|
253
|
+
*
|
|
254
|
+
* If using `others` scope, no `SIGNED_OUT` event is fired!
|
|
255
|
+
*/
|
|
256
|
+
signOut(options?: SignOut): Promise<{
|
|
257
|
+
error: AuthError | null;
|
|
258
|
+
}>;
|
|
259
|
+
protected _signOut({ scope }?: SignOut): Promise<{
|
|
260
|
+
error: AuthError | null;
|
|
261
|
+
}>;
|
|
262
|
+
/**
|
|
263
|
+
* Receive a notification every time an auth event happens.
|
|
264
|
+
* @param callback A callback function to be invoked when an auth event happens.
|
|
265
|
+
*/
|
|
266
|
+
onAuthStateChange(callback: (event: AuthChangeEvent, session: Session | null) => void | Promise<void>): {
|
|
267
|
+
data: {
|
|
268
|
+
subscription: Subscription;
|
|
269
|
+
};
|
|
270
|
+
};
|
|
271
|
+
private _emitInitialSession;
|
|
272
|
+
/**
|
|
273
|
+
* Sends a password reset request to an email address. This method supports the PKCE flow.
|
|
274
|
+
*
|
|
275
|
+
* @param email The email address of the user.
|
|
276
|
+
* @param options.redirectTo The URL to send the user to after they click the password reset link.
|
|
277
|
+
* @param options.captchaToken Verification token received when the user completes the captcha on the site.
|
|
278
|
+
*/
|
|
279
|
+
resetPasswordForEmail(email: string, options?: {
|
|
280
|
+
redirectTo?: string;
|
|
281
|
+
captchaToken?: string;
|
|
282
|
+
}): Promise<{
|
|
283
|
+
data: {};
|
|
284
|
+
error: null;
|
|
285
|
+
} | {
|
|
286
|
+
data: null;
|
|
287
|
+
error: AuthError;
|
|
288
|
+
}>;
|
|
289
|
+
/**
|
|
290
|
+
* Gets all the identities linked to a user.
|
|
291
|
+
*/
|
|
292
|
+
getUserIdentities(): Promise<{
|
|
293
|
+
data: {
|
|
294
|
+
identities: UserIdentity[];
|
|
295
|
+
};
|
|
296
|
+
error: null;
|
|
297
|
+
} | {
|
|
298
|
+
data: null;
|
|
299
|
+
error: AuthError;
|
|
300
|
+
}>;
|
|
301
|
+
/**
|
|
302
|
+
* Links an oauth identity to an existing user.
|
|
303
|
+
* This method supports the PKCE flow.
|
|
304
|
+
*/
|
|
305
|
+
linkIdentity(credentials: SignInWithOAuthCredentials): Promise<OAuthResponse>;
|
|
306
|
+
/**
|
|
307
|
+
* Unlinks an identity from a user by deleting it. The user will no longer be able to sign in with that identity once it's unlinked.
|
|
308
|
+
*/
|
|
309
|
+
unlinkIdentity(identity: UserIdentity): Promise<{
|
|
310
|
+
data: {};
|
|
311
|
+
error: null;
|
|
312
|
+
} | {
|
|
313
|
+
data: null;
|
|
314
|
+
error: AuthError;
|
|
315
|
+
}>;
|
|
316
|
+
/**
|
|
317
|
+
* Generates a new JWT.
|
|
318
|
+
* @param refreshToken A valid refresh token that was returned on login.
|
|
319
|
+
*/
|
|
320
|
+
private _refreshAccessToken;
|
|
321
|
+
private _isValidSession;
|
|
322
|
+
private _handleProviderSignIn;
|
|
323
|
+
/**
|
|
324
|
+
* Recovers the session from LocalStorage and refreshes
|
|
325
|
+
* Note: this method is async to accommodate for AsyncStorage e.g. in React native.
|
|
326
|
+
*/
|
|
327
|
+
private _recoverAndRefresh;
|
|
328
|
+
private _callRefreshToken;
|
|
329
|
+
private _notifyAllSubscribers;
|
|
330
|
+
/**
|
|
331
|
+
* set currentSession and currentUser
|
|
332
|
+
* process to _startAutoRefreshToken if possible
|
|
333
|
+
*/
|
|
334
|
+
private _saveSession;
|
|
335
|
+
private _removeSession;
|
|
336
|
+
/**
|
|
337
|
+
* Removes any registered visibilitychange callback.
|
|
338
|
+
*
|
|
339
|
+
* {@see #startAutoRefresh}
|
|
340
|
+
* {@see #stopAutoRefresh}
|
|
341
|
+
*/
|
|
342
|
+
private _removeVisibilityChangedCallback;
|
|
343
|
+
/**
|
|
344
|
+
* This is the private implementation of {@link #startAutoRefresh}. Use this
|
|
345
|
+
* within the library.
|
|
346
|
+
*/
|
|
347
|
+
private _startAutoRefresh;
|
|
348
|
+
/**
|
|
349
|
+
* This is the private implementation of {@link #stopAutoRefresh}. Use this
|
|
350
|
+
* within the library.
|
|
351
|
+
*/
|
|
352
|
+
private _stopAutoRefresh;
|
|
353
|
+
/**
|
|
354
|
+
* Starts an auto-refresh process in the background. The session is checked
|
|
355
|
+
* every few seconds. Close to the time of expiration a process is started to
|
|
356
|
+
* refresh the session. If refreshing fails it will be retried for as long as
|
|
357
|
+
* necessary.
|
|
358
|
+
*
|
|
359
|
+
* If you set the {@link GoTrueClientOptions#autoRefreshToken} you don't need
|
|
360
|
+
* to call this function, it will be called for you.
|
|
361
|
+
*
|
|
362
|
+
* On browsers the refresh process works only when the tab/window is in the
|
|
363
|
+
* foreground to conserve resources as well as prevent race conditions and
|
|
364
|
+
* flooding auth with requests. If you call this method any managed
|
|
365
|
+
* visibility change callback will be removed and you must manage visibility
|
|
366
|
+
* changes on your own.
|
|
367
|
+
*
|
|
368
|
+
* On non-browser platforms the refresh process works *continuously* in the
|
|
369
|
+
* background, which may not be desirable. You should hook into your
|
|
370
|
+
* platform's foreground indication mechanism and call these methods
|
|
371
|
+
* appropriately to conserve resources.
|
|
372
|
+
*
|
|
373
|
+
* {@see #stopAutoRefresh}
|
|
374
|
+
*/
|
|
375
|
+
startAutoRefresh(): Promise<void>;
|
|
376
|
+
/**
|
|
377
|
+
* Stops an active auto refresh process running in the background (if any).
|
|
378
|
+
*
|
|
379
|
+
* If you call this method any managed visibility change callback will be
|
|
380
|
+
* removed and you must manage visibility changes on your own.
|
|
381
|
+
*
|
|
382
|
+
* See {@link #startAutoRefresh} for more details.
|
|
383
|
+
*/
|
|
384
|
+
stopAutoRefresh(): Promise<void>;
|
|
385
|
+
/**
|
|
386
|
+
* Runs the auto refresh token tick.
|
|
387
|
+
*/
|
|
388
|
+
private _autoRefreshTokenTick;
|
|
389
|
+
/**
|
|
390
|
+
* Registers callbacks on the browser / platform, which in-turn run
|
|
391
|
+
* algorithms when the browser window/tab are in foreground. On non-browser
|
|
392
|
+
* platforms it assumes always foreground.
|
|
393
|
+
*/
|
|
394
|
+
private _handleVisibilityChange;
|
|
395
|
+
/**
|
|
396
|
+
* Callback registered with `window.addEventListener('visibilitychange')`.
|
|
397
|
+
*/
|
|
398
|
+
private _onVisibilityChanged;
|
|
399
|
+
/**
|
|
400
|
+
* Generates the relevant login URL for a third-party provider.
|
|
401
|
+
* @param options.redirectTo A URL or mobile address to send the user to after they are confirmed.
|
|
402
|
+
* @param options.scopes A space-separated list of scopes granted to the OAuth application.
|
|
403
|
+
* @param options.queryParams An object of key-value pairs containing query parameters granted to the OAuth application.
|
|
404
|
+
*/
|
|
405
|
+
private _getUrlForProvider;
|
|
406
|
+
private _unenroll;
|
|
407
|
+
/**
|
|
408
|
+
* {@see GoTrueMFAApi#enroll}
|
|
409
|
+
*/
|
|
410
|
+
private _enroll;
|
|
411
|
+
/**
|
|
412
|
+
* {@see GoTrueMFAApi#verify}
|
|
413
|
+
*/
|
|
414
|
+
private _verify;
|
|
415
|
+
/**
|
|
416
|
+
* {@see GoTrueMFAApi#challenge}
|
|
417
|
+
*/
|
|
418
|
+
private _challenge;
|
|
419
|
+
/**
|
|
420
|
+
* {@see GoTrueMFAApi#challengeAndVerify}
|
|
421
|
+
*/
|
|
422
|
+
private _challengeAndVerify;
|
|
423
|
+
/**
|
|
424
|
+
* {@see GoTrueMFAApi#listFactors}
|
|
425
|
+
*/
|
|
426
|
+
private _listFactors;
|
|
427
|
+
/**
|
|
428
|
+
* {@see GoTrueMFAApi#getAuthenticatorAssuranceLevel}
|
|
429
|
+
*/
|
|
430
|
+
private _getAuthenticatorAssuranceLevel;
|
|
431
|
+
}
|
|
432
|
+
//# sourceMappingURL=GoTrueClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GoTrueClient.d.ts","sourceRoot":"","sources":["../../src/GoTrueClient.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAE7C,OAAO,EACL,SAAS,EAUV,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,KAAK,EAMN,MAAM,aAAa,CAAA;AACpB,OAAO,EAEL,QAAQ,EAaT,MAAM,eAAe,CAAA;AAMtB,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EAEZ,iBAAiB,EACjB,yBAAyB,EACzB,eAAe,EACf,sBAAsB,EACtB,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,EACb,WAAW,EAEX,OAAO,EACP,4BAA4B,EAC5B,0BAA0B,EAC1B,6BAA6B,EAC7B,iCAAiC,EACjC,6BAA6B,EAC7B,aAAa,EACb,OAAO,EACP,YAAY,EACZ,gBAAgB,EAEhB,cAAc,EACd,YAAY,EACZ,eAAe,EACf,YAAY,EAeZ,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,YAAY,EAEb,MAAM,aAAa,CAAA;AA0BpB,MAAM,CAAC,OAAO,OAAO,YAAY;IAC/B,OAAO,CAAC,MAAM,CAAC,cAAc,CAAI;IAEjC,OAAO,CAAC,UAAU,CAAQ;IAE1B;;;OAGG;IACH,KAAK,EAAE,cAAc,CAAA;IACrB;;OAEG;IACH,GAAG,EAAE,YAAY,CAAA;IACjB;;OAEG;IACH,SAAS,CAAC,UAAU,EAAE,MAAM,CAAA;IAE5B,SAAS,CAAC,QAAQ,EAAE,YAAY,CAAA;IAEhC,SAAS,CAAC,gBAAgB,EAAE,OAAO,CAAA;IACnC,SAAS,CAAC,cAAc,EAAE,OAAO,CAAA;IACjC,SAAS,CAAC,OAAO,EAAE,gBAAgB,CAAA;IACnC,SAAS,CAAC,aAAa,EAAE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