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

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