MCPcopy Create free account
hub / github.com/CapSoftware/Cap / getAuth

Function getAuth

apps/web/app/api/utils.ts:70–88  ·  view source on GitHub ↗
(c: Context)

Source from the content-addressed store, hash-verified

68}
69
70async function getAuth(c: Context) {
71 const authHeader = c.req.header("authorization")?.split(" ")[1];
72
73 let user: Awaited<ReturnType<typeof getCurrentUser>> | undefined;
74
75 if (authHeader?.length === 36) {
76 const res = await db()
77 .select()
78 .from(users)
79 .leftJoin(authApiKeys, eq(users.id, authApiKeys.userId))
80 .where(eq(authApiKeys.id, authHeader));
81 user = res[0]?.users;
82 } else {
83 user = await getCurrentUser();
84 }
85
86 if (!user) return;
87 return { user };
88}
89
90export const withOptionalAuth = createMiddleware<{
91 Variables: {

Callers 1

utils.tsFile · 0.85

Calls 1

dbFunction · 0.90

Tested by

no test coverage detected