@netlify/identity 0.3.0-alpha.7 → 0.3.1-alpha.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 +45 -18
- package/dist/index.cjs +105 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +33 -2
- package/dist/index.d.ts +33 -2
- package/dist/index.js +104 -1
- package/dist/index.js.map +1 -1
- package/package.json +10 -3
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# @netlify/identity
|
|
2
2
|
|
|
3
|
-
A lightweight, no-config headless authentication library for projects using Netlify Identity
|
|
3
|
+
A lightweight, no-config headless authentication library for projects using Netlify Identity. Works in both browser and server contexts.
|
|
4
|
+
This is NOT the Netlify Identity Widget. This library exports standalone async functions (e.g., import { login, getUser } from '@netlify/identity'). There is no class to instantiate and no .init() call. Just import the functions you need and call them.
|
|
4
5
|
|
|
5
6
|
> **Status:** Beta. The API may change before 1.0.
|
|
6
7
|
|
|
@@ -17,14 +18,14 @@ A lightweight, no-config headless authentication library for projects using Netl
|
|
|
17
18
|
| [`netlify-identity-widget`](https://github.com/netlify/netlify-identity-widget) | Pre-built login/signup modal (HTML + CSS) | You want a drop-in UI component with no custom design |
|
|
18
19
|
| [`gotrue-js`](https://github.com/netlify/gotrue-js) | Low-level GoTrue HTTP client (browser only) | You're building your own auth wrapper and need direct API access |
|
|
19
20
|
|
|
20
|
-
This library
|
|
21
|
+
This library provides a unified API that works in both browser and server contexts, handles cookie management, and normalizes the user object. You do not need to install `gotrue-js` or the widget separately.
|
|
21
22
|
|
|
22
23
|
## Table of contents
|
|
23
24
|
|
|
24
25
|
- [Installation](#installation)
|
|
25
26
|
- [Quick start](#quick-start)
|
|
26
27
|
- [API](#api)
|
|
27
|
-
- [Functions](#functions) -- `getUser`, `login`, `signup`, `logout`, `oauthLogin`, `handleAuthCallback`, `onAuthChange`, `hydrateSession`, and more
|
|
28
|
+
- [Functions](#functions) -- `getUser`, `login`, `signup`, `logout`, `oauthLogin`, `handleAuthCallback`, `onAuthChange`, `hydrateSession`, `refreshSession`, and more
|
|
28
29
|
- [Admin Operations](#admin-operations) -- `admin.listUsers`, `admin.getUser`, `admin.createUser`, `admin.updateUser`, `admin.deleteUser`
|
|
29
30
|
- [Types](#types) -- `User`, `AuthEvent`, `CallbackResult`, `Settings`, `Admin`, `ListUsersOptions`, `CreateUserParams`, etc.
|
|
30
31
|
- [Errors](#errors) -- `AuthError`, `MissingIdentityError`
|
|
@@ -132,7 +133,7 @@ login(email: string, password: string): Promise<User>
|
|
|
132
133
|
|
|
133
134
|
Logs in with email and password. Works in both browser and server contexts.
|
|
134
135
|
|
|
135
|
-
In the browser,
|
|
136
|
+
In the browser, emits a `'login'` event. On the server (Netlify Functions, Edge Functions), calls the Identity API directly and sets the `nf_jwt` cookie via the Netlify runtime.
|
|
136
137
|
|
|
137
138
|
**Throws:** `AuthError` on invalid credentials or network failure. In the browser, `MissingIdentityError` if Identity is not configured. On the server, `AuthError` if the Netlify Functions runtime is not available.
|
|
138
139
|
|
|
@@ -158,7 +159,7 @@ logout(): Promise<void>
|
|
|
158
159
|
|
|
159
160
|
Logs out the current user and clears the session. Works in both browser and server contexts.
|
|
160
161
|
|
|
161
|
-
In the browser,
|
|
162
|
+
In the browser, emits a `'logout'` event. On the server, calls the Identity `/logout` endpoint with the JWT from the `nf_jwt` cookie, then deletes the cookie. Auth cookies are always cleared, even if the server call fails.
|
|
162
163
|
|
|
163
164
|
**Throws:** In the browser, `MissingIdentityError` if Identity is not configured. On the server, `AuthError` if the Netlify Functions runtime is not available.
|
|
164
165
|
|
|
@@ -198,11 +199,11 @@ Subscribes to auth state changes (login, logout, token refresh, user updates, an
|
|
|
198
199
|
hydrateSession(): Promise<User | null>
|
|
199
200
|
```
|
|
200
201
|
|
|
201
|
-
Bootstraps the browser-side
|
|
202
|
+
Bootstraps the browser-side session from server-set auth cookies (`nf_jwt`, `nf_refresh`). Returns the hydrated `User`, or `null` if no auth cookies are present. No-op on the server.
|
|
202
203
|
|
|
203
|
-
**When to use:** After a server-side login (e.g., via a Netlify Function or Server Action), the `nf_jwt` cookie is set but
|
|
204
|
+
**When to use:** After a server-side login (e.g., via a Netlify Function or Server Action), the `nf_jwt` cookie is set but no browser session exists yet. `getUser()` calls `hydrateSession()` automatically, but account operations like `updateUser()` or `verifyEmailChange()` require a live browser session. Call `hydrateSession()` explicitly if you need the session ready before calling those operations.
|
|
204
205
|
|
|
205
|
-
If a
|
|
206
|
+
If a browser session already exists (e.g., from a browser-side login), this is a no-op and returns the existing user.
|
|
206
207
|
|
|
207
208
|
```ts
|
|
208
209
|
import { hydrateSession, updateUser } from '@netlify/identity'
|
|
@@ -214,6 +215,30 @@ await hydrateSession()
|
|
|
214
215
|
await updateUser({ data: { full_name: 'Jane Doe' } })
|
|
215
216
|
```
|
|
216
217
|
|
|
218
|
+
#### `refreshSession`
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
refreshSession(): Promise<string | null>
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Refreshes an expired or near-expired session. Returns the new access token on success, or `null` if no refresh is needed or the refresh token is invalid/missing.
|
|
225
|
+
|
|
226
|
+
**Browser:** Checks if the current access token is near expiry and refreshes it if needed, syncing the new token to the `nf_jwt` cookie. Note: in the browser, the library automatically refreshes tokens in the background after `login()`, `hydrateSession()`, or `handleAuthCallback()`, so you typically don't need to call this manually.
|
|
227
|
+
|
|
228
|
+
**Server:** Reads the `nf_jwt` and `nf_refresh` cookies. If the access token is expired or within 60 seconds of expiry, exchanges the refresh token for a new access token via the Identity `/token` endpoint and updates both cookies on the response. Call this in framework middleware or at the start of server-side request handlers to ensure the JWT is valid for downstream processing.
|
|
229
|
+
|
|
230
|
+
**Throws:** `AuthError` on network failure or if the Identity endpoint URL cannot be determined. Does **not** throw for invalid/expired refresh tokens (returns `null` instead).
|
|
231
|
+
|
|
232
|
+
```ts
|
|
233
|
+
// Example: Astro middleware
|
|
234
|
+
import { refreshSession } from '@netlify/identity'
|
|
235
|
+
|
|
236
|
+
export async function onRequest(context, next) {
|
|
237
|
+
await refreshSession()
|
|
238
|
+
return next()
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
217
242
|
#### `requestPasswordRecovery`
|
|
218
243
|
|
|
219
244
|
```ts
|
|
@@ -279,7 +304,7 @@ Updates the current user's metadata or credentials. Requires an active session.
|
|
|
279
304
|
The `admin` namespace provides user management functions for administrators. These work in two contexts:
|
|
280
305
|
|
|
281
306
|
- **Server:** Uses the operator token from the Netlify runtime for full admin access. No logged-in user required.
|
|
282
|
-
- **Browser:** Uses the logged-in user's JWT
|
|
307
|
+
- **Browser:** Uses the logged-in user's JWT. The user must have an admin role.
|
|
283
308
|
|
|
284
309
|
```ts
|
|
285
310
|
import { admin } from '@netlify/identity'
|
|
@@ -315,7 +340,7 @@ export default async (req: Request, context: Context) => {
|
|
|
315
340
|
admin.listUsers(options?: ListUsersOptions): Promise<User[]>
|
|
316
341
|
```
|
|
317
342
|
|
|
318
|
-
Lists all users. Pagination options are supported on the server; they are ignored in the browser
|
|
343
|
+
Lists all users. Pagination options are supported on the server; they are ignored in the browser.
|
|
319
344
|
|
|
320
345
|
**Throws:** `AuthError` if the operator token is missing (server) or no user is logged in (browser).
|
|
321
346
|
|
|
@@ -460,7 +485,7 @@ interface ListUsersOptions {
|
|
|
460
485
|
}
|
|
461
486
|
```
|
|
462
487
|
|
|
463
|
-
Pagination options for `admin.listUsers()`. Only used on the server; pagination is ignored in the browser
|
|
488
|
+
Pagination options for `admin.listUsers()`. Only used on the server; pagination is ignored in the browser.
|
|
464
489
|
|
|
465
490
|
#### `CreateUserParams`
|
|
466
491
|
|
|
@@ -472,7 +497,7 @@ interface CreateUserParams {
|
|
|
472
497
|
}
|
|
473
498
|
```
|
|
474
499
|
|
|
475
|
-
Parameters for `admin.createUser()`. Optional `data` is spread into the
|
|
500
|
+
Parameters for `admin.createUser()`. Optional `data` is spread into the request body as top-level attributes (use it to set `app_metadata`, `user_metadata`, `role`, etc.).
|
|
476
501
|
|
|
477
502
|
#### `Admin`
|
|
478
503
|
|
|
@@ -506,7 +531,7 @@ Constants for auth event names. Use these instead of string literals for type sa
|
|
|
506
531
|
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
507
532
|
| `LOGIN` | `login()`, `signup()` (with autoconfirm), `recoverPassword()`, `handleAuthCallback()` (OAuth/confirmation), `hydrateSession()` |
|
|
508
533
|
| `LOGOUT` | `logout()` |
|
|
509
|
-
| `TOKEN_REFRESH` |
|
|
534
|
+
| `TOKEN_REFRESH` | The library's auto-refresh timer refreshes an expiring access token and syncs the new token to the `nf_jwt` cookie. Fires automatically after `login()`, `hydrateSession()`, or `handleAuthCallback()` establishes a session. |
|
|
510
535
|
| `USER_UPDATED` | `updateUser()`, `verifyEmailChange()`, `handleAuthCallback()` (email change) |
|
|
511
536
|
| `RECOVERY` | `handleAuthCallback()` (recovery token only). The user is authenticated but has **not** set a new password yet. Listen for this to redirect to a password reset form. `recoverPassword()` emits `LOGIN` instead because it completes both steps (token redemption + password change). |
|
|
512
537
|
|
|
@@ -564,7 +589,7 @@ For SSR frameworks (Next.js, Remix, Astro, TanStack Start), the recommended patt
|
|
|
564
589
|
- **Browser-side** for auth mutations: `login()`, `signup()`, `logout()`, `oauthLogin()`
|
|
565
590
|
- **Server-side** for reading auth state: `getUser()`, `getSettings()`, `getIdentityConfig()`
|
|
566
591
|
|
|
567
|
-
Browser-side auth mutations call the
|
|
592
|
+
Browser-side auth mutations call the Identity API directly from the browser, set the `nf_jwt` cookie, and emit `onAuthChange` events. This keeps the client UI in sync immediately. Server-side reads work because the cookie is sent with every request.
|
|
568
593
|
|
|
569
594
|
The library also supports server-side mutations (`login()`, `signup()`, `logout()` inside Netlify Functions), but these require the Netlify Functions runtime to set cookies. After a server-side mutation, you need a full page navigation so the browser sends the new cookie.
|
|
570
595
|
|
|
@@ -1010,14 +1035,16 @@ if (result?.type === 'invite' && result.token) {
|
|
|
1010
1035
|
|
|
1011
1036
|
### Session lifetime
|
|
1012
1037
|
|
|
1013
|
-
Sessions are managed by Netlify Identity
|
|
1038
|
+
Sessions are managed by Netlify Identity on the server side. The library stores two cookies:
|
|
1014
1039
|
|
|
1015
|
-
- **`nf_jwt`**: A short-lived JWT access token (default: 1 hour).
|
|
1040
|
+
- **`nf_jwt`**: A short-lived JWT access token (default: 1 hour).
|
|
1016
1041
|
- **`nf_refresh`**: A long-lived refresh token used to obtain new access tokens without re-authenticating.
|
|
1017
1042
|
|
|
1018
|
-
|
|
1043
|
+
**Browser auto-refresh:** After `login()`, `hydrateSession()`, or `handleAuthCallback()` establishes a session, the library automatically schedules a background refresh 60 seconds before the access token expires. When the refresh fires, it obtains a new access token, syncs it to the `nf_jwt` cookie, and emits a `TOKEN_REFRESH` event. This keeps the cookie fresh as long as the user has the tab open. If the refresh fails (e.g., the refresh token was revoked), the timer stops and the user will need to log in again.
|
|
1044
|
+
|
|
1045
|
+
**Server-side refresh:** On the server, the access token in the `nf_jwt` cookie is validated as-is. If it has expired and no refresh happens, `getUser()` returns `null`. To handle this, call `refreshSession()` in your framework middleware or request handler. This checks if the token is near expiry, exchanges the refresh token for a new one, and updates the cookies on the response.
|
|
1019
1046
|
|
|
1020
|
-
Session lifetime is configured in your
|
|
1047
|
+
Session lifetime is configured in your Netlify Identity settings, not in this library.
|
|
1021
1048
|
|
|
1022
1049
|
## License
|
|
1023
1050
|
|
package/dist/index.cjs
CHANGED
|
@@ -47,6 +47,7 @@ __export(index_exports, {
|
|
|
47
47
|
oauthLogin: () => oauthLogin,
|
|
48
48
|
onAuthChange: () => onAuthChange,
|
|
49
49
|
recoverPassword: () => recoverPassword,
|
|
50
|
+
refreshSession: () => refreshSession,
|
|
50
51
|
requestPasswordRecovery: () => requestPasswordRecovery,
|
|
51
52
|
signup: () => signup,
|
|
52
53
|
updateUser: () => updateUser,
|
|
@@ -271,6 +272,98 @@ var onAuthChange = (callback) => {
|
|
|
271
272
|
};
|
|
272
273
|
};
|
|
273
274
|
|
|
275
|
+
// src/refresh.ts
|
|
276
|
+
var REFRESH_MARGIN_S = 60;
|
|
277
|
+
var refreshTimer = null;
|
|
278
|
+
var startTokenRefresh = () => {
|
|
279
|
+
if (!isBrowser()) return;
|
|
280
|
+
stopTokenRefresh();
|
|
281
|
+
const client = getGoTrueClient();
|
|
282
|
+
const user = client?.currentUser();
|
|
283
|
+
if (!user) return;
|
|
284
|
+
const token = user.tokenDetails();
|
|
285
|
+
if (!token?.expires_at) return;
|
|
286
|
+
const nowS = Math.floor(Date.now() / 1e3);
|
|
287
|
+
const expiresAtS = typeof token.expires_at === "number" && token.expires_at > 1e12 ? Math.floor(token.expires_at / 1e3) : token.expires_at;
|
|
288
|
+
const delayMs = Math.max(0, expiresAtS - nowS - REFRESH_MARGIN_S) * 1e3;
|
|
289
|
+
refreshTimer = setTimeout(async () => {
|
|
290
|
+
try {
|
|
291
|
+
const freshJwt = await user.jwt(true);
|
|
292
|
+
const freshDetails = user.tokenDetails();
|
|
293
|
+
setBrowserAuthCookies(freshJwt, freshDetails?.refresh_token);
|
|
294
|
+
emitAuthEvent(AUTH_EVENTS.TOKEN_REFRESH, toUser(user));
|
|
295
|
+
startTokenRefresh();
|
|
296
|
+
} catch {
|
|
297
|
+
stopTokenRefresh();
|
|
298
|
+
}
|
|
299
|
+
}, delayMs);
|
|
300
|
+
};
|
|
301
|
+
var stopTokenRefresh = () => {
|
|
302
|
+
if (refreshTimer !== null) {
|
|
303
|
+
clearTimeout(refreshTimer);
|
|
304
|
+
refreshTimer = null;
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
var refreshSession = async () => {
|
|
308
|
+
if (isBrowser()) {
|
|
309
|
+
const client = getGoTrueClient();
|
|
310
|
+
const user = client?.currentUser();
|
|
311
|
+
if (!user) return null;
|
|
312
|
+
const details = user.tokenDetails();
|
|
313
|
+
if (details?.expires_at) {
|
|
314
|
+
const nowS2 = Math.floor(Date.now() / 1e3);
|
|
315
|
+
const expiresAtS = typeof details.expires_at === "number" && details.expires_at > 1e12 ? Math.floor(details.expires_at / 1e3) : details.expires_at;
|
|
316
|
+
if (expiresAtS - nowS2 > REFRESH_MARGIN_S) {
|
|
317
|
+
return null;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
try {
|
|
321
|
+
const jwt = await user.jwt(true);
|
|
322
|
+
setBrowserAuthCookies(jwt, user.tokenDetails()?.refresh_token);
|
|
323
|
+
return jwt;
|
|
324
|
+
} catch {
|
|
325
|
+
return null;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
const accessToken = getServerCookie(NF_JWT_COOKIE);
|
|
329
|
+
const refreshToken = getServerCookie(NF_REFRESH_COOKIE);
|
|
330
|
+
if (!accessToken || !refreshToken) return null;
|
|
331
|
+
const decoded = decodeJwtPayload(accessToken);
|
|
332
|
+
if (!decoded?.exp) return null;
|
|
333
|
+
const nowS = Math.floor(Date.now() / 1e3);
|
|
334
|
+
if (decoded.exp - nowS > REFRESH_MARGIN_S) {
|
|
335
|
+
return null;
|
|
336
|
+
}
|
|
337
|
+
const ctx = getIdentityContext();
|
|
338
|
+
const identityUrl = ctx?.url ?? (globalThis.Netlify?.context?.url ? new URL(IDENTITY_PATH, globalThis.Netlify.context.url).href : null);
|
|
339
|
+
if (!identityUrl) {
|
|
340
|
+
throw new AuthError("Could not determine the Identity endpoint URL for token refresh");
|
|
341
|
+
}
|
|
342
|
+
let res;
|
|
343
|
+
try {
|
|
344
|
+
res = await fetch(`${identityUrl}/token`, {
|
|
345
|
+
method: "POST",
|
|
346
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
347
|
+
body: `grant_type=refresh_token&refresh_token=${refreshToken}`
|
|
348
|
+
});
|
|
349
|
+
} catch (error) {
|
|
350
|
+
throw AuthError.from(error);
|
|
351
|
+
}
|
|
352
|
+
if (!res.ok) {
|
|
353
|
+
const errorBody = await res.json().catch(() => ({}));
|
|
354
|
+
if (res.status === 401 || res.status === 400) {
|
|
355
|
+
return null;
|
|
356
|
+
}
|
|
357
|
+
throw new AuthError(errorBody.msg || `Token refresh failed (${res.status})`, res.status);
|
|
358
|
+
}
|
|
359
|
+
const data = await res.json();
|
|
360
|
+
const cookies = globalThis.Netlify?.context?.cookies;
|
|
361
|
+
if (cookies) {
|
|
362
|
+
setAuthCookies(cookies, data.access_token, data.refresh_token);
|
|
363
|
+
}
|
|
364
|
+
return data.access_token;
|
|
365
|
+
};
|
|
366
|
+
|
|
274
367
|
// src/auth.ts
|
|
275
368
|
var getCookies = () => {
|
|
276
369
|
const cookies = globalThis.Netlify?.context?.cookies;
|
|
@@ -335,6 +428,7 @@ var login = async (email, password) => {
|
|
|
335
428
|
const jwt = await gotrueUser.jwt();
|
|
336
429
|
setBrowserAuthCookies(jwt, gotrueUser.tokenDetails()?.refresh_token);
|
|
337
430
|
const user = toUser(gotrueUser);
|
|
431
|
+
startTokenRefresh();
|
|
338
432
|
emitAuthEvent(AUTH_EVENTS.LOGIN, user);
|
|
339
433
|
return user;
|
|
340
434
|
} catch (error) {
|
|
@@ -379,6 +473,7 @@ var signup = async (email, password, data) => {
|
|
|
379
473
|
const refreshToken = response.tokenDetails?.()?.refresh_token;
|
|
380
474
|
setBrowserAuthCookies(jwt, refreshToken);
|
|
381
475
|
}
|
|
476
|
+
startTokenRefresh();
|
|
382
477
|
emitAuthEvent(AUTH_EVENTS.LOGIN, user);
|
|
383
478
|
}
|
|
384
479
|
return user;
|
|
@@ -410,6 +505,7 @@ var logout = async () => {
|
|
|
410
505
|
await currentUser.logout();
|
|
411
506
|
}
|
|
412
507
|
deleteBrowserAuthCookies();
|
|
508
|
+
stopTokenRefresh();
|
|
413
509
|
emitAuthEvent(AUTH_EVENTS.LOGOUT, null);
|
|
414
510
|
} catch (error) {
|
|
415
511
|
throw AuthError.from(error);
|
|
@@ -462,6 +558,7 @@ var handleOAuthCallback = async (client, params, accessToken) => {
|
|
|
462
558
|
);
|
|
463
559
|
setBrowserAuthCookies(accessToken, refreshToken || void 0);
|
|
464
560
|
const user = toUser(gotrueUser);
|
|
561
|
+
startTokenRefresh();
|
|
465
562
|
clearHash();
|
|
466
563
|
emitAuthEvent(AUTH_EVENTS.LOGIN, user);
|
|
467
564
|
return { type: "oauth", user };
|
|
@@ -471,6 +568,7 @@ var handleConfirmationCallback = async (client, token) => {
|
|
|
471
568
|
const jwt = await gotrueUser.jwt();
|
|
472
569
|
setBrowserAuthCookies(jwt, gotrueUser.tokenDetails()?.refresh_token);
|
|
473
570
|
const user = toUser(gotrueUser);
|
|
571
|
+
startTokenRefresh();
|
|
474
572
|
clearHash();
|
|
475
573
|
emitAuthEvent(AUTH_EVENTS.LOGIN, user);
|
|
476
574
|
return { type: "confirmation", user };
|
|
@@ -480,6 +578,7 @@ var handleRecoveryCallback = async (client, token) => {
|
|
|
480
578
|
const jwt = await gotrueUser.jwt();
|
|
481
579
|
setBrowserAuthCookies(jwt, gotrueUser.tokenDetails()?.refresh_token);
|
|
482
580
|
const user = toUser(gotrueUser);
|
|
581
|
+
startTokenRefresh();
|
|
483
582
|
clearHash();
|
|
484
583
|
emitAuthEvent(AUTH_EVENTS.RECOVERY, user);
|
|
485
584
|
return { type: "recovery", user };
|
|
@@ -547,6 +646,7 @@ var hydrateSession = async () => {
|
|
|
547
646
|
return null;
|
|
548
647
|
}
|
|
549
648
|
const user = toUser(gotrueUser);
|
|
649
|
+
startTokenRefresh();
|
|
550
650
|
emitAuthEvent(AUTH_EVENTS.LOGIN, user);
|
|
551
651
|
return user;
|
|
552
652
|
};
|
|
@@ -661,7 +761,7 @@ var getUser = async () => {
|
|
|
661
761
|
if (fullUser) return fullUser;
|
|
662
762
|
}
|
|
663
763
|
}
|
|
664
|
-
const claims = identityContext?.user ??
|
|
764
|
+
const claims = identityContext?.user ?? null;
|
|
665
765
|
return claims ? claimsToUser(claims) : null;
|
|
666
766
|
};
|
|
667
767
|
var isAuthenticated = async () => await getUser() !== null;
|
|
@@ -724,6 +824,7 @@ var recoverPassword = async (token, newPassword) => {
|
|
|
724
824
|
const gotrueUser = await client.recover(token, persistSession);
|
|
725
825
|
const updatedUser = await gotrueUser.update({ password: newPassword });
|
|
726
826
|
const user = toUser(updatedUser);
|
|
827
|
+
startTokenRefresh();
|
|
727
828
|
emitAuthEvent(AUTH_EVENTS.LOGIN, user);
|
|
728
829
|
return user;
|
|
729
830
|
} catch (error) {
|
|
@@ -735,6 +836,7 @@ var confirmEmail = async (token) => {
|
|
|
735
836
|
try {
|
|
736
837
|
const gotrueUser = await client.confirm(token, persistSession);
|
|
737
838
|
const user = toUser(gotrueUser);
|
|
839
|
+
startTokenRefresh();
|
|
738
840
|
emitAuthEvent(AUTH_EVENTS.LOGIN, user);
|
|
739
841
|
return user;
|
|
740
842
|
} catch (error) {
|
|
@@ -746,6 +848,7 @@ var acceptInvite = async (token, password) => {
|
|
|
746
848
|
try {
|
|
747
849
|
const gotrueUser = await client.acceptInvite(token, password, persistSession);
|
|
748
850
|
const user = toUser(gotrueUser);
|
|
851
|
+
startTokenRefresh();
|
|
749
852
|
emitAuthEvent(AUTH_EVENTS.LOGIN, user);
|
|
750
853
|
return user;
|
|
751
854
|
} catch (error) {
|
|
@@ -943,6 +1046,7 @@ var admin = { listUsers, getUser: getUser2, createUser, updateUser: updateUser2,
|
|
|
943
1046
|
oauthLogin,
|
|
944
1047
|
onAuthChange,
|
|
945
1048
|
recoverPassword,
|
|
1049
|
+
refreshSession,
|
|
946
1050
|
requestPasswordRecovery,
|
|
947
1051
|
signup,
|
|
948
1052
|
updateUser,
|