Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

Commit 7611b68

Browse files
committed
chore(core): reorder param inputs (#1164)
1 parent 881a01e commit 7611b68

File tree

15 files changed

+46
-72
lines changed

15 files changed

+46
-72
lines changed

examples/better-auth-external-db/src/backend/registry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ interface Message {
1616

1717
export const chatRoom = actor({
1818
// onAuth runs on the server & before connecting to the actor
19-
onAuth: async (c: OnAuthOptions) => {
19+
onAuth: async (opts: OnAuthOptions) => {
2020
// Access Better Auth session
2121
const authResult = await auth.api.getSession({
22-
headers: c.request.headers,
22+
headers: opts.request.headers,
2323
});
2424
if (!authResult) throw new Unauthorized();
2525

examples/tenant/README.md

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -70,29 +70,6 @@ This tenant system demonstrates:
7070
- **Dashboard Stats**: Access to basic member statistics only
7171
- **No Invoice Access**: Cannot view or manage billing information
7272

73-
## Security Features
74-
75-
### Authentication
76-
```typescript
77-
// Token-based authentication
78-
createConnState: async (c, { params }) => {
79-
const token = params.token;
80-
const { userId, role } = await authenticate(token);
81-
return { userId, role };
82-
}
83-
```
84-
85-
### Authorization
86-
```typescript
87-
// Server-side permission checks
88-
getInvoices: (c) => {
89-
if (c.conn.role !== "admin") {
90-
throw new UserError("Permission denied: Admin role required");
91-
}
92-
return c.state.invoices;
93-
}
94-
```
95-
9673
### Data Isolation
9774
- Organization-scoped data using actor keys
9875
- User context stored in connection state
@@ -217,4 +194,4 @@ To test the role-based access control:
217194

218195
## License
219196

220-
Apache 2.0
197+
Apache 2.0

internal-docs/CONFIG_TYPES.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@
44

55
- All types must be included in `ActorTypes` so the user can hardcode types
66

7-
- If using input parameters for inferring types, they must be raw parameters. e.g.:
7+
- If using input parameters for inferring types, they must be raw parameters. They also must be the last parameter. e.g.:
88

99
```typescript
10-
// It's hard for users to infer TConnParams
10+
// DO NOT DO THIS:
11+
// It's hard for users to infer TConnParams because they would have to import & use an extra type
1112
onAuth: (opts: OnAuthOpts<TConnParams>) => TAuthData,
12-
// Because you would have to import & use an extra type
13-
onAuth: (opts: OnAuthOpts<MyConnParam>) => TAuthData,
13+
14+
// DO NOT DO THIS:
15+
// If you only want to access `opts`, you'll have to also define `params`
16+
onAuth: (params: TConnParams, opts: OnAuthOpts) => TAuthData,
17+
18+
// DO THIS:
19+
// This allows you to not accept `params` and only access `opts`
20+
onAuth: (opts: OnAuthOpts, params: TConnParams) => TAuthData,
1421
```
1522

1623
- When inferring via return data, you must use a union. e.g.:

packages/core/fixtures/driver-test-suite/auth.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { actor, UserError } from "@rivetkit/core";
33
// Basic auth actor - requires API key
44
export const authActor = actor({
55
state: { requests: 0 },
6-
onAuth: (params) => {
7-
const apiKey = (params as any)?.apiKey;
6+
onAuth: (opts, params: { apiKey?: string } | undefined) => {
7+
const apiKey = params?.apiKey;
88
if (!apiKey) {
99
throw new UserError("API key required", { code: "missing_auth" });
1010
}
@@ -27,9 +27,9 @@ export const authActor = actor({
2727
// Intent-specific auth actor - checks different permissions for different intents
2828
export const intentAuthActor = actor({
2929
state: { value: 0 },
30-
onAuth: (params, { request, intents }) => {
30+
onAuth: ({ request, intents }, params: { role: string }) => {
3131
console.log("intents", intents, params);
32-
const role = (params as any)?.role;
32+
const role = params.role;
3333

3434
if (intents.has("create") && role !== "admin") {
3535
throw new UserError("Admin role required for create operations", {
@@ -80,8 +80,8 @@ export const noAuthActor = actor({
8080
// Async auth actor - tests promise-based authentication
8181
export const asyncAuthActor = actor({
8282
state: { count: 0 },
83-
onAuth: async (params) => {
84-
const token = (params as any)?.token;
83+
onAuth: async (opts, params: { token?: string } | undefined) => {
84+
const token = params?.token;
8585
if (!token) {
8686
throw new UserError("Token required", { code: "missing_token" });
8787
}

packages/core/fixtures/driver-test-suite/conn-params.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { actor } from "@rivetkit/core";
33
export const counterWithParams = actor({
44
onAuth: () => {},
55
state: { count: 0, initializers: [] as string[] },
6-
createConnState: (c, { params }: { params: { name?: string } }) => {
6+
createConnState: (c, opts, params: { name?: string }) => {
77
return {
8-
name: params?.name || "anonymous",
8+
name: params.name || "anonymous",
99
};
1010
},
1111
onConnect: (c, conn) => {

packages/core/fixtures/driver-test-suite/conn-state.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export const connStateActor = actor({
1616
// Define connection state
1717
createConnState: (
1818
c,
19-
{ params }: { params?: { username?: string; role?: string } },
19+
opts,
20+
params: { username?: string; role?: string },
2021
): ConnState => {
2122
return {
2223
username: params?.username || "anonymous",

packages/core/fixtures/driver-test-suite/lifecycle.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ export const counterWithLifecycle = actor({
88
count: 0,
99
events: [] as string[],
1010
},
11-
createConnState: (c, params: ConnParams) => ({
11+
createConnState: (c, opts, params: ConnParams) => ({
1212
joinTime: Date.now(),
1313
}),
1414
onStart: (c) => {
1515
c.state.events.push("onStart");
1616
},
17-
onBeforeConnect: (c, params) => {
17+
onBeforeConnect: (c, opts, params: ConnParams) => {
1818
if (params?.trackLifecycle) c.state.events.push("onBeforeConnect");
1919
},
2020
onConnect: (c, conn) => {

packages/core/fixtures/driver-test-suite/raw-http-auth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ export const rawHttpAuthActor = actor({
55
state: {
66
requestCount: 0,
77
},
8-
onAuth: (params) => {
9-
const apiKey = (params as any)?.apiKey;
8+
onAuth: (opts, params: { apiKey?: string }) => {
9+
const apiKey = params.apiKey;
1010
if (!apiKey) {
1111
throw new UserError("API key required", { code: "missing_auth" });
1212
}

packages/core/fixtures/driver-test-suite/raw-websocket-auth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export const rawWebSocketAuthActor = actor({
1111
connectionCount: 0,
1212
messageCount: 0,
1313
},
14-
onAuth: (params) => {
15-
const apiKey = (params as any)?.apiKey;
14+
onAuth: (opts, params: { apiKey?: string }) => {
15+
const apiKey = params.apiKey;
1616
if (!apiKey) {
1717
throw new UserError("API key required", { code: "missing_auth" });
1818
}

packages/core/fixtures/driver-test-suite/request-access-auth.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,7 @@ import { actor } from "@rivetkit/core";
55
* onAuth runs on the HTTP server, not in the actor, so we test it separately
66
*/
77
export const requestAccessAuthActor = actor({
8-
onAuth: ({
9-
request,
10-
intents,
11-
params,
12-
}: {
13-
request: Request;
14-
intents: Set<string>;
15-
params?: { trackRequest?: boolean };
16-
}) => {
8+
onAuth: ({ request, intents }, params: { trackRequest?: boolean }) => {
179
if (params?.trackRequest) {
1810
// Extract request info and return it as auth data
1911
const headers: Record<string, string> = {};

0 commit comments

Comments
 (0)