MCPcopy Create free account
hub / github.com/GoogleChrome/webstatus.dev / CheckAuthenticatedUser

Function CheckAuthenticatedUser

backend/pkg/httpserver/middlewares.go:36–62  ·  view source on GitHub ↗

CheckAuthenticatedUser retrieves the authenticated user from the context. If the user is not found, it returns an error response.

(
	ctx context.Context,
	operation string,
	newErrorResponse func(code int, message string) T)

Source from the content-addressed store, hash-verified

34// CheckAuthenticatedUser retrieves the authenticated user from the context.
35// If the user is not found, it returns an error response.
36func CheckAuthenticatedUser[T any](
37 ctx context.Context,
38 operation string,
39 newErrorResponse func(code int, message string) T) UserCheckResult[T] {
40 // At this point, the user should be authenticated and in the context.
41 // If for some reason the user is not in the context, it is a library or
42 // internal issue and not an user issue. Return 500 error in that case.
43 user, found := httpmiddlewares.AuthenticatedUserFromContext(ctx)
44 if !found {
45 slog.ErrorContext(ctx, "user not found in context. middleware failure", "operation", operation)
46
47 return UserCheckResult[T]{
48 User: nil,
49 Response: newErrorResponse(
50 http.StatusInternalServerError,
51 errMsgInternalServerError,
52 ),
53 }
54 }
55
56 var zeroT T
57
58 return UserCheckResult[T]{
59 User: user,
60 Response: zeroT,
61 }
62}
63
64// applyPreRequestValidationMiddlewares applies a list of middleware functions to a given http.Handler.
65// The middlewares are applied in reverse order to ensure they execute in the order they are defined.

Callers 12

DeleteSubscriptionMethod · 0.85
RemoveSavedSearchMethod · 0.85
PingUserMethod · 0.85
ListSubscriptionsMethod · 0.85
UpdateSubscriptionMethod · 0.85
CreateSubscriptionMethod · 0.85
GetSubscriptionMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected