MCPcopy
hub / github.com/cloudflare/vibesdk / authMiddleware

Function authMiddleware

worker/middleware/auth/auth.ts:32–54  ·  view source on GitHub ↗
(
    request: Request,
    env: Env
)

Source from the content-addressed store, hash-verified

30 * Authentication middleware
31 */
32export async function authMiddleware(
33 request: Request,
34 env: Env
35): Promise<AuthUserSession | null> {
36 try {
37 // Extract token
38 const token = extractToken(request);
39
40 if (token) {
41 const userResponse = await validateToken(token, env);
42 if (userResponse) {
43 logger.debug('User authenticated', { userId: userResponse.user.id });
44 return userResponse;
45 }
46 }
47
48 logger.debug('No authentication found');
49 return null;
50 } catch (error) {
51 logger.error('Auth middleware error', error);
52 return null;
53 }
54}

Callers 3

enforceAuthRequirementFunction · 0.90
getOptionalUserFunction · 0.90
checkAuthMethod · 0.90

Calls 4

extractTokenFunction · 0.90
validateTokenFunction · 0.85
debugMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected