@netlify/identity 0.1.1-alpha.2 → 0.1.1-alpha.4
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 +128 -7
- package/dist/index.cjs +131 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -5
- package/dist/index.d.ts +7 -5
- package/dist/index.js +130 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -74,7 +74,7 @@ Returns the current authenticated user, or `null` if not logged in. Synchronous,
|
|
|
74
74
|
isAuthenticated(): boolean
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
Returns `true` if a user is currently authenticated. Equivalent to `getUser() !== null`.
|
|
77
|
+
Returns `true` if a user is currently authenticated. Equivalent to `getUser() !== null`. Never throws.
|
|
78
78
|
|
|
79
79
|
#### `getIdentityConfig`
|
|
80
80
|
|
|
@@ -90,7 +90,9 @@ Returns the Identity endpoint URL (and operator token on the server), or `null`
|
|
|
90
90
|
getSettings(): Promise<Settings>
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
-
Fetches your project's Identity settings (enabled providers, autoconfirm, signup disabled).
|
|
93
|
+
Fetches your project's Identity settings (enabled providers, autoconfirm, signup disabled).
|
|
94
|
+
|
|
95
|
+
**Throws:** `MissingIdentityError` if Identity is not configured. `AuthError` if the endpoint is unreachable.
|
|
94
96
|
|
|
95
97
|
#### `login`
|
|
96
98
|
|
|
@@ -98,7 +100,11 @@ Fetches your project's Identity settings (enabled providers, autoconfirm, signup
|
|
|
98
100
|
login(email: string, password: string): Promise<User>
|
|
99
101
|
```
|
|
100
102
|
|
|
101
|
-
Logs in with email and password.
|
|
103
|
+
Logs in with email and password. Works in both browser and server contexts.
|
|
104
|
+
|
|
105
|
+
In the browser, uses gotrue-js and emits a `'login'` event. On the server (Netlify Functions, Edge Functions), calls the GoTrue HTTP API directly and sets the `nf_jwt` cookie via the Netlify runtime.
|
|
106
|
+
|
|
107
|
+
**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.
|
|
102
108
|
|
|
103
109
|
#### `signup`
|
|
104
110
|
|
|
@@ -106,7 +112,11 @@ Logs in with email and password. Browser only.
|
|
|
106
112
|
signup(email: string, password: string, data?: Record<string, unknown>): Promise<User>
|
|
107
113
|
```
|
|
108
114
|
|
|
109
|
-
Creates a new account.
|
|
115
|
+
Creates a new account. Works in both browser and server contexts.
|
|
116
|
+
|
|
117
|
+
In the browser, uses gotrue-js and emits `'login'` if autoconfirm is enabled. On the server, calls the GoTrue HTTP API directly and sets the `nf_jwt` cookie if the user is auto-confirmed.
|
|
118
|
+
|
|
119
|
+
**Throws:** `AuthError` on failure (e.g., email already registered, signup disabled). In the browser, `MissingIdentityError` if Identity is not configured. On the server, `AuthError` if the Netlify Functions runtime is not available.
|
|
110
120
|
|
|
111
121
|
#### `logout`
|
|
112
122
|
|
|
@@ -114,7 +124,11 @@ Creates a new account. Emits `'login'` if autoconfirm is enabled. Browser only.
|
|
|
114
124
|
logout(): Promise<void>
|
|
115
125
|
```
|
|
116
126
|
|
|
117
|
-
Logs out the current user and clears the session.
|
|
127
|
+
Logs out the current user and clears the session. Works in both browser and server contexts.
|
|
128
|
+
|
|
129
|
+
In the browser, uses gotrue-js and emits a `'logout'` event. On the server, calls GoTrue's `/logout` endpoint with the JWT from the `nf_jwt` cookie, then deletes the cookie.
|
|
130
|
+
|
|
131
|
+
**Throws:** `AuthError` on network failure. In the browser, `MissingIdentityError` if Identity is not configured. On the server, `AuthError` if the Netlify Functions runtime is not available.
|
|
118
132
|
|
|
119
133
|
#### `oauthLogin`
|
|
120
134
|
|
|
@@ -122,7 +136,11 @@ Logs out the current user and clears the session. Browser only.
|
|
|
122
136
|
oauthLogin(provider: string): never
|
|
123
137
|
```
|
|
124
138
|
|
|
125
|
-
Redirects to an OAuth provider.
|
|
139
|
+
Redirects to an OAuth provider. The page navigates away, so this function never returns normally. Browser only.
|
|
140
|
+
|
|
141
|
+
The `provider` argument should be one of the `AuthProvider` values: `'google'`, `'github'`, `'gitlab'`, `'bitbucket'`, `'facebook'`, or `'saml'`.
|
|
142
|
+
|
|
143
|
+
**Throws:** `MissingIdentityError` if Identity is not configured. `Error` if called on the server.
|
|
126
144
|
|
|
127
145
|
#### `handleAuthCallback`
|
|
128
146
|
|
|
@@ -132,6 +150,8 @@ handleAuthCallback(): Promise<CallbackResult | null>
|
|
|
132
150
|
|
|
133
151
|
Processes the URL hash after an OAuth redirect, email confirmation, password recovery, invite acceptance, or email change. Call on page load. Returns `null` if the hash contains no auth parameters. Browser only.
|
|
134
152
|
|
|
153
|
+
**Throws:** `MissingIdentityError` if Identity is not configured. `AuthError` if token exchange fails.
|
|
154
|
+
|
|
135
155
|
#### `onAuthChange`
|
|
136
156
|
|
|
137
157
|
```ts
|
|
@@ -148,6 +168,8 @@ requestPasswordRecovery(email: string): Promise<void>
|
|
|
148
168
|
|
|
149
169
|
Sends a password recovery email to the given address.
|
|
150
170
|
|
|
171
|
+
**Throws:** `MissingIdentityError` if Identity is not configured. `AuthError` on network failure.
|
|
172
|
+
|
|
151
173
|
#### `confirmEmail`
|
|
152
174
|
|
|
153
175
|
```ts
|
|
@@ -156,6 +178,8 @@ confirmEmail(token: string): Promise<User>
|
|
|
156
178
|
|
|
157
179
|
Confirms an email address using the token from a confirmation email. Logs the user in on success.
|
|
158
180
|
|
|
181
|
+
**Throws:** `MissingIdentityError` if Identity is not configured. `AuthError` if the token is invalid or expired.
|
|
182
|
+
|
|
159
183
|
#### `acceptInvite`
|
|
160
184
|
|
|
161
185
|
```ts
|
|
@@ -164,13 +188,27 @@ acceptInvite(token: string, password: string): Promise<User>
|
|
|
164
188
|
|
|
165
189
|
Accepts an invite token and sets a password for the new account. Logs the user in on success.
|
|
166
190
|
|
|
191
|
+
**Throws:** `MissingIdentityError` if Identity is not configured. `AuthError` if the token is invalid or expired.
|
|
192
|
+
|
|
167
193
|
#### `verifyEmailChange`
|
|
168
194
|
|
|
169
195
|
```ts
|
|
170
196
|
verifyEmailChange(token: string): Promise<User>
|
|
171
197
|
```
|
|
172
198
|
|
|
173
|
-
Verifies an email change using the token from a verification email.
|
|
199
|
+
Verifies an email change using the token from a verification email.
|
|
200
|
+
|
|
201
|
+
**Throws:** `MissingIdentityError` if Identity is not configured. `AuthError` if the token is invalid.
|
|
202
|
+
|
|
203
|
+
#### `recoverPassword`
|
|
204
|
+
|
|
205
|
+
```ts
|
|
206
|
+
recoverPassword(token: string, newPassword: string): Promise<User>
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Redeems a recovery token and sets a new password. Logs the user in on success.
|
|
210
|
+
|
|
211
|
+
**Throws:** `MissingIdentityError` if Identity is not configured. `AuthError` if the token is invalid or expired.
|
|
174
212
|
|
|
175
213
|
#### `updateUser`
|
|
176
214
|
|
|
@@ -180,6 +218,8 @@ updateUser(updates: Record<string, unknown>): Promise<User>
|
|
|
180
218
|
|
|
181
219
|
Updates the current user's metadata or credentials. Requires an active session.
|
|
182
220
|
|
|
221
|
+
**Throws:** `MissingIdentityError` if Identity is not configured. `AuthError` if no user is logged in, or the update fails.
|
|
222
|
+
|
|
183
223
|
### Types
|
|
184
224
|
|
|
185
225
|
#### `User`
|
|
@@ -256,6 +296,11 @@ interface CallbackResult {
|
|
|
256
296
|
}
|
|
257
297
|
```
|
|
258
298
|
|
|
299
|
+
The `token` field is only present for `invite` callbacks, where the user hasn't set a password yet. Pass `token` to `acceptInvite(token, password)` to finish.
|
|
300
|
+
|
|
301
|
+
For all other types (`oauth`, `confirmation`, `recovery`, `email_change`), the user is logged in directly and `token` is not set.
|
|
302
|
+
|
|
303
|
+
|
|
259
304
|
### Errors
|
|
260
305
|
|
|
261
306
|
#### `AuthError`
|
|
@@ -277,6 +322,61 @@ Thrown when Identity is not configured in the current environment.
|
|
|
277
322
|
|
|
278
323
|
## Guides
|
|
279
324
|
|
|
325
|
+
### Listening for auth changes
|
|
326
|
+
|
|
327
|
+
Use `onAuthChange` to keep your UI in sync with auth state. It fires on login, logout, token refresh, and user updates. It also detects session changes in other browser tabs (via `localStorage`).
|
|
328
|
+
|
|
329
|
+
```ts
|
|
330
|
+
import { onAuthChange } from '@netlify/identity'
|
|
331
|
+
|
|
332
|
+
const unsubscribe = onAuthChange((event, user) => {
|
|
333
|
+
switch (event) {
|
|
334
|
+
case 'login':
|
|
335
|
+
console.log('Logged in:', user?.email)
|
|
336
|
+
break
|
|
337
|
+
case 'logout':
|
|
338
|
+
console.log('Logged out')
|
|
339
|
+
break
|
|
340
|
+
case 'token_refresh':
|
|
341
|
+
console.log('Token refreshed for:', user?.email)
|
|
342
|
+
break
|
|
343
|
+
case 'user_updated':
|
|
344
|
+
console.log('User updated:', user?.email)
|
|
345
|
+
break
|
|
346
|
+
}
|
|
347
|
+
})
|
|
348
|
+
|
|
349
|
+
// Later, to stop listening:
|
|
350
|
+
unsubscribe()
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
On the server, `onAuthChange` is a no-op and the returned unsubscribe function does nothing.
|
|
354
|
+
|
|
355
|
+
### OAuth login
|
|
356
|
+
|
|
357
|
+
OAuth login is a two-step flow: redirect the user to the provider, then process the callback when they return.
|
|
358
|
+
|
|
359
|
+
**Step by step:**
|
|
360
|
+
|
|
361
|
+
```ts
|
|
362
|
+
import { oauthLogin, handleAuthCallback } from '@netlify/identity'
|
|
363
|
+
|
|
364
|
+
// 1. Kick off the OAuth flow (e.g., from a "Sign in with GitHub" button).
|
|
365
|
+
// This navigates away from the page and does not return.
|
|
366
|
+
oauthLogin('github')
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
```ts
|
|
370
|
+
// 2. On page load, handle the redirect back from the provider.
|
|
371
|
+
const result = await handleAuthCallback()
|
|
372
|
+
|
|
373
|
+
if (result?.type === 'oauth') {
|
|
374
|
+
console.log('Logged in via OAuth:', result.user?.email)
|
|
375
|
+
}
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
`handleAuthCallback()` exchanges the token in the URL hash, logs the user in, clears the hash, and emits a `'login'` event via `onAuthChange`.
|
|
379
|
+
|
|
280
380
|
### Password recovery
|
|
281
381
|
|
|
282
382
|
Password recovery is a two-step flow. The library handles the token exchange automatically via `handleAuthCallback()`, which logs the user in and returns `{type: 'recovery', user}`. You then show a "set new password" form and call `updateUser()` to save it.
|
|
@@ -300,6 +400,27 @@ if (result?.type === 'recovery') {
|
|
|
300
400
|
}
|
|
301
401
|
```
|
|
302
402
|
|
|
403
|
+
### Invite acceptance
|
|
404
|
+
|
|
405
|
+
When an admin invites a user, they receive an email with an invite link. Clicking it redirects to your site with an `invite_token` in the URL hash. Unlike other callback types, the user is not logged in automatically because they need to set a password first.
|
|
406
|
+
|
|
407
|
+
**Step by step:**
|
|
408
|
+
|
|
409
|
+
```ts
|
|
410
|
+
import { handleAuthCallback, acceptInvite } from '@netlify/identity'
|
|
411
|
+
|
|
412
|
+
// 1. On page load, handle the callback.
|
|
413
|
+
const result = await handleAuthCallback()
|
|
414
|
+
|
|
415
|
+
if (result?.type === 'invite' && result.token) {
|
|
416
|
+
// 2. The user is NOT logged in yet. Show a "set your password" form.
|
|
417
|
+
// When they submit:
|
|
418
|
+
const password = document.getElementById('password').value
|
|
419
|
+
const user = await acceptInvite(result.token, password)
|
|
420
|
+
console.log('Account created:', user.email)
|
|
421
|
+
}
|
|
422
|
+
```
|
|
423
|
+
|
|
303
424
|
## License
|
|
304
425
|
|
|
305
426
|
MIT
|
package/dist/index.cjs
CHANGED
|
@@ -43,6 +43,7 @@ __export(index_exports, {
|
|
|
43
43
|
logout: () => logout,
|
|
44
44
|
oauthLogin: () => oauthLogin,
|
|
45
45
|
onAuthChange: () => onAuthChange,
|
|
46
|
+
recoverPassword: () => recoverPassword,
|
|
46
47
|
requestPasswordRecovery: () => requestPasswordRecovery,
|
|
47
48
|
signup: () => signup,
|
|
48
49
|
updateUser: () => updateUser,
|
|
@@ -75,6 +76,7 @@ var MissingIdentityError = class extends Error {
|
|
|
75
76
|
};
|
|
76
77
|
|
|
77
78
|
// src/environment.ts
|
|
79
|
+
var IDENTITY_PATH = "/.netlify/identity";
|
|
78
80
|
var goTrueClient = null;
|
|
79
81
|
var cachedApiUrl;
|
|
80
82
|
var warnedMissingUrl = false;
|
|
@@ -82,13 +84,13 @@ var isBrowser = () => typeof window !== "undefined" && typeof window.location !=
|
|
|
82
84
|
var discoverApiUrl = () => {
|
|
83
85
|
if (cachedApiUrl !== void 0) return cachedApiUrl;
|
|
84
86
|
if (isBrowser()) {
|
|
85
|
-
cachedApiUrl = `${window.location.origin}
|
|
87
|
+
cachedApiUrl = `${window.location.origin}${IDENTITY_PATH}`;
|
|
86
88
|
} else {
|
|
87
89
|
const identityContext = getIdentityContext();
|
|
88
90
|
if (identityContext?.url) {
|
|
89
91
|
cachedApiUrl = identityContext.url;
|
|
90
92
|
} else if (globalThis.Netlify?.context?.url) {
|
|
91
|
-
cachedApiUrl = new URL(
|
|
93
|
+
cachedApiUrl = new URL(IDENTITY_PATH, globalThis.Netlify.context.url).href;
|
|
92
94
|
}
|
|
93
95
|
}
|
|
94
96
|
return cachedApiUrl ?? null;
|
|
@@ -115,14 +117,14 @@ var getClient = () => {
|
|
|
115
117
|
};
|
|
116
118
|
var getIdentityContext = () => {
|
|
117
119
|
const identityContext = globalThis.netlifyIdentityContext;
|
|
118
|
-
if (identityContext?.url
|
|
120
|
+
if (identityContext?.url) {
|
|
119
121
|
return {
|
|
120
122
|
url: identityContext.url,
|
|
121
|
-
token:
|
|
123
|
+
token: identityContext.token
|
|
122
124
|
};
|
|
123
125
|
}
|
|
124
126
|
if (globalThis.Netlify?.context?.url) {
|
|
125
|
-
return { url: new URL(
|
|
127
|
+
return { url: new URL(IDENTITY_PATH, globalThis.Netlify.context.url).href };
|
|
126
128
|
}
|
|
127
129
|
return null;
|
|
128
130
|
};
|
|
@@ -152,8 +154,8 @@ var claimsToUser = (claims) => {
|
|
|
152
154
|
const userMeta = claims.user_metadata ?? {};
|
|
153
155
|
const name = userMeta.full_name || userMeta.name;
|
|
154
156
|
return {
|
|
155
|
-
id:
|
|
156
|
-
email:
|
|
157
|
+
id: claims.sub ?? "",
|
|
158
|
+
email: claims.email,
|
|
157
159
|
provider: toAuthProvider(appMeta.provider),
|
|
158
160
|
name: typeof name === "string" ? name : void 0,
|
|
159
161
|
metadata: userMeta
|
|
@@ -167,17 +169,15 @@ var getUser = () => {
|
|
|
167
169
|
return toUser(currentUser);
|
|
168
170
|
}
|
|
169
171
|
const identityContext = globalThis.netlifyIdentityContext;
|
|
170
|
-
if (!identityContext) return null;
|
|
171
|
-
|
|
172
|
-
if (!claims) return null;
|
|
173
|
-
return claimsToUser(claims);
|
|
172
|
+
if (!identityContext?.user) return null;
|
|
173
|
+
return claimsToUser(identityContext.user);
|
|
174
174
|
};
|
|
175
175
|
var isAuthenticated = () => getUser() !== null;
|
|
176
176
|
|
|
177
177
|
// src/config.ts
|
|
178
178
|
var getIdentityConfig = () => {
|
|
179
179
|
if (isBrowser()) {
|
|
180
|
-
return { url: `${window.location.origin}
|
|
180
|
+
return { url: `${window.location.origin}${IDENTITY_PATH}` };
|
|
181
181
|
}
|
|
182
182
|
return getIdentityContext();
|
|
183
183
|
};
|
|
@@ -205,6 +205,20 @@ var getSettings = async () => {
|
|
|
205
205
|
};
|
|
206
206
|
|
|
207
207
|
// src/auth.ts
|
|
208
|
+
var getCookies = () => {
|
|
209
|
+
const cookies = globalThis.Netlify?.context?.cookies;
|
|
210
|
+
if (!cookies) {
|
|
211
|
+
throw new AuthError("Server-side auth requires Netlify Functions runtime");
|
|
212
|
+
}
|
|
213
|
+
return cookies;
|
|
214
|
+
};
|
|
215
|
+
var getServerIdentityUrl = () => {
|
|
216
|
+
const ctx = getIdentityContext();
|
|
217
|
+
if (!ctx?.url) {
|
|
218
|
+
throw new AuthError("Could not determine the Identity endpoint URL on the server");
|
|
219
|
+
}
|
|
220
|
+
return ctx.url;
|
|
221
|
+
};
|
|
208
222
|
var persistSession = true;
|
|
209
223
|
var listeners = /* @__PURE__ */ new Set();
|
|
210
224
|
var emitAuthEvent = (event, user) => {
|
|
@@ -239,6 +253,45 @@ var onAuthChange = (callback) => {
|
|
|
239
253
|
};
|
|
240
254
|
};
|
|
241
255
|
var login = async (email, password) => {
|
|
256
|
+
if (!isBrowser()) {
|
|
257
|
+
const identityUrl = getServerIdentityUrl();
|
|
258
|
+
const cookies = getCookies();
|
|
259
|
+
const body = new URLSearchParams({
|
|
260
|
+
grant_type: "password",
|
|
261
|
+
username: email,
|
|
262
|
+
password
|
|
263
|
+
});
|
|
264
|
+
let res;
|
|
265
|
+
try {
|
|
266
|
+
res = await fetch(`${identityUrl}/token`, {
|
|
267
|
+
method: "POST",
|
|
268
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
269
|
+
body: body.toString()
|
|
270
|
+
});
|
|
271
|
+
} catch (error) {
|
|
272
|
+
throw new AuthError(error.message, void 0, { cause: error });
|
|
273
|
+
}
|
|
274
|
+
if (!res.ok) {
|
|
275
|
+
const errorBody = await res.json().catch(() => ({}));
|
|
276
|
+
throw new AuthError(
|
|
277
|
+
errorBody.msg || errorBody.error_description || `Login failed (${res.status})`,
|
|
278
|
+
res.status
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
const data = await res.json();
|
|
282
|
+
const accessToken = data.access_token;
|
|
283
|
+
const userData = data;
|
|
284
|
+
const user = toUser(userData);
|
|
285
|
+
cookies.set({
|
|
286
|
+
name: "nf_jwt",
|
|
287
|
+
value: accessToken,
|
|
288
|
+
httpOnly: true,
|
|
289
|
+
secure: true,
|
|
290
|
+
path: "/",
|
|
291
|
+
sameSite: "Lax"
|
|
292
|
+
});
|
|
293
|
+
return user;
|
|
294
|
+
}
|
|
242
295
|
const client = getClient();
|
|
243
296
|
try {
|
|
244
297
|
const gotrueUser = await client.login(email, password, persistSession);
|
|
@@ -250,6 +303,40 @@ var login = async (email, password) => {
|
|
|
250
303
|
}
|
|
251
304
|
};
|
|
252
305
|
var signup = async (email, password, data) => {
|
|
306
|
+
if (!isBrowser()) {
|
|
307
|
+
const identityUrl = getServerIdentityUrl();
|
|
308
|
+
const cookies = getCookies();
|
|
309
|
+
let res;
|
|
310
|
+
try {
|
|
311
|
+
res = await fetch(`${identityUrl}/signup`, {
|
|
312
|
+
method: "POST",
|
|
313
|
+
headers: { "Content-Type": "application/json" },
|
|
314
|
+
body: JSON.stringify({ email, password, data })
|
|
315
|
+
});
|
|
316
|
+
} catch (error) {
|
|
317
|
+
throw new AuthError(error.message, void 0, { cause: error });
|
|
318
|
+
}
|
|
319
|
+
if (!res.ok) {
|
|
320
|
+
const errorBody = await res.json().catch(() => ({}));
|
|
321
|
+
throw new AuthError(errorBody.msg || `Signup failed (${res.status})`, res.status);
|
|
322
|
+
}
|
|
323
|
+
const responseData = await res.json();
|
|
324
|
+
const user = toUser(responseData);
|
|
325
|
+
if (responseData.confirmed_at) {
|
|
326
|
+
const accessToken = responseData.access_token;
|
|
327
|
+
if (accessToken) {
|
|
328
|
+
cookies.set({
|
|
329
|
+
name: "nf_jwt",
|
|
330
|
+
value: accessToken,
|
|
331
|
+
httpOnly: true,
|
|
332
|
+
secure: true,
|
|
333
|
+
path: "/",
|
|
334
|
+
sameSite: "Lax"
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return user;
|
|
339
|
+
}
|
|
253
340
|
const client = getClient();
|
|
254
341
|
try {
|
|
255
342
|
const response = await client.signup(email, password, data);
|
|
@@ -263,6 +350,23 @@ var signup = async (email, password, data) => {
|
|
|
263
350
|
}
|
|
264
351
|
};
|
|
265
352
|
var logout = async () => {
|
|
353
|
+
if (!isBrowser()) {
|
|
354
|
+
const identityUrl = getServerIdentityUrl();
|
|
355
|
+
const cookies = getCookies();
|
|
356
|
+
const jwt = cookies.get("nf_jwt");
|
|
357
|
+
if (jwt) {
|
|
358
|
+
try {
|
|
359
|
+
await fetch(`${identityUrl}/logout`, {
|
|
360
|
+
method: "POST",
|
|
361
|
+
headers: { Authorization: `Bearer ${jwt}` }
|
|
362
|
+
});
|
|
363
|
+
} catch (error) {
|
|
364
|
+
throw new AuthError(error.message, void 0, { cause: error });
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
cookies.delete("nf_jwt");
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
266
370
|
const client = getClient();
|
|
267
371
|
try {
|
|
268
372
|
const currentUser = client.currentUser();
|
|
@@ -329,12 +433,7 @@ var handleAuthCallback = async () => {
|
|
|
329
433
|
}
|
|
330
434
|
const emailChangeToken = params.get("email_change_token");
|
|
331
435
|
if (emailChangeToken) {
|
|
332
|
-
const
|
|
333
|
-
if (!currentUser) {
|
|
334
|
-
clearHash();
|
|
335
|
-
return { type: "email_change", user: null, token: emailChangeToken };
|
|
336
|
-
}
|
|
337
|
-
const gotrueUser = await currentUser.update({ email_change_token: emailChangeToken });
|
|
436
|
+
const gotrueUser = await client.verify("email_change", emailChangeToken, persistSession);
|
|
338
437
|
const user = toUser(gotrueUser);
|
|
339
438
|
clearHash();
|
|
340
439
|
emitAuthEvent("user_updated", user);
|
|
@@ -358,6 +457,18 @@ var requestPasswordRecovery = async (email) => {
|
|
|
358
457
|
throw new AuthError(error.message, void 0, { cause: error });
|
|
359
458
|
}
|
|
360
459
|
};
|
|
460
|
+
var recoverPassword = async (token, newPassword) => {
|
|
461
|
+
const client = getClient();
|
|
462
|
+
try {
|
|
463
|
+
const gotrueUser = await client.recover(token, persistSession);
|
|
464
|
+
const updatedUser = await gotrueUser.update({ password: newPassword });
|
|
465
|
+
const user = toUser(updatedUser);
|
|
466
|
+
emitAuthEvent("login", user);
|
|
467
|
+
return user;
|
|
468
|
+
} catch (error) {
|
|
469
|
+
throw new AuthError(error.message, void 0, { cause: error });
|
|
470
|
+
}
|
|
471
|
+
};
|
|
361
472
|
var confirmEmail = async (token) => {
|
|
362
473
|
const client = getClient();
|
|
363
474
|
try {
|
|
@@ -382,10 +493,8 @@ var acceptInvite = async (token, password) => {
|
|
|
382
493
|
};
|
|
383
494
|
var verifyEmailChange = async (token) => {
|
|
384
495
|
const client = getClient();
|
|
385
|
-
const currentUser = client.currentUser();
|
|
386
|
-
if (!currentUser) throw new AuthError("No user is currently logged in");
|
|
387
496
|
try {
|
|
388
|
-
const gotrueUser = await
|
|
497
|
+
const gotrueUser = await client.verify("email_change", token, persistSession);
|
|
389
498
|
const user = toUser(gotrueUser);
|
|
390
499
|
emitAuthEvent("user_updated", user);
|
|
391
500
|
return user;
|
|
@@ -421,6 +530,7 @@ var updateUser = async (updates) => {
|
|
|
421
530
|
logout,
|
|
422
531
|
oauthLogin,
|
|
423
532
|
onAuthChange,
|
|
533
|
+
recoverPassword,
|
|
424
534
|
requestPasswordRecovery,
|
|
425
535
|
signup,
|
|
426
536
|
updateUser,
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/types.ts","../src/environment.ts","../src/errors.ts","../src/user.ts","../src/config.ts","../src/auth.ts","../src/account.ts"],"sourcesContent":["export type { User } from './user.js'\nexport { getUser, isAuthenticated } from './user.js'\nexport { getIdentityConfig, getSettings } from './config.js'\nexport type { AuthCallback, AuthEvent, CallbackResult } from './auth.js'\nexport { login, signup, logout, oauthLogin, onAuthChange, handleAuthCallback } from './auth.js'\nexport { AuthError, MissingIdentityError } from './errors.js'\nexport type { AppMetadata, AuthProvider, IdentityConfig, Settings } from './types.js'\nexport { requestPasswordRecovery, confirmEmail, acceptInvite, verifyEmailChange, updateUser } from './account.js'\n","export const AUTH_PROVIDERS = ['google', 'github', 'gitlab', 'bitbucket', 'facebook', 'saml', 'email'] as const\nexport type AuthProvider = (typeof AUTH_PROVIDERS)[number]\n\nexport interface AppMetadata {\n provider: AuthProvider\n roles?: string[]\n [key: string]: unknown\n}\n\nexport interface IdentityConfig {\n url: string\n token?: string // this is an operator token, only available on the server\n}\n\nexport interface Settings {\n autoconfirm: boolean\n disableSignup: boolean\n providers: Record<AuthProvider, boolean>\n}\n","import GoTrue from 'gotrue-js'\n\nimport type { IdentityConfig } from './types.js'\nimport { MissingIdentityError } from './errors.js'\n\nlet goTrueClient: GoTrue | null = null\nlet cachedApiUrl: string | null | undefined\nlet warnedMissingUrl = false\n\nexport const isBrowser = (): boolean => typeof window !== 'undefined' && typeof window.location !== 'undefined'\n\n/**\n * Discovers and caches the GoTrue API URL.\n *\n * Browser: uses `window.location.origin` + `/.netlify/identity`.\n * Server: reads from `globalThis.netlifyIdentityContext`.\n */\nconst discoverApiUrl = (): string | null => {\n if (cachedApiUrl !== undefined) return cachedApiUrl\n\n if (isBrowser()) {\n cachedApiUrl = `${window.location.origin}/.netlify/identity`\n } else {\n const identityContext = getIdentityContext()\n if (identityContext?.url) {\n cachedApiUrl = identityContext.url\n } else if (globalThis.Netlify?.context?.url) {\n cachedApiUrl = new URL('/.netlify/identity', globalThis.Netlify.context.url).href\n }\n }\n\n return cachedApiUrl ?? null\n}\n\n/**\n * Returns (and lazily creates) a singleton gotrue-js client.\n * Returns `null` and logs a warning if no identity URL can be discovered.\n */\nexport const getGoTrueClient = (): GoTrue | null => {\n if (goTrueClient) return goTrueClient\n\n const apiUrl = discoverApiUrl()\n if (!apiUrl) {\n if (!warnedMissingUrl) {\n console.warn(\n '@netlify/identity: Could not determine the Identity endpoint URL. ' +\n 'Make sure your site has Netlify Identity enabled, or run your app with `netlify dev`.',\n )\n warnedMissingUrl = true\n }\n return null\n }\n\n goTrueClient = new GoTrue({ APIUrl: apiUrl, setCookie: isBrowser() })\n return goTrueClient\n}\n\n/**\n * Returns the singleton gotrue-js client, or throws if Identity is not configured.\n */\nexport const getClient = (): GoTrue => {\n const client = getGoTrueClient()\n if (!client) throw new MissingIdentityError()\n return client\n}\n\n/**\n * Reads the server-side identity context set by the Netlify bootstrap.\n * Returns `null` outside the Netlify serverless environment.\n */\nexport const getIdentityContext = (): IdentityConfig | null => {\n // TODO(kh): After Stargate deploys EX-1764, netlifyIdentityContext will have\n // typed `url` and `token` fields. Remove the typeof guards and use direct access.\n // https://linear.app/netlify/issue/EX-1764/identity-stargate-needs-to-set-identity-url-and-providertoken\n const identityContext = globalThis.netlifyIdentityContext\n if (identityContext?.url && typeof identityContext.url === 'string') {\n return {\n url: identityContext.url,\n token: typeof identityContext.token === 'string' ? identityContext.token : undefined,\n }\n }\n\n if (globalThis.Netlify?.context?.url) {\n return { url: new URL('/.netlify/identity', globalThis.Netlify.context.url).href }\n }\n\n return null\n}\n\n/** Reset cached state for tests. */\nexport const resetTestGoTrueClient = (): void => {\n goTrueClient = null\n cachedApiUrl = undefined\n warnedMissingUrl = false\n}\n","export class AuthError extends Error {\n override name = 'AuthError'\n status?: number\n declare cause?: unknown\n\n constructor(message: string, status?: number, options?: { cause?: unknown }) {\n super(message)\n this.status = status\n if (options && 'cause' in options) {\n this.cause = options.cause\n }\n }\n}\n\nexport class MissingIdentityError extends Error {\n override name = 'MissingIdentityError'\n\n constructor(message = 'Identity is not available in this environment') {\n super(message)\n }\n}\n","import type { UserData } from 'gotrue-js'\nimport { AUTH_PROVIDERS, type AuthProvider } from './types.js'\nimport { getGoTrueClient, isBrowser } from './environment.js'\n\nconst toAuthProvider = (value: unknown): AuthProvider | undefined =>\n typeof value === 'string' && (AUTH_PROVIDERS as readonly string[]).includes(value)\n ? (value as AuthProvider)\n : undefined\n\nexport interface User {\n id: string\n email?: string\n emailVerified?: boolean\n createdAt?: string\n updatedAt?: string\n provider?: AuthProvider\n name?: string\n pictureUrl?: string\n metadata?: Record<string, unknown>\n rawGoTrueData?: Record<string, unknown>\n}\n\nexport const toUser = (userData: UserData): User => {\n const userMeta = userData.user_metadata ?? {}\n const appMeta = userData.app_metadata ?? {}\n const name = userMeta.full_name || userMeta.name\n const pictureUrl = userMeta.avatar_url\n\n return {\n id: userData.id,\n email: userData.email,\n emailVerified: !!userData.confirmed_at,\n createdAt: userData.created_at,\n updatedAt: userData.updated_at,\n provider: toAuthProvider(appMeta.provider),\n name: typeof name === 'string' ? name : undefined,\n pictureUrl: typeof pictureUrl === 'string' ? pictureUrl : undefined,\n metadata: userMeta,\n rawGoTrueData: { ...userData },\n }\n}\n\n/**\n * Converts raw JWT claims from the identity header into a User.\n * JWT claims use a different shape than the gotrue-js UserData class.\n */\nconst claimsToUser = (claims: Record<string, unknown>): User => {\n const appMeta = (claims.app_metadata ?? {}) as Record<string, unknown>\n const userMeta = (claims.user_metadata ?? {}) as Record<string, unknown>\n const name = userMeta.full_name || userMeta.name\n\n return {\n id: typeof claims.sub === 'string' ? claims.sub : '',\n email: typeof claims.email === 'string' ? claims.email : undefined,\n provider: toAuthProvider(appMeta.provider),\n name: typeof name === 'string' ? name : undefined,\n metadata: userMeta,\n }\n}\n\n/**\n * Returns the currently authenticated user, or `null` if not logged in.\n * Synchronous. Never throws.\n */\nexport const getUser = (): User | null => {\n if (isBrowser()) {\n const client = getGoTrueClient()\n const currentUser = client?.currentUser() ?? null\n if (!currentUser) return null\n return toUser(currentUser)\n }\n\n const identityContext = globalThis.netlifyIdentityContext\n if (!identityContext) return null\n\n const claims = identityContext.user ?? (identityContext.sub ? identityContext : null)\n if (!claims) return null\n return claimsToUser(claims as Record<string, unknown>)\n}\n\n/**\n * Returns `true` if a user is currently authenticated.\n */\nexport const isAuthenticated = (): boolean => getUser() !== null\n","import type { AuthProvider, IdentityConfig, Settings } from './types.js'\nimport { AuthError } from './errors.js'\nimport { getClient, getIdentityContext, isBrowser } from './environment.js'\n\n/**\n * Returns the identity configuration for the current environment.\n * Browser: always returns `{ url }` derived from `window.location.origin`.\n * Server: returns `{ url, token }` from the identity context, or `null` if unavailable.\n * Never throws.\n */\nexport const getIdentityConfig = (): IdentityConfig | null => {\n if (isBrowser()) {\n return { url: `${window.location.origin}/.netlify/identity` }\n }\n\n return getIdentityContext()\n}\n\n/**\n * Fetches the GoTrue `/settings` endpoint.\n * Throws `MissingIdentityError` if Identity is not configured.\n * Throws `AuthError` if the endpoint is unreachable.\n */\nexport const getSettings = async (): Promise<Settings> => {\n const client = getClient()\n\n try {\n const raw = await client.settings()\n const external: Partial<Record<AuthProvider, boolean>> = raw.external ?? {}\n return {\n autoconfirm: raw.autoconfirm,\n disableSignup: raw.disable_signup,\n providers: {\n google: external.google ?? false,\n github: external.github ?? false,\n gitlab: external.gitlab ?? false,\n bitbucket: external.bitbucket ?? false,\n facebook: external.facebook ?? false,\n email: external.email ?? false,\n saml: external.saml ?? false,\n },\n }\n } catch (err) {\n throw new AuthError(err instanceof Error ? err.message : 'Failed to fetch identity settings', 502, { cause: err })\n }\n}\n","import type { UserData } from 'gotrue-js'\n\nimport type { AppMetadata } from './types.js'\n\nexport type AuthEvent = 'login' | 'logout' | 'token_refresh' | 'user_updated'\nimport type { User } from './user.js'\nimport { toUser } from './user.js'\nimport { getGoTrueClient, getClient, isBrowser } from './environment.js'\nimport { AuthError } from './errors.js'\n\nexport interface JWTClaims {\n sub: string // UUID\n email: string\n exp: number\n iat: number\n aud: string\n app_metadata: AppMetadata\n user_metadata: Record<string, unknown>\n}\n\nexport type AuthCallback = (event: AuthEvent, user: User | null) => void\n\n/** Persist the session to localStorage so it survives page reloads. */\nexport const persistSession = true\n\nconst listeners = new Set<AuthCallback>()\n\nexport const emitAuthEvent = (event: AuthEvent, user: User | null): void => {\n for (const listener of listeners) {\n listener(event, user)\n }\n}\n\nlet storageListenerAttached = false\n\nconst attachStorageListener = (): void => {\n if (storageListenerAttached) return\n storageListenerAttached = true\n\n window.addEventListener('storage', (event: StorageEvent) => {\n if (event.key !== 'gotrue.user') return\n\n if (event.newValue) {\n const client = getGoTrueClient()\n const currentUser = client?.currentUser()\n emitAuthEvent('login', currentUser ? toUser(currentUser) : null)\n } else {\n emitAuthEvent('logout', null)\n }\n })\n}\n\n/**\n * Subscribes to auth state changes (login, logout, token refresh, user updates).\n * Returns an unsubscribe function. No-op on the server.\n */\nexport const onAuthChange = (callback: AuthCallback): (() => void) => {\n if (!isBrowser()) {\n return () => {}\n }\n\n listeners.add(callback)\n attachStorageListener()\n\n return () => {\n listeners.delete(callback)\n }\n}\n\n/** Logs in with email and password. Browser only. */\nexport const login = async (email: string, password: string): Promise<User> => {\n const client = getClient()\n\n try {\n const gotrueUser = await client.login(email, password, persistSession)\n const user = toUser(gotrueUser)\n emitAuthEvent('login', user)\n return user\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\n/** Creates a new account. Emits 'login' if autoconfirm is enabled. Browser only. */\nexport const signup = async (email: string, password: string, data?: Record<string, unknown>): Promise<User> => {\n const client = getClient()\n\n try {\n const response = await client.signup(email, password, data)\n const user = toUser(response as UserData)\n if (response.confirmed_at) {\n emitAuthEvent('login', user)\n }\n return user\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\n/** Logs out the current user and clears the session. Browser only. */\nexport const logout = async (): Promise<void> => {\n const client = getClient()\n\n try {\n const currentUser = client.currentUser()\n if (currentUser) {\n await currentUser.logout()\n }\n emitAuthEvent('logout', null)\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\n/** Redirects to an OAuth provider. Always throws (the page navigates away). Browser only. */\nexport const oauthLogin = (provider: string): never => {\n if (!isBrowser()) {\n throw new Error('oauthLogin() is only available in the browser')\n }\n const client = getClient()\n\n window.location.href = client.loginExternalUrl(provider)\n throw new Error('Redirecting to OAuth provider')\n}\n\nexport interface CallbackResult {\n type: 'oauth' | 'confirmation' | 'recovery' | 'invite' | 'email_change'\n user: User | null\n token?: string\n}\n\n/**\n * Processes the URL hash after an OAuth redirect, email confirmation, password\n * recovery, invite acceptance, or email change. Call on page load. Browser only.\n * Returns `null` if the hash contains no auth parameters.\n */\nexport const handleAuthCallback = async (): Promise<CallbackResult | null> => {\n if (!isBrowser()) return null\n\n const hash = window.location.hash.substring(1)\n if (!hash) return null\n\n const client = getClient()\n\n try {\n const params = new URLSearchParams(hash)\n\n const accessToken = params.get('access_token')\n if (accessToken) {\n const gotrueUser = await client.createUser(\n {\n access_token: accessToken,\n token_type: (params.get('token_type') as 'bearer') ?? 'bearer',\n expires_in: Number(params.get('expires_in')),\n expires_at: Number(params.get('expires_at')),\n refresh_token: params.get('refresh_token') ?? '',\n },\n persistSession,\n )\n const user = toUser(gotrueUser)\n clearHash()\n emitAuthEvent('login', user)\n return { type: 'oauth', user }\n }\n\n const confirmationToken = params.get('confirmation_token')\n if (confirmationToken) {\n const gotrueUser = await client.confirm(confirmationToken, persistSession)\n const user = toUser(gotrueUser)\n clearHash()\n emitAuthEvent('login', user)\n return { type: 'confirmation', user }\n }\n\n const recoveryToken = params.get('recovery_token')\n if (recoveryToken) {\n const gotrueUser = await client.recover(recoveryToken, persistSession)\n const user = toUser(gotrueUser)\n clearHash()\n emitAuthEvent('login', user)\n return { type: 'recovery', user }\n }\n\n const inviteToken = params.get('invite_token')\n if (inviteToken) {\n clearHash()\n return { type: 'invite', user: null, token: inviteToken }\n }\n\n const emailChangeToken = params.get('email_change_token')\n if (emailChangeToken) {\n const currentUser = client.currentUser()\n if (!currentUser) {\n clearHash()\n return { type: 'email_change', user: null, token: emailChangeToken }\n }\n const gotrueUser = await currentUser.update({ email_change_token: emailChangeToken })\n const user = toUser(gotrueUser)\n clearHash()\n emitAuthEvent('user_updated', user)\n return { type: 'email_change', user }\n }\n\n return null\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\nconst clearHash = (): void => {\n history.replaceState(null, '', window.location.pathname + window.location.search)\n}\n","import type { User } from './user.js'\nimport { toUser } from './user.js'\nimport { getClient } from './environment.js'\nimport { emitAuthEvent, persistSession } from './auth.js'\nimport { AuthError } from './errors.js'\n\n/** Sends a password recovery email to the given address. */\nexport const requestPasswordRecovery = async (email: string): Promise<void> => {\n const client = getClient()\n\n try {\n await client.requestPasswordRecovery(email)\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\n/** Confirms an email address using the token from a confirmation email. Logs the user in on success. */\nexport const confirmEmail = async (token: string): Promise<User> => {\n const client = getClient()\n\n try {\n const gotrueUser = await client.confirm(token, persistSession)\n const user = toUser(gotrueUser)\n emitAuthEvent('login', user)\n return user\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\n/** Accepts an invite token and sets a password for the new account. Logs the user in on success. */\nexport const acceptInvite = async (token: string, password: string): Promise<User> => {\n const client = getClient()\n\n try {\n const gotrueUser = await client.acceptInvite(token, password, persistSession)\n const user = toUser(gotrueUser)\n emitAuthEvent('login', user)\n return user\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\n/** Verifies an email change using the token from a verification email. Requires an active session. */\nexport const verifyEmailChange = async (token: string): Promise<User> => {\n const client = getClient()\n\n const currentUser = client.currentUser()\n if (!currentUser) throw new AuthError('No user is currently logged in')\n\n try {\n const gotrueUser = await currentUser.update({ email_change_token: token })\n const user = toUser(gotrueUser)\n emitAuthEvent('user_updated', user)\n return user\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\n/** Updates the current user's metadata or credentials. Requires an active session. */\nexport const updateUser = async (updates: Record<string, unknown>): Promise<User> => {\n const client = getClient()\n\n const currentUser = client.currentUser()\n if (!currentUser) throw new AuthError('No user is currently logged in')\n\n try {\n const updatedUser = await currentUser.update(updates)\n const user = toUser(updatedUser)\n emitAuthEvent('user_updated', user)\n return user\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,iBAAiB,CAAC,UAAU,UAAU,UAAU,aAAa,YAAY,QAAQ,OAAO;;;ACArG,uBAAmB;;;ACAZ,IAAM,YAAN,cAAwB,MAAM;AAAA,EAKnC,YAAY,SAAi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M,CAAC;AAAA,EAC3E;AACF;AAGO,IAAM,aAAa,OAAO,YAAoD;AACnF,QAAM,SAAS,UAAU;AAEzB,QAAM,cAAc,OAAO,YAAY;AACvC,MAAI,CAAC,YAAa,OAAM,IAAI,UAAU,gCAAgC;AAEtE,MAAI;AACF,UAAM,cAAc,MAAM,YAAY,OAAO,OAAO;AACpD,UAAM,OAAO,OAAO,WAAW;AAC/B,kBAAc,gBAAgB,IAAI;AAClC,WAAO;AAAA,EACT,SAAS,OAAO;AACd,UAAM,IAAI,UAAW,MAAgB,SAAS,QAAW,EAAE,OAAO,MAAM,CAAC;AAAA,EAC3E;AACF;","names":["GoTrue"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/types.ts","../src/environment.ts","../src/errors.ts","../src/user.ts","../src/config.ts","../src/auth.ts","../src/account.ts"],"sourcesContent":["export type { User } from './user.js'\nexport { getUser, isAuthenticated } from './user.js'\nexport { getIdentityConfig, getSettings } from './config.js'\nexport type { AuthCallback, AuthEvent, CallbackResult } from './auth.js'\nexport { login, signup, logout, oauthLogin, onAuthChange, handleAuthCallback } from './auth.js'\nexport { AuthError, MissingIdentityError } from './errors.js'\nexport type { AppMetadata, AuthProvider, IdentityConfig, Settings } from './types.js'\nexport {\n requestPasswordRecovery,\n recoverPassword,\n confirmEmail,\n acceptInvite,\n verifyEmailChange,\n updateUser,\n} from './account.js'\n","export const AUTH_PROVIDERS = ['google', 'github', 'gitlab', 'bitbucket', 'facebook', 'saml', 'email'] as const\nexport type AuthProvider = (typeof AUTH_PROVIDERS)[number]\n\nexport interface AppMetadata {\n provider: AuthProvider\n roles?: string[]\n [key: string]: unknown\n}\n\nexport interface IdentityConfig {\n url: string\n token?: string // this is an operator token, only available on the server\n}\n\nexport interface Settings {\n autoconfirm: boolean\n disableSignup: boolean\n providers: Record<AuthProvider, boolean>\n}\n\nexport interface NetlifyCookies {\n get(name: string): string | undefined\n set(options: {\n name: string\n value: string\n httpOnly: boolean\n secure: boolean\n path: string\n sameSite: string\n }): void\n delete(name: string): void\n}\n","import GoTrue from 'gotrue-js'\n\nimport type { IdentityConfig } from './types.js'\nimport { MissingIdentityError } from './errors.js'\n\nexport const IDENTITY_PATH = '/.netlify/identity'\n\nlet goTrueClient: GoTrue | null = null\nlet cachedApiUrl: string | null | undefined\nlet warnedMissingUrl = false\n\nexport const isBrowser = (): boolean => typeof window !== 'undefined' && typeof window.location !== 'undefined'\n\n/**\n * Discovers and caches the GoTrue API URL.\n *\n * Browser: uses `window.location.origin` + IDENTITY_PATH.\n * Server: reads from `globalThis.netlifyIdentityContext`.\n */\nconst discoverApiUrl = (): string | null => {\n if (cachedApiUrl !== undefined) return cachedApiUrl\n\n if (isBrowser()) {\n cachedApiUrl = `${window.location.origin}${IDENTITY_PATH}`\n } else {\n const identityContext = getIdentityContext()\n if (identityContext?.url) {\n cachedApiUrl = identityContext.url\n } else if (globalThis.Netlify?.context?.url) {\n cachedApiUrl = new URL(IDENTITY_PATH, globalThis.Netlify.context.url).href\n }\n }\n\n return cachedApiUrl ?? null\n}\n\n/**\n * Returns (and lazily creates) a singleton gotrue-js client.\n * Returns `null` and logs a warning if no identity URL can be discovered.\n */\nexport const getGoTrueClient = (): GoTrue | null => {\n if (goTrueClient) return goTrueClient\n\n const apiUrl = discoverApiUrl()\n if (!apiUrl) {\n if (!warnedMissingUrl) {\n console.warn(\n '@netlify/identity: Could not determine the Identity endpoint URL. ' +\n 'Make sure your site has Netlify Identity enabled, or run your app with `netlify dev`.',\n )\n warnedMissingUrl = true\n }\n return null\n }\n\n goTrueClient = new GoTrue({ APIUrl: apiUrl, setCookie: isBrowser() })\n return goTrueClient\n}\n\n/**\n * Returns the singleton gotrue-js client, or throws if Identity is not configured.\n */\nexport const getClient = (): GoTrue => {\n const client = getGoTrueClient()\n if (!client) throw new MissingIdentityError()\n return client\n}\n\n/**\n * Reads the server-side identity context set by the Netlify bootstrap.\n * Returns `null` outside the Netlify serverless environment.\n */\nexport const getIdentityContext = (): IdentityConfig | null => {\n const identityContext = globalThis.netlifyIdentityContext\n if (identityContext?.url) {\n return {\n url: identityContext.url,\n token: identityContext.token,\n }\n }\n\n if (globalThis.Netlify?.context?.url) {\n return { url: new URL(IDENTITY_PATH, globalThis.Netlify.context.url).href }\n }\n\n return null\n}\n\n/** Reset cached state for tests. */\nexport const resetTestGoTrueClient = (): void => {\n goTrueClient = null\n cachedApiUrl = undefined\n warnedMissingUrl = false\n}\n","export class AuthError extends Error {\n override name = 'AuthError'\n status?: number\n declare cause?: unknown\n\n constructor(message: string, status?: number, options?: { cause?: unknown }) {\n super(message)\n this.status = status\n if (options && 'cause' in options) {\n this.cause = options.cause\n }\n }\n}\n\nexport class MissingIdentityError extends Error {\n override name = 'MissingIdentityError'\n\n constructor(message = 'Identity is not available in this environment') {\n super(message)\n }\n}\n","import type { UserData } from 'gotrue-js'\nimport { AUTH_PROVIDERS, type AuthProvider } from './types.js'\nimport { getGoTrueClient, isBrowser } from './environment.js'\n\nexport interface IdentityUser {\n sub?: string\n email?: string\n exp?: number\n app_metadata?: Record<string, unknown>\n user_metadata?: Record<string, unknown>\n [key: string]: unknown\n}\n\nconst toAuthProvider = (value: unknown): AuthProvider | undefined =>\n typeof value === 'string' && (AUTH_PROVIDERS as readonly string[]).includes(value)\n ? (value as AuthProvider)\n : undefined\n\nexport interface User {\n id: string\n email?: string\n emailVerified?: boolean\n createdAt?: string\n updatedAt?: string\n provider?: AuthProvider\n name?: string\n pictureUrl?: string\n metadata?: Record<string, unknown>\n rawGoTrueData?: Record<string, unknown>\n}\n\nexport const toUser = (userData: UserData): User => {\n const userMeta = userData.user_metadata ?? {}\n const appMeta = userData.app_metadata ?? {}\n const name = userMeta.full_name || userMeta.name\n const pictureUrl = userMeta.avatar_url\n\n return {\n id: userData.id,\n email: userData.email,\n emailVerified: !!userData.confirmed_at,\n createdAt: userData.created_at,\n updatedAt: userData.updated_at,\n provider: toAuthProvider(appMeta.provider),\n name: typeof name === 'string' ? name : undefined,\n pictureUrl: typeof pictureUrl === 'string' ? pictureUrl : undefined,\n metadata: userMeta,\n rawGoTrueData: { ...userData },\n }\n}\n\n/**\n * Converts server-side JWT claims into User\n */\nconst claimsToUser = (claims: IdentityUser): User => {\n const appMeta = claims.app_metadata ?? {}\n const userMeta = claims.user_metadata ?? {}\n const name = userMeta.full_name || userMeta.name\n\n return {\n id: claims.sub ?? '',\n email: claims.email,\n provider: toAuthProvider(appMeta.provider),\n name: typeof name === 'string' ? name : undefined,\n metadata: userMeta,\n }\n}\n\n/**\n * Returns the currently authenticated user, or `null` if not logged in.\n * Synchronous. Never throws.\n */\nexport const getUser = (): User | null => {\n if (isBrowser()) {\n const client = getGoTrueClient()\n const currentUser = client?.currentUser() ?? null\n if (!currentUser) return null\n return toUser(currentUser)\n }\n\n const identityContext = globalThis.netlifyIdentityContext\n if (!identityContext?.user) return null\n\n return claimsToUser(identityContext.user)\n}\n\n/**\n * Returns `true` if a user is currently authenticated.\n */\nexport const isAuthenticated = (): boolean => getUser() !== null\n","import type { AuthProvider, IdentityConfig, Settings } from './types.js'\nimport { getClient, getIdentityContext, IDENTITY_PATH, isBrowser } from './environment.js'\nimport { AuthError } from './errors.js'\n\n/**\n * Returns the identity configuration for the current environment.\n * Browser: always returns `{ url }` derived from `window.location.origin`.\n * Server: returns `{ url, token }` from the identity context, or `null` if unavailable.\n * Never throws.\n */\nexport const getIdentityConfig = (): IdentityConfig | null => {\n if (isBrowser()) {\n return { url: `${window.location.origin}${IDENTITY_PATH}` }\n }\n\n return getIdentityContext()\n}\n\n/**\n * Fetches the GoTrue `/settings` endpoint.\n * Throws `MissingIdentityError` if Identity is not configured.\n * Throws `AuthError` if the endpoint is unreachable.\n */\nexport const getSettings = async (): Promise<Settings> => {\n const client = getClient()\n\n try {\n const raw = await client.settings()\n const external: Partial<Record<AuthProvider, boolean>> = raw.external ?? {}\n return {\n autoconfirm: raw.autoconfirm,\n disableSignup: raw.disable_signup,\n providers: {\n google: external.google ?? false,\n github: external.github ?? false,\n gitlab: external.gitlab ?? false,\n bitbucket: external.bitbucket ?? false,\n facebook: external.facebook ?? false,\n email: external.email ?? false,\n saml: external.saml ?? false,\n },\n }\n } catch (err) {\n throw new AuthError(err instanceof Error ? err.message : 'Failed to fetch identity settings', 502, { cause: err })\n }\n}\n","import type { UserData } from 'gotrue-js'\n\nimport type { AppMetadata, NetlifyCookies } from './types.js'\n\nexport type AuthEvent = 'login' | 'logout' | 'token_refresh' | 'user_updated'\nimport type { User } from './user.js'\nimport { toUser } from './user.js'\nimport { getGoTrueClient, getClient, getIdentityContext, isBrowser } from './environment.js'\nimport { AuthError } from './errors.js'\n\nconst getCookies = (): NetlifyCookies => {\n const cookies = globalThis.Netlify?.context?.cookies\n if (!cookies) {\n throw new AuthError('Server-side auth requires Netlify Functions runtime')\n }\n return cookies\n}\n\nconst getServerIdentityUrl = (): string => {\n const ctx = getIdentityContext()\n if (!ctx?.url) {\n throw new AuthError('Could not determine the Identity endpoint URL on the server')\n }\n return ctx.url\n}\n\nexport interface JWTClaims {\n sub: string // UUID\n email: string\n exp: number\n iat: number\n aud: string\n app_metadata: AppMetadata\n user_metadata: Record<string, unknown>\n}\n\nexport type AuthCallback = (event: AuthEvent, user: User | null) => void\n\n/** Persist the session to localStorage so it survives page reloads. */\nexport const persistSession = true\n\nconst listeners = new Set<AuthCallback>()\n\nexport const emitAuthEvent = (event: AuthEvent, user: User | null): void => {\n for (const listener of listeners) {\n listener(event, user)\n }\n}\n\nlet storageListenerAttached = false\n\nconst attachStorageListener = (): void => {\n if (storageListenerAttached) return\n storageListenerAttached = true\n\n window.addEventListener('storage', (event: StorageEvent) => {\n if (event.key !== 'gotrue.user') return\n\n if (event.newValue) {\n const client = getGoTrueClient()\n const currentUser = client?.currentUser()\n emitAuthEvent('login', currentUser ? toUser(currentUser) : null)\n } else {\n emitAuthEvent('logout', null)\n }\n })\n}\n\n/**\n * Subscribes to auth state changes (login, logout, token refresh, user updates).\n * Returns an unsubscribe function. No-op on the server.\n */\nexport const onAuthChange = (callback: AuthCallback): (() => void) => {\n if (!isBrowser()) {\n return () => {}\n }\n\n listeners.add(callback)\n attachStorageListener()\n\n return () => {\n listeners.delete(callback)\n }\n}\n\n/** Logs in with email and password. Works in both browser and server contexts. */\nexport const login = async (email: string, password: string): Promise<User> => {\n if (!isBrowser()) {\n const identityUrl = getServerIdentityUrl()\n const cookies = getCookies()\n\n const body = new URLSearchParams({\n grant_type: 'password',\n username: email,\n password,\n })\n\n let res: Response\n try {\n res = await fetch(`${identityUrl}/token`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/x-www-form-urlencoded' },\n body: body.toString(),\n })\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n\n if (!res.ok) {\n const errorBody = await res.json().catch(() => ({}))\n throw new AuthError(\n (errorBody as Record<string, string>).msg ||\n (errorBody as Record<string, string>).error_description ||\n `Login failed (${res.status})`,\n res.status,\n )\n }\n\n const data = (await res.json()) as Record<string, unknown>\n const accessToken = data.access_token as string\n const userData = data as unknown as UserData\n const user = toUser(userData)\n\n cookies.set({\n name: 'nf_jwt',\n value: accessToken,\n httpOnly: true,\n secure: true,\n path: '/',\n sameSite: 'Lax',\n })\n\n return user\n }\n\n const client = getClient()\n\n try {\n const gotrueUser = await client.login(email, password, persistSession)\n const user = toUser(gotrueUser)\n emitAuthEvent('login', user)\n return user\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\n/** Creates a new account. Emits 'login' if autoconfirm is enabled. Works in both browser and server contexts. */\nexport const signup = async (email: string, password: string, data?: Record<string, unknown>): Promise<User> => {\n if (!isBrowser()) {\n const identityUrl = getServerIdentityUrl()\n const cookies = getCookies()\n\n let res: Response\n try {\n res = await fetch(`${identityUrl}/signup`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ email, password, data }),\n })\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n\n if (!res.ok) {\n const errorBody = await res.json().catch(() => ({}))\n throw new AuthError((errorBody as Record<string, string>).msg || `Signup failed (${res.status})`, res.status)\n }\n\n const responseData = (await res.json()) as UserData\n const user = toUser(responseData)\n\n if (responseData.confirmed_at) {\n const accessToken = (responseData as unknown as Record<string, unknown>).access_token as string | undefined\n if (accessToken) {\n cookies.set({\n name: 'nf_jwt',\n value: accessToken,\n httpOnly: true,\n secure: true,\n path: '/',\n sameSite: 'Lax',\n })\n }\n }\n\n return user\n }\n\n const client = getClient()\n\n try {\n const response = await client.signup(email, password, data)\n const user = toUser(response as UserData)\n if (response.confirmed_at) {\n emitAuthEvent('login', user)\n }\n return user\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\n/** Logs out the current user and clears the session. Works in both browser and server contexts. */\nexport const logout = async (): Promise<void> => {\n if (!isBrowser()) {\n const identityUrl = getServerIdentityUrl()\n const cookies = getCookies()\n\n const jwt = cookies.get('nf_jwt')\n if (jwt) {\n try {\n await fetch(`${identityUrl}/logout`, {\n method: 'POST',\n headers: { Authorization: `Bearer ${jwt}` },\n })\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n }\n\n cookies.delete('nf_jwt')\n return\n }\n\n const client = getClient()\n\n try {\n const currentUser = client.currentUser()\n if (currentUser) {\n await currentUser.logout()\n }\n emitAuthEvent('logout', null)\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\n/** Redirects to an OAuth provider. Always throws (the page navigates away). Browser only. */\nexport const oauthLogin = (provider: string): never => {\n if (!isBrowser()) {\n throw new Error('oauthLogin() is only available in the browser')\n }\n const client = getClient()\n\n window.location.href = client.loginExternalUrl(provider)\n throw new Error('Redirecting to OAuth provider')\n}\n\nexport interface CallbackResult {\n type: 'oauth' | 'confirmation' | 'recovery' | 'invite' | 'email_change'\n user: User | null\n token?: string\n}\n\n/**\n * Processes the URL hash after an OAuth redirect, email confirmation, password\n * recovery, invite acceptance, or email change. Call on page load. Browser only.\n * Returns `null` if the hash contains no auth parameters.\n */\nexport const handleAuthCallback = async (): Promise<CallbackResult | null> => {\n if (!isBrowser()) return null\n\n const hash = window.location.hash.substring(1)\n if (!hash) return null\n\n const client = getClient()\n\n try {\n const params = new URLSearchParams(hash)\n\n const accessToken = params.get('access_token')\n if (accessToken) {\n const gotrueUser = await client.createUser(\n {\n access_token: accessToken,\n token_type: (params.get('token_type') as 'bearer') ?? 'bearer',\n expires_in: Number(params.get('expires_in')),\n expires_at: Number(params.get('expires_at')),\n refresh_token: params.get('refresh_token') ?? '',\n },\n persistSession,\n )\n const user = toUser(gotrueUser)\n clearHash()\n emitAuthEvent('login', user)\n return { type: 'oauth', user }\n }\n\n const confirmationToken = params.get('confirmation_token')\n if (confirmationToken) {\n const gotrueUser = await client.confirm(confirmationToken, persistSession)\n const user = toUser(gotrueUser)\n clearHash()\n emitAuthEvent('login', user)\n return { type: 'confirmation', user }\n }\n\n const recoveryToken = params.get('recovery_token')\n if (recoveryToken) {\n const gotrueUser = await client.recover(recoveryToken, persistSession)\n const user = toUser(gotrueUser)\n clearHash()\n emitAuthEvent('login', user)\n return { type: 'recovery', user }\n }\n\n const inviteToken = params.get('invite_token')\n if (inviteToken) {\n clearHash()\n return { type: 'invite', user: null, token: inviteToken }\n }\n\n const emailChangeToken = params.get('email_change_token')\n if (emailChangeToken) {\n const gotrueUser = await client.verify('email_change', emailChangeToken, persistSession)\n const user = toUser(gotrueUser)\n clearHash()\n emitAuthEvent('user_updated', user)\n return { type: 'email_change', user }\n }\n\n return null\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\nconst clearHash = (): void => {\n history.replaceState(null, '', window.location.pathname + window.location.search)\n}\n","import type { User } from './user.js'\nimport { toUser } from './user.js'\nimport { getClient } from './environment.js'\nimport { emitAuthEvent, persistSession } from './auth.js'\nimport { AuthError } from './errors.js'\n\n/** Sends a password recovery email to the given address. */\nexport const requestPasswordRecovery = async (email: string): Promise<void> => {\n const client = getClient()\n\n try {\n await client.requestPasswordRecovery(email)\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\n/** Redeems a recovery token and sets a new password. Logs the user in on success. */\nexport const recoverPassword = async (token: string, newPassword: string): Promise<User> => {\n const client = getClient()\n\n try {\n const gotrueUser = await client.recover(token, persistSession)\n const updatedUser = await gotrueUser.update({ password: newPassword })\n const user = toUser(updatedUser)\n emitAuthEvent('login', user)\n return user\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\n\n/** Confirms an email address using the token from a confirmation email. Logs the user in on success. */\nexport const confirmEmail = async (token: string): Promise<User> => {\n const client = getClient()\n\n try {\n const gotrueUser = await client.confirm(token, persistSession)\n const user = toUser(gotrueUser)\n emitAuthEvent('login', user)\n return user\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\n/** Accepts an invite token and sets a password for the new account. Logs the user in on success. */\nexport const acceptInvite = async (token: string, password: string): Promise<User> => {\n const client = getClient()\n\n try {\n const gotrueUser = await client.acceptInvite(token, password, persistSession)\n const user = toUser(gotrueUser)\n emitAuthEvent('login', user)\n return user\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\n/** Verifies an email change using the token from a verification email. */\nexport const verifyEmailChange = async (token: string): Promise<User> => {\n const client = getClient()\n\n try {\n const gotrueUser = await client.verify('email_change', token, persistSession)\n const user = toUser(gotrueUser)\n emitAuthEvent('user_updated', user)\n return user\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\n/** Updates the current user's metadata or credentials. Requires an active session. */\nexport const updateUser = async (updates: Record<string, unknown>): Promise<User> => {\n const client = getClient()\n\n const currentUser = client.currentUser()\n if (!currentUser) throw new AuthError('No user is currently logged in')\n\n try {\n const updatedUser = await currentUser.update(updates)\n const user = toUser(updatedUser)\n emitAuthEvent('user_updated', user)\n return user\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n"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AAC3B,WAAO;AAAA,EACT,SAAS,OAAO;AACd,UAAM,IAAI,UAAW,MAAgB,SAAS,QAAW,EAAE,OAAO,MAAM,CAAC;AAAA,EAC3E;AACF;AAGO,IAAM,oBAAoB,OAAO,UAAiC;AACvE,QAAM,SAAS,UAAU;AAEzB,MAAI;AACF,UAAM,aAAa,MAAM,OAAO,OAAO,gBAAgB,OAAO,cAAc;AAC5E,UAAM,OAAO,OAAO,UAAU;AAC9B,kBAAc,gBAAgB,IAAI;AAClC,WAAO;AAAA,EACT,SAAS,OAAO;AACd,UAAM,IAAI,UAAW,MAAgB,SAAS,QAAW,EAAE,OAAO,MAAM,CAAC;AAAA,EAC3E;AACF;AAGO,IAAM,aAAa,OAAO,YAAoD;AACnF,QAAM,SAAS,UAAU;AAEzB,QAAM,cAAc,OAAO,YAAY;AACvC,MAAI,CAAC,YAAa,OAAM,IAAI,UAAU,gCAAgC;AAEtE,MAAI;AACF,UAAM,cAAc,MAAM,YAAY,OAAO,OAAO;AACpD,UAAM,OAAO,OAAO,WAAW;AAC/B,kBAAc,gBAAgB,IAAI;AAClC,WAAO;AAAA,EACT,SAAS,OAAO;AACd,UAAM,IAAI,UAAW,MAAgB,SAAS,QAAW,EAAE,OAAO,MAAM,CAAC;AAAA,EAC3E;AACF;","names":["GoTrue"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -59,11 +59,11 @@ type AuthCallback = (event: AuthEvent, user: User | null) => void;
|
|
|
59
59
|
* Returns an unsubscribe function. No-op on the server.
|
|
60
60
|
*/
|
|
61
61
|
declare const onAuthChange: (callback: AuthCallback) => (() => void);
|
|
62
|
-
/** Logs in with email and password.
|
|
62
|
+
/** Logs in with email and password. Works in both browser and server contexts. */
|
|
63
63
|
declare const login: (email: string, password: string) => Promise<User>;
|
|
64
|
-
/** Creates a new account. Emits 'login' if autoconfirm is enabled.
|
|
64
|
+
/** Creates a new account. Emits 'login' if autoconfirm is enabled. Works in both browser and server contexts. */
|
|
65
65
|
declare const signup: (email: string, password: string, data?: Record<string, unknown>) => Promise<User>;
|
|
66
|
-
/** Logs out the current user and clears the session.
|
|
66
|
+
/** Logs out the current user and clears the session. Works in both browser and server contexts. */
|
|
67
67
|
declare const logout: () => Promise<void>;
|
|
68
68
|
/** Redirects to an OAuth provider. Always throws (the page navigates away). Browser only. */
|
|
69
69
|
declare const oauthLogin: (provider: string) => never;
|
|
@@ -94,13 +94,15 @@ declare class MissingIdentityError extends Error {
|
|
|
94
94
|
|
|
95
95
|
/** Sends a password recovery email to the given address. */
|
|
96
96
|
declare const requestPasswordRecovery: (email: string) => Promise<void>;
|
|
97
|
+
/** Redeems a recovery token and sets a new password. Logs the user in on success. */
|
|
98
|
+
declare const recoverPassword: (token: string, newPassword: string) => Promise<User>;
|
|
97
99
|
/** Confirms an email address using the token from a confirmation email. Logs the user in on success. */
|
|
98
100
|
declare const confirmEmail: (token: string) => Promise<User>;
|
|
99
101
|
/** Accepts an invite token and sets a password for the new account. Logs the user in on success. */
|
|
100
102
|
declare const acceptInvite: (token: string, password: string) => Promise<User>;
|
|
101
|
-
/** Verifies an email change using the token from a verification email.
|
|
103
|
+
/** Verifies an email change using the token from a verification email. */
|
|
102
104
|
declare const verifyEmailChange: (token: string) => Promise<User>;
|
|
103
105
|
/** Updates the current user's metadata or credentials. Requires an active session. */
|
|
104
106
|
declare const updateUser: (updates: Record<string, unknown>) => Promise<User>;
|
|
105
107
|
|
|
106
|
-
export { type AppMetadata, type AuthCallback, AuthError, type AuthEvent, type AuthProvider, type CallbackResult, type IdentityConfig, MissingIdentityError, type Settings, type User, acceptInvite, confirmEmail, getIdentityConfig, getSettings, getUser, handleAuthCallback, isAuthenticated, login, logout, oauthLogin, onAuthChange, requestPasswordRecovery, signup, updateUser, verifyEmailChange };
|
|
108
|
+
export { type AppMetadata, type AuthCallback, AuthError, type AuthEvent, type AuthProvider, type CallbackResult, type IdentityConfig, MissingIdentityError, type Settings, type User, acceptInvite, confirmEmail, getIdentityConfig, getSettings, getUser, handleAuthCallback, isAuthenticated, login, logout, oauthLogin, onAuthChange, recoverPassword, requestPasswordRecovery, signup, updateUser, verifyEmailChange };
|
package/dist/index.d.ts
CHANGED
|
@@ -59,11 +59,11 @@ type AuthCallback = (event: AuthEvent, user: User | null) => void;
|
|
|
59
59
|
* Returns an unsubscribe function. No-op on the server.
|
|
60
60
|
*/
|
|
61
61
|
declare const onAuthChange: (callback: AuthCallback) => (() => void);
|
|
62
|
-
/** Logs in with email and password.
|
|
62
|
+
/** Logs in with email and password. Works in both browser and server contexts. */
|
|
63
63
|
declare const login: (email: string, password: string) => Promise<User>;
|
|
64
|
-
/** Creates a new account. Emits 'login' if autoconfirm is enabled.
|
|
64
|
+
/** Creates a new account. Emits 'login' if autoconfirm is enabled. Works in both browser and server contexts. */
|
|
65
65
|
declare const signup: (email: string, password: string, data?: Record<string, unknown>) => Promise<User>;
|
|
66
|
-
/** Logs out the current user and clears the session.
|
|
66
|
+
/** Logs out the current user and clears the session. Works in both browser and server contexts. */
|
|
67
67
|
declare const logout: () => Promise<void>;
|
|
68
68
|
/** Redirects to an OAuth provider. Always throws (the page navigates away). Browser only. */
|
|
69
69
|
declare const oauthLogin: (provider: string) => never;
|
|
@@ -94,13 +94,15 @@ declare class MissingIdentityError extends Error {
|
|
|
94
94
|
|
|
95
95
|
/** Sends a password recovery email to the given address. */
|
|
96
96
|
declare const requestPasswordRecovery: (email: string) => Promise<void>;
|
|
97
|
+
/** Redeems a recovery token and sets a new password. Logs the user in on success. */
|
|
98
|
+
declare const recoverPassword: (token: string, newPassword: string) => Promise<User>;
|
|
97
99
|
/** Confirms an email address using the token from a confirmation email. Logs the user in on success. */
|
|
98
100
|
declare const confirmEmail: (token: string) => Promise<User>;
|
|
99
101
|
/** Accepts an invite token and sets a password for the new account. Logs the user in on success. */
|
|
100
102
|
declare const acceptInvite: (token: string, password: string) => Promise<User>;
|
|
101
|
-
/** Verifies an email change using the token from a verification email.
|
|
103
|
+
/** Verifies an email change using the token from a verification email. */
|
|
102
104
|
declare const verifyEmailChange: (token: string) => Promise<User>;
|
|
103
105
|
/** Updates the current user's metadata or credentials. Requires an active session. */
|
|
104
106
|
declare const updateUser: (updates: Record<string, unknown>) => Promise<User>;
|
|
105
107
|
|
|
106
|
-
export { type AppMetadata, type AuthCallback, AuthError, type AuthEvent, type AuthProvider, type CallbackResult, type IdentityConfig, MissingIdentityError, type Settings, type User, acceptInvite, confirmEmail, getIdentityConfig, getSettings, getUser, handleAuthCallback, isAuthenticated, login, logout, oauthLogin, onAuthChange, requestPasswordRecovery, signup, updateUser, verifyEmailChange };
|
|
108
|
+
export { type AppMetadata, type AuthCallback, AuthError, type AuthEvent, type AuthProvider, type CallbackResult, type IdentityConfig, MissingIdentityError, type Settings, type User, acceptInvite, confirmEmail, getIdentityConfig, getSettings, getUser, handleAuthCallback, isAuthenticated, login, logout, oauthLogin, onAuthChange, recoverPassword, requestPasswordRecovery, signup, updateUser, verifyEmailChange };
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ var MissingIdentityError = class extends Error {
|
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
// src/environment.ts
|
|
26
|
+
var IDENTITY_PATH = "/.netlify/identity";
|
|
26
27
|
var goTrueClient = null;
|
|
27
28
|
var cachedApiUrl;
|
|
28
29
|
var warnedMissingUrl = false;
|
|
@@ -30,13 +31,13 @@ var isBrowser = () => typeof window !== "undefined" && typeof window.location !=
|
|
|
30
31
|
var discoverApiUrl = () => {
|
|
31
32
|
if (cachedApiUrl !== void 0) return cachedApiUrl;
|
|
32
33
|
if (isBrowser()) {
|
|
33
|
-
cachedApiUrl = `${window.location.origin}
|
|
34
|
+
cachedApiUrl = `${window.location.origin}${IDENTITY_PATH}`;
|
|
34
35
|
} else {
|
|
35
36
|
const identityContext = getIdentityContext();
|
|
36
37
|
if (identityContext?.url) {
|
|
37
38
|
cachedApiUrl = identityContext.url;
|
|
38
39
|
} else if (globalThis.Netlify?.context?.url) {
|
|
39
|
-
cachedApiUrl = new URL(
|
|
40
|
+
cachedApiUrl = new URL(IDENTITY_PATH, globalThis.Netlify.context.url).href;
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
return cachedApiUrl ?? null;
|
|
@@ -63,14 +64,14 @@ var getClient = () => {
|
|
|
63
64
|
};
|
|
64
65
|
var getIdentityContext = () => {
|
|
65
66
|
const identityContext = globalThis.netlifyIdentityContext;
|
|
66
|
-
if (identityContext?.url
|
|
67
|
+
if (identityContext?.url) {
|
|
67
68
|
return {
|
|
68
69
|
url: identityContext.url,
|
|
69
|
-
token:
|
|
70
|
+
token: identityContext.token
|
|
70
71
|
};
|
|
71
72
|
}
|
|
72
73
|
if (globalThis.Netlify?.context?.url) {
|
|
73
|
-
return { url: new URL(
|
|
74
|
+
return { url: new URL(IDENTITY_PATH, globalThis.Netlify.context.url).href };
|
|
74
75
|
}
|
|
75
76
|
return null;
|
|
76
77
|
};
|
|
@@ -100,8 +101,8 @@ var claimsToUser = (claims) => {
|
|
|
100
101
|
const userMeta = claims.user_metadata ?? {};
|
|
101
102
|
const name = userMeta.full_name || userMeta.name;
|
|
102
103
|
return {
|
|
103
|
-
id:
|
|
104
|
-
email:
|
|
104
|
+
id: claims.sub ?? "",
|
|
105
|
+
email: claims.email,
|
|
105
106
|
provider: toAuthProvider(appMeta.provider),
|
|
106
107
|
name: typeof name === "string" ? name : void 0,
|
|
107
108
|
metadata: userMeta
|
|
@@ -115,17 +116,15 @@ var getUser = () => {
|
|
|
115
116
|
return toUser(currentUser);
|
|
116
117
|
}
|
|
117
118
|
const identityContext = globalThis.netlifyIdentityContext;
|
|
118
|
-
if (!identityContext) return null;
|
|
119
|
-
|
|
120
|
-
if (!claims) return null;
|
|
121
|
-
return claimsToUser(claims);
|
|
119
|
+
if (!identityContext?.user) return null;
|
|
120
|
+
return claimsToUser(identityContext.user);
|
|
122
121
|
};
|
|
123
122
|
var isAuthenticated = () => getUser() !== null;
|
|
124
123
|
|
|
125
124
|
// src/config.ts
|
|
126
125
|
var getIdentityConfig = () => {
|
|
127
126
|
if (isBrowser()) {
|
|
128
|
-
return { url: `${window.location.origin}
|
|
127
|
+
return { url: `${window.location.origin}${IDENTITY_PATH}` };
|
|
129
128
|
}
|
|
130
129
|
return getIdentityContext();
|
|
131
130
|
};
|
|
@@ -153,6 +152,20 @@ var getSettings = async () => {
|
|
|
153
152
|
};
|
|
154
153
|
|
|
155
154
|
// src/auth.ts
|
|
155
|
+
var getCookies = () => {
|
|
156
|
+
const cookies = globalThis.Netlify?.context?.cookies;
|
|
157
|
+
if (!cookies) {
|
|
158
|
+
throw new AuthError("Server-side auth requires Netlify Functions runtime");
|
|
159
|
+
}
|
|
160
|
+
return cookies;
|
|
161
|
+
};
|
|
162
|
+
var getServerIdentityUrl = () => {
|
|
163
|
+
const ctx = getIdentityContext();
|
|
164
|
+
if (!ctx?.url) {
|
|
165
|
+
throw new AuthError("Could not determine the Identity endpoint URL on the server");
|
|
166
|
+
}
|
|
167
|
+
return ctx.url;
|
|
168
|
+
};
|
|
156
169
|
var persistSession = true;
|
|
157
170
|
var listeners = /* @__PURE__ */ new Set();
|
|
158
171
|
var emitAuthEvent = (event, user) => {
|
|
@@ -187,6 +200,45 @@ var onAuthChange = (callback) => {
|
|
|
187
200
|
};
|
|
188
201
|
};
|
|
189
202
|
var login = async (email, password) => {
|
|
203
|
+
if (!isBrowser()) {
|
|
204
|
+
const identityUrl = getServerIdentityUrl();
|
|
205
|
+
const cookies = getCookies();
|
|
206
|
+
const body = new URLSearchParams({
|
|
207
|
+
grant_type: "password",
|
|
208
|
+
username: email,
|
|
209
|
+
password
|
|
210
|
+
});
|
|
211
|
+
let res;
|
|
212
|
+
try {
|
|
213
|
+
res = await fetch(`${identityUrl}/token`, {
|
|
214
|
+
method: "POST",
|
|
215
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
216
|
+
body: body.toString()
|
|
217
|
+
});
|
|
218
|
+
} catch (error) {
|
|
219
|
+
throw new AuthError(error.message, void 0, { cause: error });
|
|
220
|
+
}
|
|
221
|
+
if (!res.ok) {
|
|
222
|
+
const errorBody = await res.json().catch(() => ({}));
|
|
223
|
+
throw new AuthError(
|
|
224
|
+
errorBody.msg || errorBody.error_description || `Login failed (${res.status})`,
|
|
225
|
+
res.status
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
const data = await res.json();
|
|
229
|
+
const accessToken = data.access_token;
|
|
230
|
+
const userData = data;
|
|
231
|
+
const user = toUser(userData);
|
|
232
|
+
cookies.set({
|
|
233
|
+
name: "nf_jwt",
|
|
234
|
+
value: accessToken,
|
|
235
|
+
httpOnly: true,
|
|
236
|
+
secure: true,
|
|
237
|
+
path: "/",
|
|
238
|
+
sameSite: "Lax"
|
|
239
|
+
});
|
|
240
|
+
return user;
|
|
241
|
+
}
|
|
190
242
|
const client = getClient();
|
|
191
243
|
try {
|
|
192
244
|
const gotrueUser = await client.login(email, password, persistSession);
|
|
@@ -198,6 +250,40 @@ var login = async (email, password) => {
|
|
|
198
250
|
}
|
|
199
251
|
};
|
|
200
252
|
var signup = async (email, password, data) => {
|
|
253
|
+
if (!isBrowser()) {
|
|
254
|
+
const identityUrl = getServerIdentityUrl();
|
|
255
|
+
const cookies = getCookies();
|
|
256
|
+
let res;
|
|
257
|
+
try {
|
|
258
|
+
res = await fetch(`${identityUrl}/signup`, {
|
|
259
|
+
method: "POST",
|
|
260
|
+
headers: { "Content-Type": "application/json" },
|
|
261
|
+
body: JSON.stringify({ email, password, data })
|
|
262
|
+
});
|
|
263
|
+
} catch (error) {
|
|
264
|
+
throw new AuthError(error.message, void 0, { cause: error });
|
|
265
|
+
}
|
|
266
|
+
if (!res.ok) {
|
|
267
|
+
const errorBody = await res.json().catch(() => ({}));
|
|
268
|
+
throw new AuthError(errorBody.msg || `Signup failed (${res.status})`, res.status);
|
|
269
|
+
}
|
|
270
|
+
const responseData = await res.json();
|
|
271
|
+
const user = toUser(responseData);
|
|
272
|
+
if (responseData.confirmed_at) {
|
|
273
|
+
const accessToken = responseData.access_token;
|
|
274
|
+
if (accessToken) {
|
|
275
|
+
cookies.set({
|
|
276
|
+
name: "nf_jwt",
|
|
277
|
+
value: accessToken,
|
|
278
|
+
httpOnly: true,
|
|
279
|
+
secure: true,
|
|
280
|
+
path: "/",
|
|
281
|
+
sameSite: "Lax"
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return user;
|
|
286
|
+
}
|
|
201
287
|
const client = getClient();
|
|
202
288
|
try {
|
|
203
289
|
const response = await client.signup(email, password, data);
|
|
@@ -211,6 +297,23 @@ var signup = async (email, password, data) => {
|
|
|
211
297
|
}
|
|
212
298
|
};
|
|
213
299
|
var logout = async () => {
|
|
300
|
+
if (!isBrowser()) {
|
|
301
|
+
const identityUrl = getServerIdentityUrl();
|
|
302
|
+
const cookies = getCookies();
|
|
303
|
+
const jwt = cookies.get("nf_jwt");
|
|
304
|
+
if (jwt) {
|
|
305
|
+
try {
|
|
306
|
+
await fetch(`${identityUrl}/logout`, {
|
|
307
|
+
method: "POST",
|
|
308
|
+
headers: { Authorization: `Bearer ${jwt}` }
|
|
309
|
+
});
|
|
310
|
+
} catch (error) {
|
|
311
|
+
throw new AuthError(error.message, void 0, { cause: error });
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
cookies.delete("nf_jwt");
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
214
317
|
const client = getClient();
|
|
215
318
|
try {
|
|
216
319
|
const currentUser = client.currentUser();
|
|
@@ -277,12 +380,7 @@ var handleAuthCallback = async () => {
|
|
|
277
380
|
}
|
|
278
381
|
const emailChangeToken = params.get("email_change_token");
|
|
279
382
|
if (emailChangeToken) {
|
|
280
|
-
const
|
|
281
|
-
if (!currentUser) {
|
|
282
|
-
clearHash();
|
|
283
|
-
return { type: "email_change", user: null, token: emailChangeToken };
|
|
284
|
-
}
|
|
285
|
-
const gotrueUser = await currentUser.update({ email_change_token: emailChangeToken });
|
|
383
|
+
const gotrueUser = await client.verify("email_change", emailChangeToken, persistSession);
|
|
286
384
|
const user = toUser(gotrueUser);
|
|
287
385
|
clearHash();
|
|
288
386
|
emitAuthEvent("user_updated", user);
|
|
@@ -306,6 +404,18 @@ var requestPasswordRecovery = async (email) => {
|
|
|
306
404
|
throw new AuthError(error.message, void 0, { cause: error });
|
|
307
405
|
}
|
|
308
406
|
};
|
|
407
|
+
var recoverPassword = async (token, newPassword) => {
|
|
408
|
+
const client = getClient();
|
|
409
|
+
try {
|
|
410
|
+
const gotrueUser = await client.recover(token, persistSession);
|
|
411
|
+
const updatedUser = await gotrueUser.update({ password: newPassword });
|
|
412
|
+
const user = toUser(updatedUser);
|
|
413
|
+
emitAuthEvent("login", user);
|
|
414
|
+
return user;
|
|
415
|
+
} catch (error) {
|
|
416
|
+
throw new AuthError(error.message, void 0, { cause: error });
|
|
417
|
+
}
|
|
418
|
+
};
|
|
309
419
|
var confirmEmail = async (token) => {
|
|
310
420
|
const client = getClient();
|
|
311
421
|
try {
|
|
@@ -330,10 +440,8 @@ var acceptInvite = async (token, password) => {
|
|
|
330
440
|
};
|
|
331
441
|
var verifyEmailChange = async (token) => {
|
|
332
442
|
const client = getClient();
|
|
333
|
-
const currentUser = client.currentUser();
|
|
334
|
-
if (!currentUser) throw new AuthError("No user is currently logged in");
|
|
335
443
|
try {
|
|
336
|
-
const gotrueUser = await
|
|
444
|
+
const gotrueUser = await client.verify("email_change", token, persistSession);
|
|
337
445
|
const user = toUser(gotrueUser);
|
|
338
446
|
emitAuthEvent("user_updated", user);
|
|
339
447
|
return user;
|
|
@@ -368,6 +476,7 @@ export {
|
|
|
368
476
|
logout,
|
|
369
477
|
oauthLogin,
|
|
370
478
|
onAuthChange,
|
|
479
|
+
recoverPassword,
|
|
371
480
|
requestPasswordRecovery,
|
|
372
481
|
signup,
|
|
373
482
|
updateUser,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts","../src/environment.ts","../src/errors.ts","../src/user.ts","../src/config.ts","../src/auth.ts","../src/account.ts"],"sourcesContent":["export const AUTH_PROVIDERS = ['google', 'github', 'gitlab', 'bitbucket', 'facebook', 'saml', 'email'] as const\nexport type AuthProvider = (typeof AUTH_PROVIDERS)[number]\n\nexport interface AppMetadata {\n provider: AuthProvider\n roles?: string[]\n [key: string]: unknown\n}\n\nexport interface IdentityConfig {\n url: string\n token?: string // this is an operator token, only available on the server\n}\n\nexport interface Settings {\n autoconfirm: boolean\n disableSignup: boolean\n providers: Record<AuthProvider, boolean>\n}\n","import GoTrue from 'gotrue-js'\n\nimport type { IdentityConfig } from './types.js'\nimport { MissingIdentityError } from './errors.js'\n\nlet goTrueClient: GoTrue | null = null\nlet cachedApiUrl: string | null | undefined\nlet warnedMissingUrl = false\n\nexport const isBrowser = (): boolean => typeof window !== 'undefined' && typeof window.location !== 'undefined'\n\n/**\n * Discovers and caches the GoTrue API URL.\n *\n * Browser: uses `window.location.origin` + `/.netlify/identity`.\n * Server: reads from `globalThis.netlifyIdentityContext`.\n */\nconst discoverApiUrl = (): string | null => {\n if (cachedApiUrl !== undefined) return cachedApiUrl\n\n if (isBrowser()) {\n cachedApiUrl = `${window.location.origin}/.netlify/identity`\n } else {\n const identityContext = getIdentityContext()\n if (identityContext?.url) {\n cachedApiUrl = identityContext.url\n } else if (globalThis.Netlify?.context?.url) {\n cachedApiUrl = new URL('/.netlify/identity', globalThis.Netlify.context.url).href\n }\n }\n\n return cachedApiUrl ?? null\n}\n\n/**\n * Returns (and lazily creates) a singleton gotrue-js client.\n * Returns `null` and logs a warning if no identity URL can be discovered.\n */\nexport const getGoTrueClient = (): GoTrue | null => {\n if (goTrueClient) return goTrueClient\n\n const apiUrl = discoverApiUrl()\n if (!apiUrl) {\n if (!warnedMissingUrl) {\n console.warn(\n '@netlify/identity: Could not determine the Identity endpoint URL. ' +\n 'Make sure your site has Netlify Identity enabled, or run your app with `netlify dev`.',\n )\n warnedMissingUrl = true\n }\n return null\n }\n\n goTrueClient = new GoTrue({ APIUrl: apiUrl, setCookie: isBrowser() })\n return goTrueClient\n}\n\n/**\n * Returns the singleton gotrue-js client, or throws if Identity is not configured.\n */\nexport const getClient = (): GoTrue => {\n const client = getGoTrueClient()\n if (!client) throw new MissingIdentityError()\n return client\n}\n\n/**\n * Reads the server-side identity context set by the Netlify bootstrap.\n * Returns `null` outside the Netlify serverless environment.\n */\nexport const getIdentityContext = (): IdentityConfig | null => {\n // TODO(kh): After Stargate deploys EX-1764, netlifyIdentityContext will have\n // typed `url` and `token` fields. Remove the typeof guards and use direct access.\n // https://linear.app/netlify/issue/EX-1764/identity-stargate-needs-to-set-identity-url-and-providertoken\n const identityContext = globalThis.netlifyIdentityContext\n if (identityContext?.url && typeof identityContext.url === 'string') {\n return {\n url: identityContext.url,\n token: typeof identityContext.token === 'string' ? identityContext.token : undefined,\n }\n }\n\n if (globalThis.Netlify?.context?.url) {\n return { url: new URL('/.netlify/identity', globalThis.Netlify.context.url).href }\n }\n\n return null\n}\n\n/** Reset cached state for tests. */\nexport const resetTestGoTrueClient = (): void => {\n goTrueClient = null\n cachedApiUrl = undefined\n warnedMissingUrl = false\n}\n","export class AuthError extends Error {\n override name = 'AuthError'\n status?: number\n declare cause?: unknown\n\n constructor(message: string, status?: number, options?: { cause?: unknown }) {\n super(message)\n this.status = status\n if (options && 'cause' in options) {\n this.cause = options.cause\n }\n }\n}\n\nexport class MissingIdentityError extends Error {\n override name = 'MissingIdentityError'\n\n constructor(message = 'Identity is not available in this environment') {\n super(message)\n }\n}\n","import type { UserData } from 'gotrue-js'\nimport { AUTH_PROVIDERS, type AuthProvider } from './types.js'\nimport { getGoTrueClient, isBrowser } from './environment.js'\n\nconst toAuthProvider = (value: unknown): AuthProvider | undefined =>\n typeof value === 'string' && (AUTH_PROVIDERS as readonly string[]).includes(value)\n ? (value as AuthProvider)\n : undefined\n\nexport interface User {\n id: string\n email?: string\n emailVerified?: boolean\n createdAt?: string\n updatedAt?: string\n provider?: AuthProvider\n name?: string\n pictureUrl?: string\n metadata?: Record<string, unknown>\n rawGoTrueData?: Record<string, unknown>\n}\n\nexport const toUser = (userData: UserData): User => {\n const userMeta = userData.user_metadata ?? {}\n const appMeta = userData.app_metadata ?? {}\n const name = userMeta.full_name || userMeta.name\n const pictureUrl = userMeta.avatar_url\n\n return {\n id: userData.id,\n email: userData.email,\n emailVerified: !!userData.confirmed_at,\n createdAt: userData.created_at,\n updatedAt: userData.updated_at,\n provider: toAuthProvider(appMeta.provider),\n name: typeof name === 'string' ? name : undefined,\n pictureUrl: typeof pictureUrl === 'string' ? pictureUrl : undefined,\n metadata: userMeta,\n rawGoTrueData: { ...userData },\n }\n}\n\n/**\n * Converts raw JWT claims from the identity header into a User.\n * JWT claims use a different shape than the gotrue-js UserData class.\n */\nconst claimsToUser = (claims: Record<string, unknown>): User => {\n const appMeta = (claims.app_metadata ?? {}) as Record<string, unknown>\n const userMeta = (claims.user_metadata ?? {}) as Record<string, unknown>\n const name = userMeta.full_name || userMeta.name\n\n return {\n id: typeof claims.sub === 'string' ? claims.sub : '',\n email: typeof claims.email === 'string' ? claims.email : undefined,\n provider: toAuthProvider(appMeta.provider),\n name: typeof name === 'string' ? name : undefined,\n metadata: userMeta,\n }\n}\n\n/**\n * Returns the currently authenticated user, or `null` if not logged in.\n * Synchronous. Never throws.\n */\nexport const getUser = (): User | null => {\n if (isBrowser()) {\n const client = getGoTrueClient()\n const currentUser = client?.currentUser() ?? null\n if (!currentUser) return null\n return toUser(currentUser)\n }\n\n const identityContext = globalThis.netlifyIdentityContext\n if (!identityContext) return null\n\n const claims = identityContext.user ?? (identityContext.sub ? identityContext : null)\n if (!claims) return null\n return claimsToUser(claims as Record<string, unknown>)\n}\n\n/**\n * Returns `true` if a user is currently authenticated.\n */\nexport const isAuthenticated = (): boolean => getUser() !== null\n","import type { AuthProvider, IdentityConfig, Settings } from './types.js'\nimport { AuthError } from './errors.js'\nimport { getClient, getIdentityContext, isBrowser } from './environment.js'\n\n/**\n * Returns the identity configuration for the current environment.\n * Browser: always returns `{ url }` derived from `window.location.origin`.\n * Server: returns `{ url, token }` from the identity context, or `null` if unavailable.\n * Never throws.\n */\nexport const getIdentityConfig = (): IdentityConfig | null => {\n if (isBrowser()) {\n return { url: `${window.location.origin}/.netlify/identity` }\n }\n\n return getIdentityContext()\n}\n\n/**\n * Fetches the GoTrue `/settings` endpoint.\n * Throws `MissingIdentityError` if Identity is not configured.\n * Throws `AuthError` if the endpoint is unreachable.\n */\nexport const getSettings = async (): Promise<Settings> => {\n const client = getClient()\n\n try {\n const raw = await client.settings()\n const external: Partial<Record<AuthProvider, boolean>> = raw.external ?? {}\n return {\n autoconfirm: raw.autoconfirm,\n disableSignup: raw.disable_signup,\n providers: {\n google: external.google ?? false,\n github: external.github ?? false,\n gitlab: external.gitlab ?? false,\n bitbucket: external.bitbucket ?? false,\n facebook: external.facebook ?? false,\n email: external.email ?? false,\n saml: external.saml ?? false,\n },\n }\n } catch (err) {\n throw new AuthError(err instanceof Error ? err.message : 'Failed to fetch identity settings', 502, { cause: err })\n }\n}\n","import type { UserData } from 'gotrue-js'\n\nimport type { AppMetadata } from './types.js'\n\nexport type AuthEvent = 'login' | 'logout' | 'token_refresh' | 'user_updated'\nimport type { User } from './user.js'\nimport { toUser } from './user.js'\nimport { getGoTrueClient, getClient, isBrowser } from './environment.js'\nimport { AuthError } from './errors.js'\n\nexport interface JWTClaims {\n sub: string // UUID\n email: string\n exp: number\n iat: number\n aud: string\n app_metadata: AppMetadata\n user_metadata: Record<string, unknown>\n}\n\nexport type AuthCallback = (event: AuthEvent, user: User | null) => void\n\n/** Persist the session to localStorage so it survives page reloads. */\nexport const persistSession = true\n\nconst listeners = new Set<AuthCallback>()\n\nexport const emitAuthEvent = (event: AuthEvent, user: User | null): void => {\n for (const listener of listeners) {\n listener(event, user)\n }\n}\n\nlet storageListenerAttached = false\n\nconst attachStorageListener = (): void => {\n if (storageListenerAttached) return\n storageListenerAttached = true\n\n window.addEventListener('storage', (event: StorageEvent) => {\n if (event.key !== 'gotrue.user') return\n\n if (event.newValue) {\n const client = getGoTrueClient()\n const currentUser = client?.currentUser()\n emitAuthEvent('login', currentUser ? toUser(currentUser) : null)\n } else {\n emitAuthEvent('logout', null)\n }\n })\n}\n\n/**\n * Subscribes to auth state changes (login, logout, token refresh, user updates).\n * Returns an unsubscribe function. No-op on the server.\n */\nexport const onAuthChange = (callback: AuthCallback): (() => void) => {\n if (!isBrowser()) {\n return () => {}\n }\n\n listeners.add(callback)\n attachStorageListener()\n\n return () => {\n listeners.delete(callback)\n }\n}\n\n/** Logs in with email and password. Browser only. */\nexport const login = async (email: string, password: string): Promise<User> => {\n const client = getClient()\n\n try {\n const gotrueUser = await client.login(email, password, persistSession)\n const user = toUser(gotrueUser)\n emitAuthEvent('login', user)\n return user\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\n/** Creates a new account. Emits 'login' if autoconfirm is enabled. Browser only. */\nexport const signup = async (email: string, password: string, data?: Record<string, unknown>): Promise<User> => {\n const client = getClient()\n\n try {\n const response = await client.signup(email, password, data)\n const user = toUser(response as UserData)\n if (response.confirmed_at) {\n emitAuthEvent('login', user)\n }\n return user\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\n/** Logs out the current user and clears the session. Browser only. */\nexport const logout = async (): Promise<void> => {\n const client = getClient()\n\n try {\n const currentUser = client.currentUser()\n if (currentUser) {\n await currentUser.logout()\n }\n emitAuthEvent('logout', null)\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\n/** Redirects to an OAuth provider. Always throws (the page navigates away). Browser only. */\nexport const oauthLogin = (provider: string): never => {\n if (!isBrowser()) {\n throw new Error('oauthLogin() is only available in the browser')\n }\n const client = getClient()\n\n window.location.href = client.loginExternalUrl(provider)\n throw new Error('Redirecting to OAuth provider')\n}\n\nexport interface CallbackResult {\n type: 'oauth' | 'confirmation' | 'recovery' | 'invite' | 'email_change'\n user: User | null\n token?: string\n}\n\n/**\n * Processes the URL hash after an OAuth redirect, email confirmation, password\n * recovery, invite acceptance, or email change. Call on page load. Browser only.\n * Returns `null` if the hash contains no auth parameters.\n */\nexport const handleAuthCallback = async (): Promise<CallbackResult | null> => {\n if (!isBrowser()) return null\n\n const hash = window.location.hash.substring(1)\n if (!hash) return null\n\n const client = getClient()\n\n try {\n const params = new URLSearchParams(hash)\n\n const accessToken = params.get('access_token')\n if (accessToken) {\n const gotrueUser = await client.createUser(\n {\n access_token: accessToken,\n token_type: (params.get('token_type') as 'bearer') ?? 'bearer',\n expires_in: Number(params.get('expires_in')),\n expires_at: Number(params.get('expires_at')),\n refresh_token: params.get('refresh_token') ?? '',\n },\n persistSession,\n )\n const user = toUser(gotrueUser)\n clearHash()\n emitAuthEvent('login', user)\n return { type: 'oauth', user }\n }\n\n const confirmationToken = params.get('confirmation_token')\n if (confirmationToken) {\n const gotrueUser = await client.confirm(confirmationToken, persistSession)\n const user = toUser(gotrueUser)\n clearHash()\n emitAuthEvent('login', user)\n return { type: 'confirmation', user }\n }\n\n const recoveryToken = params.get('recovery_token')\n if (recoveryToken) {\n const gotrueUser = await client.recover(recoveryToken, persistSession)\n const user = toUser(gotrueUser)\n clearHash()\n emitAuthEvent('login', user)\n return { type: 'recovery', user }\n }\n\n const inviteToken = params.get('invite_token')\n if (inviteToken) {\n clearHash()\n return { type: 'invite', user: null, token: inviteToken }\n }\n\n const emailChangeToken = params.get('email_change_token')\n if (emailChangeToken) {\n const currentUser = client.currentUser()\n if (!currentUser) {\n clearHash()\n return { type: 'email_change', user: null, token: emailChangeToken }\n }\n const gotrueUser = await currentUser.update({ email_change_token: emailChangeToken })\n const user = toUser(gotrueUser)\n clearHash()\n emitAuthEvent('user_updated', user)\n return { type: 'email_change', user }\n }\n\n return null\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\nconst clearHash = (): void => {\n history.replaceState(null, '', window.location.pathname + window.location.search)\n}\n","import type { User } from './user.js'\nimport { toUser } from './user.js'\nimport { getClient } from './environment.js'\nimport { emitAuthEvent, persistSession } from './auth.js'\nimport { AuthError } from './errors.js'\n\n/** Sends a password recovery email to the given address. */\nexport const requestPasswordRecovery = async (email: string): Promise<void> => {\n const client = getClient()\n\n try {\n await client.requestPasswordRecovery(email)\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\n/** Confirms an email address using the token from a confirmation email. Logs the user in on success. */\nexport const confirmEmail = async (token: string): Promise<User> => {\n const client = getClient()\n\n try {\n const gotrueUser = await client.confirm(token, persistSession)\n const user = toUser(gotrueUser)\n emitAuthEvent('login', user)\n return user\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\n/** Accepts an invite token and sets a password for the new account. Logs the user in on success. */\nexport const acceptInvite = async (token: string, password: string): Promise<User> => {\n const client = getClient()\n\n try {\n const gotrueUser = await client.acceptInvite(token, password, persistSession)\n const user = toUser(gotrueUser)\n emitAuthEvent('login', user)\n return user\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\n/** Verifies an email change using the token from a verification email. Requires an active session. */\nexport const verifyEmailChange = async (token: string): Promise<User> => {\n const client = getClient()\n\n const currentUser = client.currentUser()\n if (!currentUser) throw new AuthError('No user is currently logged in')\n\n try {\n const gotrueUser = await currentUser.update({ email_change_token: token })\n const user = toUser(gotrueUser)\n emitAuthEvent('user_updated', user)\n return user\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\n/** Updates the current user's metadata or credentials. Requires an active session. */\nexport const updateUser = async (updates: Record<string, unknown>): Promise<User> => {\n const client = getClient()\n\n const currentUser = client.currentUser()\n if (!currentUser) throw new AuthError('No user is currently logged in')\n\n try {\n const updatedUser = await currentUser.update(updates)\n const user = toUser(updatedUser)\n emitAuthEvent('user_updated', user)\n return user\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n"],"mappings":";AAAO,IAAM,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,UAAU;AAC9B,kBAAc,gBAAgB,IAAI;AAClC,WAAO;AAAA,EACT,SAAS,OAAO;AACd,UAAM,IAAI,UAAW,MAAgB,SAAS,QAAW,EAAE,OAAO,MAAM,CAAC;AAAA,EAC3E;AACF;AAGO,IAAM,aAAa,OAAO,YAAoD;AACnF,QAAM,SAAS,UAAU;AAEzB,QAAM,cAAc,OAAO,YAAY;AACvC,MAAI,CAAC,YAAa,OAAM,IAAI,UAAU,gCAAgC;AAEtE,MAAI;AACF,UAAM,cAAc,MAAM,YAAY,OAAO,OAAO;AACpD,UAAM,OAAO,OAAO,WAAW;AAC/B,kBAAc,gBAAgB,IAAI;AAClC,WAAO;AAAA,EACT,SAAS,OAAO;AACd,UAAM,IAAI,UAAW,MAAgB,SAAS,QAAW,EAAE,OAAO,MAAM,CAAC;AAAA,EAC3E;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/types.ts","../src/environment.ts","../src/errors.ts","../src/user.ts","../src/config.ts","../src/auth.ts","../src/account.ts"],"sourcesContent":["export const AUTH_PROVIDERS = ['google', 'github', 'gitlab', 'bitbucket', 'facebook', 'saml', 'email'] as const\nexport type AuthProvider = (typeof AUTH_PROVIDERS)[number]\n\nexport interface AppMetadata {\n provider: AuthProvider\n roles?: string[]\n [key: string]: unknown\n}\n\nexport interface IdentityConfig {\n url: string\n token?: string // this is an operator token, only available on the server\n}\n\nexport interface Settings {\n autoconfirm: boolean\n disableSignup: boolean\n providers: Record<AuthProvider, boolean>\n}\n\nexport interface NetlifyCookies {\n get(name: string): string | undefined\n set(options: {\n name: string\n value: string\n httpOnly: boolean\n secure: boolean\n path: string\n sameSite: string\n }): void\n delete(name: string): void\n}\n","import GoTrue from 'gotrue-js'\n\nimport type { IdentityConfig } from './types.js'\nimport { MissingIdentityError } from './errors.js'\n\nexport const IDENTITY_PATH = '/.netlify/identity'\n\nlet goTrueClient: GoTrue | null = null\nlet cachedApiUrl: string | null | undefined\nlet warnedMissingUrl = false\n\nexport const isBrowser = (): boolean => typeof window !== 'undefined' && typeof window.location !== 'undefined'\n\n/**\n * Discovers and caches the GoTrue API URL.\n *\n * Browser: uses `window.location.origin` + IDENTITY_PATH.\n * Server: reads from `globalThis.netlifyIdentityContext`.\n */\nconst discoverApiUrl = (): string | null => {\n if (cachedApiUrl !== undefined) return cachedApiUrl\n\n if (isBrowser()) {\n cachedApiUrl = `${window.location.origin}${IDENTITY_PATH}`\n } else {\n const identityContext = getIdentityContext()\n if (identityContext?.url) {\n cachedApiUrl = identityContext.url\n } else if (globalThis.Netlify?.context?.url) {\n cachedApiUrl = new URL(IDENTITY_PATH, globalThis.Netlify.context.url).href\n }\n }\n\n return cachedApiUrl ?? null\n}\n\n/**\n * Returns (and lazily creates) a singleton gotrue-js client.\n * Returns `null` and logs a warning if no identity URL can be discovered.\n */\nexport const getGoTrueClient = (): GoTrue | null => {\n if (goTrueClient) return goTrueClient\n\n const apiUrl = discoverApiUrl()\n if (!apiUrl) {\n if (!warnedMissingUrl) {\n console.warn(\n '@netlify/identity: Could not determine the Identity endpoint URL. ' +\n 'Make sure your site has Netlify Identity enabled, or run your app with `netlify dev`.',\n )\n warnedMissingUrl = true\n }\n return null\n }\n\n goTrueClient = new GoTrue({ APIUrl: apiUrl, setCookie: isBrowser() })\n return goTrueClient\n}\n\n/**\n * Returns the singleton gotrue-js client, or throws if Identity is not configured.\n */\nexport const getClient = (): GoTrue => {\n const client = getGoTrueClient()\n if (!client) throw new MissingIdentityError()\n return client\n}\n\n/**\n * Reads the server-side identity context set by the Netlify bootstrap.\n * Returns `null` outside the Netlify serverless environment.\n */\nexport const getIdentityContext = (): IdentityConfig | null => {\n const identityContext = globalThis.netlifyIdentityContext\n if (identityContext?.url) {\n return {\n url: identityContext.url,\n token: identityContext.token,\n }\n }\n\n if (globalThis.Netlify?.context?.url) {\n return { url: new URL(IDENTITY_PATH, globalThis.Netlify.context.url).href }\n }\n\n return null\n}\n\n/** Reset cached state for tests. */\nexport const resetTestGoTrueClient = (): void => {\n goTrueClient = null\n cachedApiUrl = undefined\n warnedMissingUrl = false\n}\n","export class AuthError extends Error {\n override name = 'AuthError'\n status?: number\n declare cause?: unknown\n\n constructor(message: string, status?: number, options?: { cause?: unknown }) {\n super(message)\n this.status = status\n if (options && 'cause' in options) {\n this.cause = options.cause\n }\n }\n}\n\nexport class MissingIdentityError extends Error {\n override name = 'MissingIdentityError'\n\n constructor(message = 'Identity is not available in this environment') {\n super(message)\n }\n}\n","import type { UserData } from 'gotrue-js'\nimport { AUTH_PROVIDERS, type AuthProvider } from './types.js'\nimport { getGoTrueClient, isBrowser } from './environment.js'\n\nexport interface IdentityUser {\n sub?: string\n email?: string\n exp?: number\n app_metadata?: Record<string, unknown>\n user_metadata?: Record<string, unknown>\n [key: string]: unknown\n}\n\nconst toAuthProvider = (value: unknown): AuthProvider | undefined =>\n typeof value === 'string' && (AUTH_PROVIDERS as readonly string[]).includes(value)\n ? (value as AuthProvider)\n : undefined\n\nexport interface User {\n id: string\n email?: string\n emailVerified?: boolean\n createdAt?: string\n updatedAt?: string\n provider?: AuthProvider\n name?: string\n pictureUrl?: string\n metadata?: Record<string, unknown>\n rawGoTrueData?: Record<string, unknown>\n}\n\nexport const toUser = (userData: UserData): User => {\n const userMeta = userData.user_metadata ?? {}\n const appMeta = userData.app_metadata ?? {}\n const name = userMeta.full_name || userMeta.name\n const pictureUrl = userMeta.avatar_url\n\n return {\n id: userData.id,\n email: userData.email,\n emailVerified: !!userData.confirmed_at,\n createdAt: userData.created_at,\n updatedAt: userData.updated_at,\n provider: toAuthProvider(appMeta.provider),\n name: typeof name === 'string' ? name : undefined,\n pictureUrl: typeof pictureUrl === 'string' ? pictureUrl : undefined,\n metadata: userMeta,\n rawGoTrueData: { ...userData },\n }\n}\n\n/**\n * Converts server-side JWT claims into User\n */\nconst claimsToUser = (claims: IdentityUser): User => {\n const appMeta = claims.app_metadata ?? {}\n const userMeta = claims.user_metadata ?? {}\n const name = userMeta.full_name || userMeta.name\n\n return {\n id: claims.sub ?? '',\n email: claims.email,\n provider: toAuthProvider(appMeta.provider),\n name: typeof name === 'string' ? name : undefined,\n metadata: userMeta,\n }\n}\n\n/**\n * Returns the currently authenticated user, or `null` if not logged in.\n * Synchronous. Never throws.\n */\nexport const getUser = (): User | null => {\n if (isBrowser()) {\n const client = getGoTrueClient()\n const currentUser = client?.currentUser() ?? null\n if (!currentUser) return null\n return toUser(currentUser)\n }\n\n const identityContext = globalThis.netlifyIdentityContext\n if (!identityContext?.user) return null\n\n return claimsToUser(identityContext.user)\n}\n\n/**\n * Returns `true` if a user is currently authenticated.\n */\nexport const isAuthenticated = (): boolean => getUser() !== null\n","import type { AuthProvider, IdentityConfig, Settings } from './types.js'\nimport { getClient, getIdentityContext, IDENTITY_PATH, isBrowser } from './environment.js'\nimport { AuthError } from './errors.js'\n\n/**\n * Returns the identity configuration for the current environment.\n * Browser: always returns `{ url }` derived from `window.location.origin`.\n * Server: returns `{ url, token }` from the identity context, or `null` if unavailable.\n * Never throws.\n */\nexport const getIdentityConfig = (): IdentityConfig | null => {\n if (isBrowser()) {\n return { url: `${window.location.origin}${IDENTITY_PATH}` }\n }\n\n return getIdentityContext()\n}\n\n/**\n * Fetches the GoTrue `/settings` endpoint.\n * Throws `MissingIdentityError` if Identity is not configured.\n * Throws `AuthError` if the endpoint is unreachable.\n */\nexport const getSettings = async (): Promise<Settings> => {\n const client = getClient()\n\n try {\n const raw = await client.settings()\n const external: Partial<Record<AuthProvider, boolean>> = raw.external ?? {}\n return {\n autoconfirm: raw.autoconfirm,\n disableSignup: raw.disable_signup,\n providers: {\n google: external.google ?? false,\n github: external.github ?? false,\n gitlab: external.gitlab ?? false,\n bitbucket: external.bitbucket ?? false,\n facebook: external.facebook ?? false,\n email: external.email ?? false,\n saml: external.saml ?? false,\n },\n }\n } catch (err) {\n throw new AuthError(err instanceof Error ? err.message : 'Failed to fetch identity settings', 502, { cause: err })\n }\n}\n","import type { UserData } from 'gotrue-js'\n\nimport type { AppMetadata, NetlifyCookies } from './types.js'\n\nexport type AuthEvent = 'login' | 'logout' | 'token_refresh' | 'user_updated'\nimport type { User } from './user.js'\nimport { toUser } from './user.js'\nimport { getGoTrueClient, getClient, getIdentityContext, isBrowser } from './environment.js'\nimport { AuthError } from './errors.js'\n\nconst getCookies = (): NetlifyCookies => {\n const cookies = globalThis.Netlify?.context?.cookies\n if (!cookies) {\n throw new AuthError('Server-side auth requires Netlify Functions runtime')\n }\n return cookies\n}\n\nconst getServerIdentityUrl = (): string => {\n const ctx = getIdentityContext()\n if (!ctx?.url) {\n throw new AuthError('Could not determine the Identity endpoint URL on the server')\n }\n return ctx.url\n}\n\nexport interface JWTClaims {\n sub: string // UUID\n email: string\n exp: number\n iat: number\n aud: string\n app_metadata: AppMetadata\n user_metadata: Record<string, unknown>\n}\n\nexport type AuthCallback = (event: AuthEvent, user: User | null) => void\n\n/** Persist the session to localStorage so it survives page reloads. */\nexport const persistSession = true\n\nconst listeners = new Set<AuthCallback>()\n\nexport const emitAuthEvent = (event: AuthEvent, user: User | null): void => {\n for (const listener of listeners) {\n listener(event, user)\n }\n}\n\nlet storageListenerAttached = false\n\nconst attachStorageListener = (): void => {\n if (storageListenerAttached) return\n storageListenerAttached = true\n\n window.addEventListener('storage', (event: StorageEvent) => {\n if (event.key !== 'gotrue.user') return\n\n if (event.newValue) {\n const client = getGoTrueClient()\n const currentUser = client?.currentUser()\n emitAuthEvent('login', currentUser ? toUser(currentUser) : null)\n } else {\n emitAuthEvent('logout', null)\n }\n })\n}\n\n/**\n * Subscribes to auth state changes (login, logout, token refresh, user updates).\n * Returns an unsubscribe function. No-op on the server.\n */\nexport const onAuthChange = (callback: AuthCallback): (() => void) => {\n if (!isBrowser()) {\n return () => {}\n }\n\n listeners.add(callback)\n attachStorageListener()\n\n return () => {\n listeners.delete(callback)\n }\n}\n\n/** Logs in with email and password. Works in both browser and server contexts. */\nexport const login = async (email: string, password: string): Promise<User> => {\n if (!isBrowser()) {\n const identityUrl = getServerIdentityUrl()\n const cookies = getCookies()\n\n const body = new URLSearchParams({\n grant_type: 'password',\n username: email,\n password,\n })\n\n let res: Response\n try {\n res = await fetch(`${identityUrl}/token`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/x-www-form-urlencoded' },\n body: body.toString(),\n })\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n\n if (!res.ok) {\n const errorBody = await res.json().catch(() => ({}))\n throw new AuthError(\n (errorBody as Record<string, string>).msg ||\n (errorBody as Record<string, string>).error_description ||\n `Login failed (${res.status})`,\n res.status,\n )\n }\n\n const data = (await res.json()) as Record<string, unknown>\n const accessToken = data.access_token as string\n const userData = data as unknown as UserData\n const user = toUser(userData)\n\n cookies.set({\n name: 'nf_jwt',\n value: accessToken,\n httpOnly: true,\n secure: true,\n path: '/',\n sameSite: 'Lax',\n })\n\n return user\n }\n\n const client = getClient()\n\n try {\n const gotrueUser = await client.login(email, password, persistSession)\n const user = toUser(gotrueUser)\n emitAuthEvent('login', user)\n return user\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\n/** Creates a new account. Emits 'login' if autoconfirm is enabled. Works in both browser and server contexts. */\nexport const signup = async (email: string, password: string, data?: Record<string, unknown>): Promise<User> => {\n if (!isBrowser()) {\n const identityUrl = getServerIdentityUrl()\n const cookies = getCookies()\n\n let res: Response\n try {\n res = await fetch(`${identityUrl}/signup`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ email, password, data }),\n })\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n\n if (!res.ok) {\n const errorBody = await res.json().catch(() => ({}))\n throw new AuthError((errorBody as Record<string, string>).msg || `Signup failed (${res.status})`, res.status)\n }\n\n const responseData = (await res.json()) as UserData\n const user = toUser(responseData)\n\n if (responseData.confirmed_at) {\n const accessToken = (responseData as unknown as Record<string, unknown>).access_token as string | undefined\n if (accessToken) {\n cookies.set({\n name: 'nf_jwt',\n value: accessToken,\n httpOnly: true,\n secure: true,\n path: '/',\n sameSite: 'Lax',\n })\n }\n }\n\n return user\n }\n\n const client = getClient()\n\n try {\n const response = await client.signup(email, password, data)\n const user = toUser(response as UserData)\n if (response.confirmed_at) {\n emitAuthEvent('login', user)\n }\n return user\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\n/** Logs out the current user and clears the session. Works in both browser and server contexts. */\nexport const logout = async (): Promise<void> => {\n if (!isBrowser()) {\n const identityUrl = getServerIdentityUrl()\n const cookies = getCookies()\n\n const jwt = cookies.get('nf_jwt')\n if (jwt) {\n try {\n await fetch(`${identityUrl}/logout`, {\n method: 'POST',\n headers: { Authorization: `Bearer ${jwt}` },\n })\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n }\n\n cookies.delete('nf_jwt')\n return\n }\n\n const client = getClient()\n\n try {\n const currentUser = client.currentUser()\n if (currentUser) {\n await currentUser.logout()\n }\n emitAuthEvent('logout', null)\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\n/** Redirects to an OAuth provider. Always throws (the page navigates away). Browser only. */\nexport const oauthLogin = (provider: string): never => {\n if (!isBrowser()) {\n throw new Error('oauthLogin() is only available in the browser')\n }\n const client = getClient()\n\n window.location.href = client.loginExternalUrl(provider)\n throw new Error('Redirecting to OAuth provider')\n}\n\nexport interface CallbackResult {\n type: 'oauth' | 'confirmation' | 'recovery' | 'invite' | 'email_change'\n user: User | null\n token?: string\n}\n\n/**\n * Processes the URL hash after an OAuth redirect, email confirmation, password\n * recovery, invite acceptance, or email change. Call on page load. Browser only.\n * Returns `null` if the hash contains no auth parameters.\n */\nexport const handleAuthCallback = async (): Promise<CallbackResult | null> => {\n if (!isBrowser()) return null\n\n const hash = window.location.hash.substring(1)\n if (!hash) return null\n\n const client = getClient()\n\n try {\n const params = new URLSearchParams(hash)\n\n const accessToken = params.get('access_token')\n if (accessToken) {\n const gotrueUser = await client.createUser(\n {\n access_token: accessToken,\n token_type: (params.get('token_type') as 'bearer') ?? 'bearer',\n expires_in: Number(params.get('expires_in')),\n expires_at: Number(params.get('expires_at')),\n refresh_token: params.get('refresh_token') ?? '',\n },\n persistSession,\n )\n const user = toUser(gotrueUser)\n clearHash()\n emitAuthEvent('login', user)\n return { type: 'oauth', user }\n }\n\n const confirmationToken = params.get('confirmation_token')\n if (confirmationToken) {\n const gotrueUser = await client.confirm(confirmationToken, persistSession)\n const user = toUser(gotrueUser)\n clearHash()\n emitAuthEvent('login', user)\n return { type: 'confirmation', user }\n }\n\n const recoveryToken = params.get('recovery_token')\n if (recoveryToken) {\n const gotrueUser = await client.recover(recoveryToken, persistSession)\n const user = toUser(gotrueUser)\n clearHash()\n emitAuthEvent('login', user)\n return { type: 'recovery', user }\n }\n\n const inviteToken = params.get('invite_token')\n if (inviteToken) {\n clearHash()\n return { type: 'invite', user: null, token: inviteToken }\n }\n\n const emailChangeToken = params.get('email_change_token')\n if (emailChangeToken) {\n const gotrueUser = await client.verify('email_change', emailChangeToken, persistSession)\n const user = toUser(gotrueUser)\n clearHash()\n emitAuthEvent('user_updated', user)\n return { type: 'email_change', user }\n }\n\n return null\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\nconst clearHash = (): void => {\n history.replaceState(null, '', window.location.pathname + window.location.search)\n}\n","import type { User } from './user.js'\nimport { toUser } from './user.js'\nimport { getClient } from './environment.js'\nimport { emitAuthEvent, persistSession } from './auth.js'\nimport { AuthError } from './errors.js'\n\n/** Sends a password recovery email to the given address. */\nexport const requestPasswordRecovery = async (email: string): Promise<void> => {\n const client = getClient()\n\n try {\n await client.requestPasswordRecovery(email)\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\n/** Redeems a recovery token and sets a new password. Logs the user in on success. */\nexport const recoverPassword = async (token: string, newPassword: string): Promise<User> => {\n const client = getClient()\n\n try {\n const gotrueUser = await client.recover(token, persistSession)\n const updatedUser = await gotrueUser.update({ password: newPassword })\n const user = toUser(updatedUser)\n emitAuthEvent('login', user)\n return user\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\n\n/** Confirms an email address using the token from a confirmation email. Logs the user in on success. */\nexport const confirmEmail = async (token: string): Promise<User> => {\n const client = getClient()\n\n try {\n const gotrueUser = await client.confirm(token, persistSession)\n const user = toUser(gotrueUser)\n emitAuthEvent('login', user)\n return user\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\n/** Accepts an invite token and sets a password for the new account. Logs the user in on success. */\nexport const acceptInvite = async (token: string, password: string): Promise<User> => {\n const client = getClient()\n\n try {\n const gotrueUser = await client.acceptInvite(token, password, persistSession)\n const user = toUser(gotrueUser)\n emitAuthEvent('login', user)\n return user\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\n/** Verifies an email change using the token from a verification email. */\nexport const verifyEmailChange = async (token: string): Promise<User> => {\n const client = getClient()\n\n try {\n const gotrueUser = await client.verify('email_change', token, persistSession)\n const user = toUser(gotrueUser)\n emitAuthEvent('user_updated', user)\n return user\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n\n/** Updates the current user's metadata or credentials. Requires an active session. */\nexport const updateUser = async (updates: Record<string, unknown>): Promise<User> => {\n const client = getClient()\n\n const currentUser = client.currentUser()\n if (!currentUser) throw new AuthError('No user is currently logged in')\n\n try {\n const updatedUser = await currentUser.update(updates)\n const user = toUser(updatedUser)\n emitAuthEvent('user_updated', user)\n return user\n } catch (error) {\n throw new AuthError((error as Error).message, undefined, { cause: error })\n }\n}\n"],"mappings":";AAAO,IAAM,iBAAiB,CAAC,UAAU,UAAU,UAAU,aAAa,YAAY,QAAQ,OAAO;;;ACArG,OAAO,YAAY;;;ACAZ,IAAM,YAAN,cAAwB,MAAM;AAAA,EAKnC,YAAY,SAAiB,QAAiB,SAA+B;AAC3E,UAAM,OAAO;AALf,SAAS,OAAO;AAMd,SA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