MCPcopy Create free account
hub / github.com/loopbackio/loopback-next / handle

Method handle

examples/passport-login/src/sequence.ts:46–96  ·  view source on GitHub ↗
(context: RequestContext)

Source from the content-addressed store, hash-verified

44 ) {}
45
46 async handle(context: RequestContext) {
47 try {
48 const {request, response} = context;
49 const finished = await this.invokeMiddleware(context);
50 if (finished) return;
51
52 const route = this.findRoute(request);
53
54 // usually authentication is done before proceeding to parse params
55 // but in our case we need the path params to know the provider name
56 const args = await this.parseParams(request, route);
57
58 // if provider name is available in the request path params, set it in the query
59 if (route.pathParams?.provider) {
60 request.query['oauth2-provider-name'] = route.pathParams.provider;
61 }
62
63 //call authentication action
64 await this.authenticateRequest(request);
65
66 // Authentication successful, proceed to invoke controller
67 const result = await this.invoke(route, args);
68 this.send(response, result);
69 } catch (error) {
70 /**
71 * Authentication errors for login page are handled by the express app
72 */
73 if (
74 context.request.path === '/login' &&
75 (error.status === 401 || error.name === 'UnauthorizedError')
76 ) {
77 /**
78 * The express app that routed the /signup call to LB App, will handle the error event.
79 */
80 context.response.emit(
81 'UnauthorizedError',
82 'User Authentication Failed',
83 );
84 return;
85 }
86
87 if (
88 error.code === AUTHENTICATION_STRATEGY_NOT_FOUND ||
89 error.code === USER_PROFILE_NOT_FOUND
90 ) {
91 Object.assign(error, {statusCode: 401 /* Unauthorized */});
92 }
93 this.reject(context, error);
94 return;
95 }
96 }
97}

Callers

nothing calls this directly

Calls 3

parseParamsMethod · 0.80
rejectMethod · 0.80
findRouteMethod · 0.45

Tested by

no test coverage detected