@authowl/next 0.4.6 → 0.4.7
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 +46 -1
- package/dist/chunk-QM64DWOE.js +8 -0
- package/dist/client.cjs +111 -39
- package/dist/client.js +110 -39
- package/dist/server.cjs +10 -1
- package/dist/server.js +8 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -81,6 +81,51 @@ The route accepts only same-origin browser requests and stores a token only
|
|
|
81
81
|
after AuthOwl validates that it belongs to a live session whose MFA enrollment
|
|
82
82
|
is complete. Never proxy this route through a different origin.
|
|
83
83
|
|
|
84
|
+
### Social and SSO callbacks with server-gated pages
|
|
85
|
+
|
|
86
|
+
Use a public sign-in or callback page on your application origin for the OAuth
|
|
87
|
+
return. Mount the bridge-aware `AuthOwlProvider` there. Keep that page and
|
|
88
|
+
`/api/authowl/session` reachable without an existing app-session cookie, including
|
|
89
|
+
in middleware and parent layouts. A Server Component cannot redeem a code from
|
|
90
|
+
the URL fragment, so returning directly to a page gated by `auth()` redirects the
|
|
91
|
+
visitor away before the browser can establish the app session.
|
|
92
|
+
|
|
93
|
+
For the drop-in forms, `redirectTo` is the final destination:
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
'use client';
|
|
97
|
+
|
|
98
|
+
import { SignIn } from '@authowl/react';
|
|
99
|
+
|
|
100
|
+
export default function SignInPage() {
|
|
101
|
+
return <SignIn redirectTo="/dashboard" />;
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
`<SignUp redirectTo="/dashboard" />` uses the same callback completion. Social
|
|
106
|
+
and SSO buttons return to the form page first. The SDK navigates to AuthOwl's
|
|
107
|
+
first-party session start endpoint, which sets the OAuth state in the auth
|
|
108
|
+
host's cookie context before visiting the provider. After the provider callback,
|
|
109
|
+
AuthOwl returns a single-use `#authowl_code` to your public page. Core removes the
|
|
110
|
+
fragment and redeems the code with the verifier held on your app origin. It then
|
|
111
|
+
awaits the Next bridge projection before completing the handoff. The form runs
|
|
112
|
+
its normal sign-in completion and navigates to `redirectTo`, where `auth()` can
|
|
113
|
+
validate the app-session cookie. Required MFA enrollment still completes before
|
|
114
|
+
that navigation.
|
|
115
|
+
|
|
116
|
+
For custom social or SSO controls, set `callbackURL` to a public page on the same
|
|
117
|
+
origin. On that page, await the client's optional `handoff` promise and finish
|
|
118
|
+
navigation only when it resolves `true`. A failed or expired handoff must leave
|
|
119
|
+
the visitor able to retry. Configure the callback origin in the project's
|
|
120
|
+
allowed origins.
|
|
121
|
+
|
|
122
|
+
The bridge stores only `{ sessionId, remember }` in localStorage under a
|
|
123
|
+
project-specific key so another tab can preserve the cookie lifetime. It uses
|
|
124
|
+
sessionStorage to avoid duplicate projections in the current tab. A different
|
|
125
|
+
session ID never inherits the previous session's remember choice. When browser
|
|
126
|
+
storage is unavailable, the current client retains the choice in memory;
|
|
127
|
+
a fresh client defaults to a session-only cookie.
|
|
128
|
+
|
|
84
129
|
For the remaining client-side components, use
|
|
85
130
|
[`@authowl/react`](https://www.npmjs.com/package/@authowl/react).
|
|
86
131
|
Those components use AuthOwl gold (`#F5B84C`) by default and automatically
|
|
@@ -88,7 +133,7 @@ honor project branding or an explicit `appearance.primaryColor` override.
|
|
|
88
133
|
|
|
89
134
|
**Optional UX middleware** (`@authowl/next/middleware`,
|
|
90
135
|
`createAuthRedirectMiddleware`) redirects unauthenticated users by cookie
|
|
91
|
-
presence
|
|
136
|
+
presence. It is a UX helper, **not** an authorization boundary. Always authorize
|
|
92
137
|
on the server with `auth()`, which re-validates against the auth service.
|
|
93
138
|
|
|
94
139
|
For bearer-token route handlers, `@authowl/next/server` also re-exports
|
package/dist/client.cjs
CHANGED
|
@@ -31,7 +31,35 @@ var import_core = require("@authowl/core");
|
|
|
31
31
|
var APP_SESSION_BRIDGE_HEADER = "x-authowl-session-bridge";
|
|
32
32
|
var APP_SESSION_BRIDGE_CODE_MAX_LENGTH = 4096;
|
|
33
33
|
|
|
34
|
+
// src/is-record.ts
|
|
35
|
+
function isRecord(value) {
|
|
36
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
37
|
+
}
|
|
38
|
+
|
|
34
39
|
// src/client.ts
|
|
40
|
+
function safeStorage(kind) {
|
|
41
|
+
return {
|
|
42
|
+
get(key) {
|
|
43
|
+
try {
|
|
44
|
+
return globalThis[kind]?.getItem(key) ?? null;
|
|
45
|
+
} catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
set(key, value) {
|
|
50
|
+
try {
|
|
51
|
+
globalThis[kind]?.setItem(key, value);
|
|
52
|
+
} catch {
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
remove(key) {
|
|
56
|
+
try {
|
|
57
|
+
globalThis[kind]?.removeItem(key);
|
|
58
|
+
} catch {
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
35
63
|
var AuthOwlNextSessionBridgeError = class extends Error {
|
|
36
64
|
status;
|
|
37
65
|
constructor(message, status) {
|
|
@@ -77,35 +105,53 @@ function createAuthOwlNextFetch(options) {
|
|
|
77
105
|
let memoryEnsured = false;
|
|
78
106
|
let currentSessionId = null;
|
|
79
107
|
let remember = false;
|
|
108
|
+
let pendingRemember;
|
|
109
|
+
const preferenceKey = `${storageKey}:session`;
|
|
110
|
+
const projectionStorage = safeStorage("sessionStorage");
|
|
111
|
+
const preferenceStorage = safeStorage("localStorage");
|
|
80
112
|
let bridgeUnavailable = false;
|
|
81
113
|
let sessionEnding = null;
|
|
82
|
-
const
|
|
83
|
-
try {
|
|
84
|
-
return globalThis.sessionStorage?.getItem(storageKey) === "1";
|
|
85
|
-
} catch {
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
const hasEnsuredProjection = () => memoryEnsured || storedEnsured();
|
|
114
|
+
const hasEnsuredProjection = () => memoryEnsured || projectionStorage.get(storageKey) === "1";
|
|
90
115
|
const markEnsured = () => {
|
|
91
116
|
memoryEnsured = true;
|
|
92
|
-
|
|
93
|
-
globalThis.sessionStorage?.setItem(storageKey, "1");
|
|
94
|
-
} catch {
|
|
95
|
-
}
|
|
117
|
+
projectionStorage.set(storageKey, "1");
|
|
96
118
|
};
|
|
97
119
|
const resetEnsured = () => {
|
|
98
120
|
memoryEnsured = false;
|
|
121
|
+
projectionStorage.remove(storageKey);
|
|
122
|
+
};
|
|
123
|
+
const storedPreference = () => {
|
|
99
124
|
try {
|
|
100
|
-
|
|
125
|
+
const value = JSON.parse(preferenceStorage.get(preferenceKey) ?? "null");
|
|
126
|
+
return isRecord(value) && typeof value.sessionId === "string" && typeof value.remember === "boolean" ? { sessionId: value.sessionId, remember: value.remember } : null;
|
|
101
127
|
} catch {
|
|
128
|
+
return null;
|
|
102
129
|
}
|
|
103
130
|
};
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
131
|
+
const savePreference = () => {
|
|
132
|
+
if (!currentSessionId) return;
|
|
133
|
+
preferenceStorage.set(preferenceKey, JSON.stringify({
|
|
134
|
+
sessionId: currentSessionId,
|
|
135
|
+
remember
|
|
136
|
+
}));
|
|
107
137
|
};
|
|
108
|
-
const
|
|
138
|
+
const selectSession = (sessionId) => {
|
|
139
|
+
if (currentSessionId === sessionId) return;
|
|
140
|
+
const stored = storedPreference();
|
|
141
|
+
if (currentSessionId !== null || stored && stored.sessionId !== sessionId) {
|
|
142
|
+
resetEnsured();
|
|
143
|
+
}
|
|
144
|
+
remember = pendingRemember ?? (stored?.sessionId === sessionId && stored.remember);
|
|
145
|
+
currentSessionId = sessionId;
|
|
146
|
+
pendingRemember = void 0;
|
|
147
|
+
};
|
|
148
|
+
const serialize = (work, failure) => {
|
|
149
|
+
const task = synchronization.then(work).catch(() => failure);
|
|
150
|
+
synchronization = task.then(() => void 0);
|
|
151
|
+
return task;
|
|
152
|
+
};
|
|
153
|
+
const postToBridge = (body, signal) => baseFetch(bridgePath, {
|
|
154
|
+
signal,
|
|
109
155
|
method: "POST",
|
|
110
156
|
headers: {
|
|
111
157
|
"content-type": "application/json",
|
|
@@ -116,9 +162,9 @@ function createAuthOwlNextFetch(options) {
|
|
|
116
162
|
redirect: "error",
|
|
117
163
|
body: JSON.stringify(body)
|
|
118
164
|
});
|
|
119
|
-
const clear = () => serialize(async () => {
|
|
120
|
-
await postToBridge({ token: null });
|
|
121
|
-
});
|
|
165
|
+
const clear = () => serialize(() => (0, import_core.withSessionRequestDeadline)(async (signal) => {
|
|
166
|
+
await postToBridge({ token: null }, signal);
|
|
167
|
+
}), void 0);
|
|
122
168
|
const beginClear = () => {
|
|
123
169
|
if (sessionEnding) return sessionEnding;
|
|
124
170
|
const task = clear().finally(() => {
|
|
@@ -127,43 +173,70 @@ function createAuthOwlNextFetch(options) {
|
|
|
127
173
|
sessionEnding = task;
|
|
128
174
|
return task;
|
|
129
175
|
};
|
|
130
|
-
const ensure = (
|
|
131
|
-
if (
|
|
176
|
+
const ensure = () => serialize(() => (0, import_core.withSessionRequestDeadline)(async (signal) => {
|
|
177
|
+
if (hasEnsuredProjection()) return true;
|
|
178
|
+
if (bridgeUnavailable) return false;
|
|
132
179
|
const authenticatedFetch = connection?.authenticatedFetch;
|
|
133
|
-
if (!authenticatedFetch) return;
|
|
180
|
+
if (!authenticatedFetch) return false;
|
|
181
|
+
if (currentSessionId === null) {
|
|
182
|
+
const sessionResponse = await authenticatedFetch(`${target.projectBaseURL}/get-session`, {
|
|
183
|
+
signal,
|
|
184
|
+
headers: { "x-publishable-key": target.publishableKey },
|
|
185
|
+
credentials: "include",
|
|
186
|
+
cache: "no-store",
|
|
187
|
+
redirect: "error"
|
|
188
|
+
});
|
|
189
|
+
if (!sessionResponse.ok) return false;
|
|
190
|
+
const data = await sessionResponse.json();
|
|
191
|
+
signal.throwIfAborted();
|
|
192
|
+
if (typeof data?.session?.id !== "string") return false;
|
|
193
|
+
selectSession(data.session.id);
|
|
194
|
+
}
|
|
195
|
+
const remembered = remember;
|
|
134
196
|
const minted = await authenticatedFetch(mintUrl, {
|
|
197
|
+
signal,
|
|
135
198
|
method: "POST",
|
|
136
199
|
headers: { "x-publishable-key": target.publishableKey },
|
|
137
200
|
credentials: "include",
|
|
138
201
|
cache: "no-store",
|
|
139
202
|
redirect: "error"
|
|
140
203
|
});
|
|
204
|
+
signal.throwIfAborted();
|
|
141
205
|
if (minted.status === 404) {
|
|
142
206
|
bridgeUnavailable = true;
|
|
143
|
-
return;
|
|
207
|
+
return false;
|
|
144
208
|
}
|
|
145
|
-
if (!minted.ok) return;
|
|
209
|
+
if (!minted.ok) return false;
|
|
146
210
|
const payload = await minted.json();
|
|
211
|
+
signal.throwIfAborted();
|
|
147
212
|
if (typeof payload.code !== "string" || payload.code.length > APP_SESSION_BRIDGE_CODE_MAX_LENGTH) {
|
|
148
|
-
return;
|
|
213
|
+
return false;
|
|
149
214
|
}
|
|
150
|
-
const bridged = await postToBridge({ code: payload.code, remember: remembered });
|
|
215
|
+
const bridged = await postToBridge({ code: payload.code, remember: remembered }, signal);
|
|
216
|
+
signal.throwIfAborted();
|
|
151
217
|
if (bridged.ok) {
|
|
152
218
|
markEnsured();
|
|
153
|
-
|
|
219
|
+
savePreference();
|
|
220
|
+
return true;
|
|
154
221
|
}
|
|
155
|
-
|
|
222
|
+
const error = await bridgeError(bridged);
|
|
223
|
+
signal.throwIfAborted();
|
|
224
|
+
if (error === "bridge_misconfigured") {
|
|
156
225
|
bridgeUnavailable = true;
|
|
157
226
|
}
|
|
158
|
-
|
|
227
|
+
return false;
|
|
228
|
+
}), false);
|
|
159
229
|
const onLifecycle = (event) => {
|
|
160
230
|
if (event.type === "beginSession") {
|
|
161
|
-
|
|
231
|
+
pendingRemember = event.remember;
|
|
162
232
|
currentSessionId = null;
|
|
163
233
|
resetEnsured();
|
|
164
234
|
return;
|
|
165
235
|
}
|
|
166
236
|
currentSessionId = null;
|
|
237
|
+
pendingRemember = void 0;
|
|
238
|
+
remember = false;
|
|
239
|
+
preferenceStorage.remove(preferenceKey);
|
|
167
240
|
resetEnsured();
|
|
168
241
|
void beginClear();
|
|
169
242
|
};
|
|
@@ -174,19 +247,18 @@ function createAuthOwlNextFetch(options) {
|
|
|
174
247
|
if (!sessionId) {
|
|
175
248
|
const projected = currentSessionId !== null || hasEnsuredProjection();
|
|
176
249
|
currentSessionId = null;
|
|
250
|
+
if (pendingRemember === void 0) {
|
|
251
|
+
remember = false;
|
|
252
|
+
preferenceStorage.remove(preferenceKey);
|
|
253
|
+
}
|
|
177
254
|
if (projected) {
|
|
178
255
|
resetEnsured();
|
|
179
256
|
void clear();
|
|
180
257
|
}
|
|
181
258
|
return;
|
|
182
259
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
if (currentSessionId !== sessionId) {
|
|
187
|
-
currentSessionId = sessionId;
|
|
188
|
-
}
|
|
189
|
-
void ensure(remember);
|
|
260
|
+
selectSession(sessionId);
|
|
261
|
+
void ensure();
|
|
190
262
|
};
|
|
191
263
|
const integration = {
|
|
192
264
|
connect(next) {
|
|
@@ -198,7 +270,7 @@ function createAuthOwlNextFetch(options) {
|
|
|
198
270
|
synchronizeSession();
|
|
199
271
|
},
|
|
200
272
|
sessionEstablished() {
|
|
201
|
-
return ensure(
|
|
273
|
+
return ensure();
|
|
202
274
|
},
|
|
203
275
|
sessionEnded() {
|
|
204
276
|
return beginClear();
|
package/dist/client.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import {
|
|
3
|
+
isRecord
|
|
4
|
+
} from "./chunk-QM64DWOE.js";
|
|
2
5
|
import {
|
|
3
6
|
APP_SESSION_BRIDGE_CODE_MAX_LENGTH,
|
|
4
7
|
APP_SESSION_BRIDGE_HEADER
|
|
@@ -7,8 +10,32 @@ import {
|
|
|
7
10
|
// src/client.ts
|
|
8
11
|
import {
|
|
9
12
|
resolveAuthTarget,
|
|
13
|
+
withSessionRequestDeadline,
|
|
10
14
|
withSessionTransportIntegration
|
|
11
15
|
} from "@authowl/core";
|
|
16
|
+
function safeStorage(kind) {
|
|
17
|
+
return {
|
|
18
|
+
get(key) {
|
|
19
|
+
try {
|
|
20
|
+
return globalThis[kind]?.getItem(key) ?? null;
|
|
21
|
+
} catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
set(key, value) {
|
|
26
|
+
try {
|
|
27
|
+
globalThis[kind]?.setItem(key, value);
|
|
28
|
+
} catch {
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
remove(key) {
|
|
32
|
+
try {
|
|
33
|
+
globalThis[kind]?.removeItem(key);
|
|
34
|
+
} catch {
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
12
39
|
var AuthOwlNextSessionBridgeError = class extends Error {
|
|
13
40
|
status;
|
|
14
41
|
constructor(message, status) {
|
|
@@ -54,35 +81,53 @@ function createAuthOwlNextFetch(options) {
|
|
|
54
81
|
let memoryEnsured = false;
|
|
55
82
|
let currentSessionId = null;
|
|
56
83
|
let remember = false;
|
|
84
|
+
let pendingRemember;
|
|
85
|
+
const preferenceKey = `${storageKey}:session`;
|
|
86
|
+
const projectionStorage = safeStorage("sessionStorage");
|
|
87
|
+
const preferenceStorage = safeStorage("localStorage");
|
|
57
88
|
let bridgeUnavailable = false;
|
|
58
89
|
let sessionEnding = null;
|
|
59
|
-
const
|
|
60
|
-
try {
|
|
61
|
-
return globalThis.sessionStorage?.getItem(storageKey) === "1";
|
|
62
|
-
} catch {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
const hasEnsuredProjection = () => memoryEnsured || storedEnsured();
|
|
90
|
+
const hasEnsuredProjection = () => memoryEnsured || projectionStorage.get(storageKey) === "1";
|
|
67
91
|
const markEnsured = () => {
|
|
68
92
|
memoryEnsured = true;
|
|
69
|
-
|
|
70
|
-
globalThis.sessionStorage?.setItem(storageKey, "1");
|
|
71
|
-
} catch {
|
|
72
|
-
}
|
|
93
|
+
projectionStorage.set(storageKey, "1");
|
|
73
94
|
};
|
|
74
95
|
const resetEnsured = () => {
|
|
75
96
|
memoryEnsured = false;
|
|
97
|
+
projectionStorage.remove(storageKey);
|
|
98
|
+
};
|
|
99
|
+
const storedPreference = () => {
|
|
76
100
|
try {
|
|
77
|
-
|
|
101
|
+
const value = JSON.parse(preferenceStorage.get(preferenceKey) ?? "null");
|
|
102
|
+
return isRecord(value) && typeof value.sessionId === "string" && typeof value.remember === "boolean" ? { sessionId: value.sessionId, remember: value.remember } : null;
|
|
78
103
|
} catch {
|
|
104
|
+
return null;
|
|
79
105
|
}
|
|
80
106
|
};
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
107
|
+
const savePreference = () => {
|
|
108
|
+
if (!currentSessionId) return;
|
|
109
|
+
preferenceStorage.set(preferenceKey, JSON.stringify({
|
|
110
|
+
sessionId: currentSessionId,
|
|
111
|
+
remember
|
|
112
|
+
}));
|
|
84
113
|
};
|
|
85
|
-
const
|
|
114
|
+
const selectSession = (sessionId) => {
|
|
115
|
+
if (currentSessionId === sessionId) return;
|
|
116
|
+
const stored = storedPreference();
|
|
117
|
+
if (currentSessionId !== null || stored && stored.sessionId !== sessionId) {
|
|
118
|
+
resetEnsured();
|
|
119
|
+
}
|
|
120
|
+
remember = pendingRemember ?? (stored?.sessionId === sessionId && stored.remember);
|
|
121
|
+
currentSessionId = sessionId;
|
|
122
|
+
pendingRemember = void 0;
|
|
123
|
+
};
|
|
124
|
+
const serialize = (work, failure) => {
|
|
125
|
+
const task = synchronization.then(work).catch(() => failure);
|
|
126
|
+
synchronization = task.then(() => void 0);
|
|
127
|
+
return task;
|
|
128
|
+
};
|
|
129
|
+
const postToBridge = (body, signal) => baseFetch(bridgePath, {
|
|
130
|
+
signal,
|
|
86
131
|
method: "POST",
|
|
87
132
|
headers: {
|
|
88
133
|
"content-type": "application/json",
|
|
@@ -93,9 +138,9 @@ function createAuthOwlNextFetch(options) {
|
|
|
93
138
|
redirect: "error",
|
|
94
139
|
body: JSON.stringify(body)
|
|
95
140
|
});
|
|
96
|
-
const clear = () => serialize(async () => {
|
|
97
|
-
await postToBridge({ token: null });
|
|
98
|
-
});
|
|
141
|
+
const clear = () => serialize(() => withSessionRequestDeadline(async (signal) => {
|
|
142
|
+
await postToBridge({ token: null }, signal);
|
|
143
|
+
}), void 0);
|
|
99
144
|
const beginClear = () => {
|
|
100
145
|
if (sessionEnding) return sessionEnding;
|
|
101
146
|
const task = clear().finally(() => {
|
|
@@ -104,43 +149,70 @@ function createAuthOwlNextFetch(options) {
|
|
|
104
149
|
sessionEnding = task;
|
|
105
150
|
return task;
|
|
106
151
|
};
|
|
107
|
-
const ensure = (
|
|
108
|
-
if (
|
|
152
|
+
const ensure = () => serialize(() => withSessionRequestDeadline(async (signal) => {
|
|
153
|
+
if (hasEnsuredProjection()) return true;
|
|
154
|
+
if (bridgeUnavailable) return false;
|
|
109
155
|
const authenticatedFetch = connection?.authenticatedFetch;
|
|
110
|
-
if (!authenticatedFetch) return;
|
|
156
|
+
if (!authenticatedFetch) return false;
|
|
157
|
+
if (currentSessionId === null) {
|
|
158
|
+
const sessionResponse = await authenticatedFetch(`${target.projectBaseURL}/get-session`, {
|
|
159
|
+
signal,
|
|
160
|
+
headers: { "x-publishable-key": target.publishableKey },
|
|
161
|
+
credentials: "include",
|
|
162
|
+
cache: "no-store",
|
|
163
|
+
redirect: "error"
|
|
164
|
+
});
|
|
165
|
+
if (!sessionResponse.ok) return false;
|
|
166
|
+
const data = await sessionResponse.json();
|
|
167
|
+
signal.throwIfAborted();
|
|
168
|
+
if (typeof data?.session?.id !== "string") return false;
|
|
169
|
+
selectSession(data.session.id);
|
|
170
|
+
}
|
|
171
|
+
const remembered = remember;
|
|
111
172
|
const minted = await authenticatedFetch(mintUrl, {
|
|
173
|
+
signal,
|
|
112
174
|
method: "POST",
|
|
113
175
|
headers: { "x-publishable-key": target.publishableKey },
|
|
114
176
|
credentials: "include",
|
|
115
177
|
cache: "no-store",
|
|
116
178
|
redirect: "error"
|
|
117
179
|
});
|
|
180
|
+
signal.throwIfAborted();
|
|
118
181
|
if (minted.status === 404) {
|
|
119
182
|
bridgeUnavailable = true;
|
|
120
|
-
return;
|
|
183
|
+
return false;
|
|
121
184
|
}
|
|
122
|
-
if (!minted.ok) return;
|
|
185
|
+
if (!minted.ok) return false;
|
|
123
186
|
const payload = await minted.json();
|
|
187
|
+
signal.throwIfAborted();
|
|
124
188
|
if (typeof payload.code !== "string" || payload.code.length > APP_SESSION_BRIDGE_CODE_MAX_LENGTH) {
|
|
125
|
-
return;
|
|
189
|
+
return false;
|
|
126
190
|
}
|
|
127
|
-
const bridged = await postToBridge({ code: payload.code, remember: remembered });
|
|
191
|
+
const bridged = await postToBridge({ code: payload.code, remember: remembered }, signal);
|
|
192
|
+
signal.throwIfAborted();
|
|
128
193
|
if (bridged.ok) {
|
|
129
194
|
markEnsured();
|
|
130
|
-
|
|
195
|
+
savePreference();
|
|
196
|
+
return true;
|
|
131
197
|
}
|
|
132
|
-
|
|
198
|
+
const error = await bridgeError(bridged);
|
|
199
|
+
signal.throwIfAborted();
|
|
200
|
+
if (error === "bridge_misconfigured") {
|
|
133
201
|
bridgeUnavailable = true;
|
|
134
202
|
}
|
|
135
|
-
|
|
203
|
+
return false;
|
|
204
|
+
}), false);
|
|
136
205
|
const onLifecycle = (event) => {
|
|
137
206
|
if (event.type === "beginSession") {
|
|
138
|
-
|
|
207
|
+
pendingRemember = event.remember;
|
|
139
208
|
currentSessionId = null;
|
|
140
209
|
resetEnsured();
|
|
141
210
|
return;
|
|
142
211
|
}
|
|
143
212
|
currentSessionId = null;
|
|
213
|
+
pendingRemember = void 0;
|
|
214
|
+
remember = false;
|
|
215
|
+
preferenceStorage.remove(preferenceKey);
|
|
144
216
|
resetEnsured();
|
|
145
217
|
void beginClear();
|
|
146
218
|
};
|
|
@@ -151,19 +223,18 @@ function createAuthOwlNextFetch(options) {
|
|
|
151
223
|
if (!sessionId) {
|
|
152
224
|
const projected = currentSessionId !== null || hasEnsuredProjection();
|
|
153
225
|
currentSessionId = null;
|
|
226
|
+
if (pendingRemember === void 0) {
|
|
227
|
+
remember = false;
|
|
228
|
+
preferenceStorage.remove(preferenceKey);
|
|
229
|
+
}
|
|
154
230
|
if (projected) {
|
|
155
231
|
resetEnsured();
|
|
156
232
|
void clear();
|
|
157
233
|
}
|
|
158
234
|
return;
|
|
159
235
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
if (currentSessionId !== sessionId) {
|
|
164
|
-
currentSessionId = sessionId;
|
|
165
|
-
}
|
|
166
|
-
void ensure(remember);
|
|
236
|
+
selectSession(sessionId);
|
|
237
|
+
void ensure();
|
|
167
238
|
};
|
|
168
239
|
const integration = {
|
|
169
240
|
connect(next) {
|
|
@@ -175,7 +246,7 @@ function createAuthOwlNextFetch(options) {
|
|
|
175
246
|
synchronizeSession();
|
|
176
247
|
},
|
|
177
248
|
sessionEstablished() {
|
|
178
|
-
return ensure(
|
|
249
|
+
return ensure();
|
|
179
250
|
},
|
|
180
251
|
sessionEnded() {
|
|
181
252
|
return beginClear();
|
package/dist/server.cjs
CHANGED
|
@@ -95,6 +95,11 @@ function resolveAuthConfig(config) {
|
|
|
95
95
|
return serverConfig(config);
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
+
// src/is-record.ts
|
|
99
|
+
function isRecord(value) {
|
|
100
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
101
|
+
}
|
|
102
|
+
|
|
98
103
|
// src/session-bridge.ts
|
|
99
104
|
var MAX_BODY_BYTES = 16384;
|
|
100
105
|
var AUTH_FETCH_TIMEOUT_MS = 1e4;
|
|
@@ -230,7 +235,11 @@ function createAuthOwlSessionBridge(input) {
|
|
|
230
235
|
if (raw.length > MAX_BODY_BYTES) return response(413, { error: "payload_too_large" });
|
|
231
236
|
let body;
|
|
232
237
|
try {
|
|
233
|
-
|
|
238
|
+
const parsed = JSON.parse(raw);
|
|
239
|
+
if (!isRecord(parsed)) {
|
|
240
|
+
return response(400, { error: "invalid_request" });
|
|
241
|
+
}
|
|
242
|
+
body = parsed;
|
|
234
243
|
} catch {
|
|
235
244
|
return response(400, { error: "invalid_request" });
|
|
236
245
|
}
|
package/dist/server.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isRecord
|
|
3
|
+
} from "./chunk-QM64DWOE.js";
|
|
1
4
|
import {
|
|
2
5
|
APP_SESSION_BRIDGE_CODE_MAX_LENGTH,
|
|
3
6
|
APP_SESSION_BRIDGE_HEADER,
|
|
@@ -191,7 +194,11 @@ function createAuthOwlSessionBridge(input) {
|
|
|
191
194
|
if (raw.length > MAX_BODY_BYTES) return response(413, { error: "payload_too_large" });
|
|
192
195
|
let body;
|
|
193
196
|
try {
|
|
194
|
-
|
|
197
|
+
const parsed = JSON.parse(raw);
|
|
198
|
+
if (!isRecord(parsed)) {
|
|
199
|
+
return response(400, { error: "invalid_request" });
|
|
200
|
+
}
|
|
201
|
+
body = parsed;
|
|
195
202
|
} catch {
|
|
196
203
|
return response(400, { error: "invalid_request" });
|
|
197
204
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@authowl/next",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.7",
|
|
4
4
|
"description": "Next.js (App Router) server helpers for AuthOwl, the multi-tenant auth SaaS.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"LICENSE"
|
|
62
62
|
],
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@authowl/core": "0.
|
|
64
|
+
"@authowl/core": "0.27.0"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
67
|
"next": ">=14"
|