Skip to content

Commit 93f79d7

Browse files
committed
rename getUser into authFunction
1 parent 5c6a768 commit 93f79d7

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

test/backend/middlewares/auth.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { User } from "@clerk/backend";
22
import type { Context } from "@worker/trpc/context";
3-
import { getUser } from "@worker/trpc/middlewares/auth";
3+
import { authFunction } from "@worker/trpc/middlewares/auth";
44
import { beforeEach, describe, expect, it, mock } from "bun:test";
55

66
// Mock the Clerk module
@@ -13,7 +13,7 @@ mock.module("@clerk/backend", () => ({
1313
createClerkClient: mockCreateClerkClient,
1414
}));
1515

16-
describe("getUser", () => {
16+
describe("authFunction", () => {
1717
let mockContext: Context;
1818

1919
beforeEach(() => {
@@ -51,7 +51,7 @@ describe("getUser", () => {
5151
mockGetUser.mockResolvedValue(mockUser);
5252

5353
// When
54-
const result = await getUser(mockContext);
54+
const result = await authFunction(mockContext);
5555

5656
// Then
5757
expect(result).toBe(mockUser);
@@ -77,7 +77,7 @@ describe("getUser", () => {
7777
mockToAuth.mockReturnValue(mockAuth);
7878

7979
// When & Then
80-
expect(getUser(mockContext)).rejects.toThrow("User is not authenticated");
80+
expect(authFunction(mockContext)).rejects.toThrow("User is not authenticated");
8181
expect(mockGetUser).not.toHaveBeenCalled();
8282
});
8383

@@ -87,7 +87,7 @@ describe("getUser", () => {
8787
mockAuthenticateRequest.mockRejectedValue(clerkError);
8888

8989
// When & Then
90-
expect(getUser(mockContext)).rejects.toThrow("Clerk API error");
90+
expect(authFunction(mockContext)).rejects.toThrow("Clerk API error");
9191
expect(mockGetUser).not.toHaveBeenCalled();
9292
});
9393
});

worker/trpc/middlewares/auth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ export type AuthenticatedContext = Context & { user: User };
77

88
export const authentication = t.middleware(async ({ next, ctx }) => {
99
try {
10-
const user = await getUser(ctx);
10+
const user = await authFunction(ctx);
1111
return next({ ctx: { ...ctx, user } });
1212
} catch (error) {
1313
console.error(error);
1414
throw new TRPCError({ message: "Unable to get auth", cause: error, code: "UNAUTHORIZED" });
1515
}
1616
});
1717

18-
export async function getUser(ctx: Context) {
18+
export async function authFunction(ctx: Context) {
1919
const clerk = createClerkClient({ secretKey: ctx.env.CLERK_SECRET_KEY, publishableKey: ctx.env.CLERK_PUBLISHABLE_KEY });
2020
const requestState = await clerk.authenticateRequest(ctx.req);
2121
const auth = requestState.toAuth();

0 commit comments

Comments
 (0)