Skip to content

Commit 2a5cb63

Browse files
Add user info middleware (#1002)
* Add user info middleware * Update src/utils/route-handlers-middleware/middlewares/user-info.ts Co-authored-by: Adhitya Mamallan <adi1998is@gmail.com> --------- Co-authored-by: Adhitya Mamallan <adi1998is@gmail.com>
1 parent 54865ba commit 2a5cb63

File tree

8 files changed

+24
-8
lines changed

8 files changed

+24
-8
lines changed

src/route-handlers/reset-workflow/reset-workflow.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export async function resetWorkflow(
3838
decisionFinishEventId: data.decisionFinishEventId,
3939
requestId: data.requestId,
4040
skipSignalReapply: data.skipSignalReapply,
41-
// TODO: add user identity
4241
});
4342

4443
return NextResponse.json(response);

src/route-handlers/restart-workflow/restart-workflow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export async function restartWorkflow(
3636
runId: decodedParams.runId,
3737
},
3838
reason: data.reason,
39-
// TODO: add user identity
39+
identity: ctx.userInfo?.id,
4040
});
4141

4242
return NextResponse.json(response);

src/route-handlers/signal-workflow/signal-workflow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export async function signalWorkflow(
3939
signalInput: data.signalInput
4040
? { data: Buffer.from(data.signalInput) }
4141
: undefined,
42-
// TODO: add user identity
42+
identity: ctx.userInfo?.id,
4343
});
4444

4545
return NextResponse.json(response);

src/route-handlers/signal-workflow/signal-workflow.types.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { type z } from 'zod';
22

3-
import { type GRPCClusterMethods } from '@/utils/grpc/grpc-client';
3+
import { type DefaultMiddlewaresContext } from '@/utils/route-handlers-middleware';
44

55
import type signalWorkflowRequestBodySchema from './schemas/signal-workflow-request-body-schema';
66

@@ -17,6 +17,4 @@ export type SignalWorkflowRequestBody = z.infer<
1717
typeof signalWorkflowRequestBodySchema
1818
>;
1919

20-
export type Context = {
21-
grpcClusterMethods: GRPCClusterMethods;
22-
};
20+
export type Context = DefaultMiddlewaresContext;

src/route-handlers/terminate-workflow/terminate-workflow.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export async function terminateWorkflow(
4040
runId: decodedParams.runId,
4141
},
4242
reason: data.reason,
43+
identity: ctx.userInfo?.id,
4344
});
4445

4546
return NextResponse.json({} satisfies TerminateWorkflowResponse);
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { type GRPCClusterMethods } from '@/utils/grpc/grpc-client';
22

33
import grpcClusterMethodsMiddleware from '../middlewares/grpc-cluster-methods';
4+
import userInfoMiddleware from '../middlewares/user-info';
5+
import { type UserInfoMiddlewareContext } from '../middlewares/user-info.types';
46
import { type MiddlewareFunction } from '../route-handlers-middleware.types';
57

68
const routeHandlersDefaultMiddlewares: [
79
MiddlewareFunction<['grpcClusterMethods', GRPCClusterMethods]>,
8-
] = [grpcClusterMethodsMiddleware];
10+
MiddlewareFunction<['userInfo', UserInfoMiddlewareContext]>,
11+
] = [grpcClusterMethodsMiddleware, userInfoMiddleware];
912

1013
export default routeHandlersDefaultMiddlewares;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { type MiddlewareFunction } from '../route-handlers-middleware.types';
2+
3+
import { type UserInfoMiddlewareContext } from './user-info.types';
4+
5+
const userInfo: MiddlewareFunction<
6+
['userInfo', UserInfoMiddlewareContext]
7+
> = async () => {
8+
// Placeholder for user info middleware, to be implemented after integrating auth
9+
return ['userInfo', null];
10+
};
11+
12+
export default userInfo;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export type UserInfoMiddlewareContext = {
2+
id: string;
3+
} | null;

0 commit comments

Comments
 (0)