@voult/core 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/package.json +6 -1
- package/src/index.d.ts +3 -0
- package/src/index.js +2 -0
- package/src/oauth.js +13 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to `@voult/core` are documented here.
|
|
4
4
|
|
|
5
|
+
## 0.2.1
|
|
6
|
+
|
|
7
|
+
- New route `GET /session/renew?returnTo=/path`: renews the session from the refresh cookie, saves the new cookies and redirects back (or to `errorPath?voult_error=SESSION_EXPIRED`). For pages rendered where cookies can't be written, such as Next.js Server Components: renewing there would rotate the refresh token without saving it, and Voult's reuse detection would then end the session.
|
|
8
|
+
- New entry point `@voult/core/cookies` (signing and cookie parsing only, no `@voult/sdk`), for Edge middleware.
|
|
9
|
+
- `parseUserCookie` and `safeReturnTo` are exported.
|
|
10
|
+
|
|
5
11
|
## 0.2.0
|
|
6
12
|
|
|
7
13
|
The router now serves every end-user feature, so apps write no auth route handlers. New routes (below the mount path):
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voult/core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "The Voult auth router on the Fetch API (Request \u2192 Response), shared by @voult/express and @voult/next",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
"types": "./src/index.d.ts",
|
|
11
11
|
"import": "./src/index.js",
|
|
12
12
|
"default": "./src/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./cookies": {
|
|
15
|
+
"types": "./src/index.d.ts",
|
|
16
|
+
"import": "./src/cookies.js",
|
|
17
|
+
"default": "./src/cookies.js"
|
|
13
18
|
}
|
|
14
19
|
},
|
|
15
20
|
"sideEffects": false,
|
package/src/index.d.ts
CHANGED
|
@@ -88,6 +88,9 @@ export function restoreSession(
|
|
|
88
88
|
config: VoultConfig
|
|
89
89
|
): IncomingSession;
|
|
90
90
|
export function sessionCookies(client: VoultClient, incoming: IncomingSession, config: VoultConfig): CookieToSet[];
|
|
91
|
+
/** `value` when it's a same-site relative path (`/x`, not `//x` or `https://…`), else `fallback`. */
|
|
92
|
+
export function safeReturnTo(value: unknown, fallback: string): string;
|
|
93
|
+
export function parseUserCookie(value: unknown): Record<string, unknown> | null;
|
|
91
94
|
export function renewSession(client: VoultClient, read: ReadCookie, config: VoultConfig): Promise<CookieToSet[]>;
|
|
92
95
|
|
|
93
96
|
export function readCookieHeader(header: string | null | undefined, secret?: string): Promise<{
|
package/src/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
export { createVoultHandler } from './handler.js';
|
|
4
4
|
export { loadConfigFromEnv, resolveConfig } from './config.js';
|
|
5
5
|
export { normalizeVoultError } from './errors.js';
|
|
6
|
+
export { safeReturnTo } from './oauth.js';
|
|
6
7
|
export {
|
|
7
8
|
COOKIE_ACCESS,
|
|
8
9
|
COOKIE_MFA_PENDING,
|
|
@@ -11,6 +12,7 @@ export {
|
|
|
11
12
|
COOKIE_USER,
|
|
12
13
|
createVoultClient,
|
|
13
14
|
getSessionFromRequest,
|
|
15
|
+
parseUserCookie,
|
|
14
16
|
renewSession,
|
|
15
17
|
restoreSession,
|
|
16
18
|
sessionCookies,
|
package/src/oauth.js
CHANGED
|
@@ -100,6 +100,19 @@ export function oauthRoutes() {
|
|
|
100
100
|
let providersCache = { at: 0, value: null };
|
|
101
101
|
|
|
102
102
|
return [
|
|
103
|
+
// For pages rendered where cookies can't be written (Next.js Server Components): renewing
|
|
104
|
+
// there would rotate the refresh token without saving it. They send the browser here
|
|
105
|
+
// instead; this renews, saves the new cookies and goes back.
|
|
106
|
+
['GET', '/session/renew', async (ctx) => {
|
|
107
|
+
// The caller already knows the access token is stale (its cookie outlives the token).
|
|
108
|
+
ctx.client.accessToken = null;
|
|
109
|
+
await ctx.renew();
|
|
110
|
+
const back = safeReturnTo(ctx.query('returnTo'), ctx.config.oauth.successPath);
|
|
111
|
+
return ctx.client.accessToken
|
|
112
|
+
? redirect(appLocation(ctx.config, back))
|
|
113
|
+
: redirectWithError(ctx.config, 'SESSION_EXPIRED', 'Please sign in again.');
|
|
114
|
+
}],
|
|
115
|
+
|
|
103
116
|
['GET', '/oauth/providers', async (ctx) => {
|
|
104
117
|
if (!providersCache.value || Date.now() - providersCache.at > PROVIDERS_CACHE_MS) {
|
|
105
118
|
const info = await getAppInfo(ctx.client);
|