@aiveth/nextjs 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/README.md +1 -0
- package/dist/handlers.js +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/oidc.d.ts +4 -2
- package/dist/oidc.js +6 -3
- package/dist/server.d.ts +4 -0
- package/dist/server.js +15 -0
- package/dist/session.d.ts +12 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.6.0 — 2026-11-26
|
|
4
|
+
|
|
5
|
+
- `/auth/login?workspace=…` signs the person in to a workspace; `switchWorkspace(ref)` (Server Actions, Route Handlers) switches it with the refresh token. `User` carries the workspace claims.
|
|
6
|
+
|
|
3
7
|
## 0.5.0 — 2026-11-26
|
|
4
8
|
|
|
5
9
|
- `audience` / env `AIVETH_API_AUDIENCE`: your own API's address. `getAccessToken()` then gives a signed token for that API, which it checks with `verifyAccessToken` (`@aiveth/node`).
|
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@ AIVETH_CLIENT_ID=okc_...
|
|
|
16
16
|
AIVETH_CLIENT_SECRET=oks_...
|
|
17
17
|
AIVETH_COOKIE_SECRET=$(openssl rand -base64 32) # at least 32 characters
|
|
18
18
|
AIVETH_APP_URL=https://your-app.com
|
|
19
|
+
# /auth/login?workspace=acme signs in to a workspace; switchWorkspace(ref) switches it
|
|
19
20
|
# AIVETH_API_AUDIENCE=https://api.your-app.com # optional: a signed token for your own API (Developers → Your APIs)
|
|
20
21
|
```
|
|
21
22
|
|
package/dist/handlers.js
CHANGED
|
@@ -23,6 +23,7 @@ export async function login(req, c) {
|
|
|
23
23
|
const to = await authorizeUrl(c, {
|
|
24
24
|
state: tx.state, nonce: tx.nonce, challenge: await challengeOf(tx.verifier),
|
|
25
25
|
loginHint: req.nextUrl.searchParams.get('login_hint') ?? undefined,
|
|
26
|
+
workspace: req.nextUrl.searchParams.get('workspace') ?? undefined,
|
|
26
27
|
});
|
|
27
28
|
return write(NextResponse.redirect(to), [txCookie(await seal(tx, c.cookieSecret, TX_SECONDS), secureFor(c))]);
|
|
28
29
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { aivethProxy, REFRESH_BEFORE_SECONDS, type AivethProxyOptions, type Protect } from './proxy.js';
|
|
2
|
-
export { getAccessToken, getSession, getUser, requireUser } from './server.js';
|
|
2
|
+
export { getAccessToken, getSession, getUser, requireUser, switchWorkspace } from './server.js';
|
|
3
3
|
export { configureAiveth, ROUTES, type AivethNextConfig } from './config.js';
|
|
4
4
|
export { AivethAuthError } from './oidc.js';
|
|
5
5
|
export type { Session, User } from './session.js';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { aivethProxy, REFRESH_BEFORE_SECONDS } from './proxy.js';
|
|
2
|
-
export { getAccessToken, getSession, getUser, requireUser } from './server.js';
|
|
2
|
+
export { getAccessToken, getSession, getUser, requireUser, switchWorkspace } from './server.js';
|
|
3
3
|
export { configureAiveth, ROUTES } from './config.js';
|
|
4
4
|
export { AivethAuthError } from './oidc.js';
|
package/dist/oidc.d.ts
CHANGED
|
@@ -28,12 +28,14 @@ export declare function authorizeUrl(c: AivethNextConfig, a: {
|
|
|
28
28
|
nonce: string;
|
|
29
29
|
challenge: string;
|
|
30
30
|
loginHint?: string;
|
|
31
|
+
workspace?: string;
|
|
31
32
|
}): Promise<string>;
|
|
32
33
|
/** The ID token's claims: signed by Aiveth, for this app, live — and, on sign-in, this nonce. */
|
|
33
34
|
export declare function verifyIdToken(c: AivethNextConfig, idToken: string, nonce?: string): Promise<User>;
|
|
34
35
|
export declare function sessionFrom(t: TokenAnswer, user: User, idToken: string, createdAt?: number): Session;
|
|
35
36
|
export declare function exchangeCode(c: AivethNextConfig, code: string, verifier: string, nonce: string): Promise<Session>;
|
|
36
|
-
/** A new access token (and, as Aiveth turns them, a new refresh token).
|
|
37
|
-
|
|
37
|
+
/** A new access token (and, as Aiveth turns them, a new refresh token). ``workspace``: switch the
|
|
38
|
+
* active workspace (id or slug) — the person must be a member. */
|
|
39
|
+
export declare function refreshSession(c: AivethNextConfig, s: Session, workspace?: string): Promise<Session>;
|
|
38
40
|
export declare function logoutUrl(c: AivethNextConfig, idToken: string | undefined): Promise<string>;
|
|
39
41
|
export {};
|
package/dist/oidc.js
CHANGED
|
@@ -54,6 +54,8 @@ export async function authorizeUrl(c, a) {
|
|
|
54
54
|
});
|
|
55
55
|
if (a.loginHint)
|
|
56
56
|
q.set('login_hint', a.loginHint);
|
|
57
|
+
if (a.workspace)
|
|
58
|
+
q.set('workspace', a.workspace); // signed in to that workspace (a member's only)
|
|
57
59
|
if (c.audience)
|
|
58
60
|
q.set('resource', c.audience); // RFC 8707: a signed access token for that API
|
|
59
61
|
return `${d.authorization_endpoint}?${q}`;
|
|
@@ -114,11 +116,12 @@ export async function exchangeCode(c, code, verifier, nonce) {
|
|
|
114
116
|
throw new AivethAuthError('Aiveth sent no ID token: the scope needs openid.');
|
|
115
117
|
return sessionFrom(t, await verifyIdToken(c, t.id_token, nonce), t.id_token);
|
|
116
118
|
}
|
|
117
|
-
/** A new access token (and, as Aiveth turns them, a new refresh token).
|
|
118
|
-
|
|
119
|
+
/** A new access token (and, as Aiveth turns them, a new refresh token). ``workspace``: switch the
|
|
120
|
+
* active workspace (id or slug) — the person must be a member. */
|
|
121
|
+
export async function refreshSession(c, s, workspace) {
|
|
119
122
|
if (!s.refreshToken)
|
|
120
123
|
throw new AivethAuthError('No refresh token: ask for offline_access.');
|
|
121
|
-
const t = await token(c, { grant_type: 'refresh_token', refresh_token: s.refreshToken });
|
|
124
|
+
const t = await token(c, { grant_type: 'refresh_token', refresh_token: s.refreshToken, ...(workspace ? { workspace } : {}) });
|
|
122
125
|
const idToken = t.id_token ?? s.idToken;
|
|
123
126
|
const user = t.id_token ? await verifyIdToken(c, t.id_token) : s.user;
|
|
124
127
|
return { ...sessionFrom(t, user, idToken, s.createdAt), refreshToken: t.refresh_token ?? s.refreshToken };
|
package/dist/server.d.ts
CHANGED
|
@@ -7,3 +7,7 @@ export declare function requireUser(returnTo?: string): Promise<User>;
|
|
|
7
7
|
* ends; the new session is written where Next lets a cookie be written (Route Handlers, Server
|
|
8
8
|
* Actions) — in a Server Component it is used for this render, and the proxy writes it next time. */
|
|
9
9
|
export declare function getAccessToken(): Promise<string | null>;
|
|
10
|
+
/** Switch the active workspace (id or slug) — in a Server Action or a Route Handler, where the
|
|
11
|
+
* session cookie can be written. The person must be a member; the new ID and access tokens name
|
|
12
|
+
* that workspace from now on (WorkOS's switch: a refresh with the workspace). Needs offline_access. */
|
|
13
|
+
export declare function switchWorkspace(workspace: string): Promise<Session>;
|
package/dist/server.js
CHANGED
|
@@ -42,3 +42,18 @@ export async function getAccessToken() {
|
|
|
42
42
|
}
|
|
43
43
|
return session.accessToken;
|
|
44
44
|
}
|
|
45
|
+
/** Switch the active workspace (id or slug) — in a Server Action or a Route Handler, where the
|
|
46
|
+
* session cookie can be written. The person must be a member; the new ID and access tokens name
|
|
47
|
+
* that workspace from now on (WorkOS's switch: a refresh with the workspace). Needs offline_access. */
|
|
48
|
+
export async function switchWorkspace(workspace) {
|
|
49
|
+
const c = config();
|
|
50
|
+
const jar = await cookies();
|
|
51
|
+
const session = await readSession(jar, c.cookieSecret);
|
|
52
|
+
if (!session)
|
|
53
|
+
throw new Error('Nobody is signed in.');
|
|
54
|
+
const next = await refreshSession(c, session, workspace);
|
|
55
|
+
for (const { name, value, options } of await sessionCookies(next, c.cookieSecret, secureFor(c), jar)) {
|
|
56
|
+
jar.set(name, value, options);
|
|
57
|
+
}
|
|
58
|
+
return next;
|
|
59
|
+
}
|
package/dist/session.d.ts
CHANGED
|
@@ -10,6 +10,18 @@ export interface User {
|
|
|
10
10
|
role?: string;
|
|
11
11
|
permissions?: string[];
|
|
12
12
|
feature_flags?: string[];
|
|
13
|
+
/** The active workspace (`/auth/login?workspace=…`, or `switchWorkspace`). */
|
|
14
|
+
workspace_id?: string;
|
|
15
|
+
workspace_slug?: string;
|
|
16
|
+
workspace_role?: string;
|
|
17
|
+
workspace_permissions?: string[];
|
|
18
|
+
/** With the `workspaces` scope: every workspace the person is in, for your switcher. */
|
|
19
|
+
workspaces?: {
|
|
20
|
+
id: string;
|
|
21
|
+
slug: string;
|
|
22
|
+
name: string;
|
|
23
|
+
role: string;
|
|
24
|
+
}[];
|
|
13
25
|
[claim: string]: unknown;
|
|
14
26
|
}
|
|
15
27
|
export interface Session {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiveth/nextjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Aiveth by Gooclaim for Next.js: sign in on Aiveth's page, an encrypted session cookie, the user on the server and in the browser.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Gooclaim",
|