Inversify's Http Context consistently remains void of any content

Hello there, I'm in need of assistance with building an API using inversify and inversify-express-utils. Everything seems to be working fine with my controllers and the API so far, except for one issue. When trying to access the httpContext property in my controller that comes from the BaseHttpController inheritance, I find that the user details are not showing up because the httpContext property is empty. I have followed the official documentation on configuring a custom Authentication provider as explained here.

Here is my code snippet:

app.ts

import AuthInversifyProvider from './providers/auth-inversify.provider';

export default class Application {
  private readonly server: InversifyExpressServer;
  private readonly environment: Environment;
  private readonly rootPath = '/api/v1';

  constructor(container: Container, environment: Environment) {
    this.server = new InversifyExpressServer(container, null, {
      rootPath: this.rootPath,
    }, null, AuthInversifyProvider);
    this.environment = environment;
  }

  public initialize(): ExpressApp {
    // Code omitted for brevity
  }
}

auth-inversify.provider.ts

// Code omitted for brevity
// Refer to documentation for full implementation details
// Picture references available at the provided links

This image serves as a reference to show successful retrieval of current user information:

Link to view my controller setup:

Answer №1

Have you initialized your new Container with the Singleton option? If so, consider using the default option - transient instead of Singleton. I encountered a similar issue where my httpContext was empty.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What improvements can I make to enhance my method?

I have a block of code that I'm looking to clean up and streamline for better efficiency. My main goal is to remove the multiple return statements within the method. Any suggestions on how I might refactor this code? Are there any design patterns th ...

What is the solution to fixing the Vetur/Vuelidate issue where the error message "'validate' does not exist in type 'ComponentOptions<Vue [etc.]" is displayed?

QUERY: I'm facing an issue with error 'validations' does not exist in type 'ComponentOptions<Vue [etc.] when using Vetur with TypeScript installed in VSCode. How can I resolve this? CONTEXT: I integrated Vuelidate into a single-file ...

Retrieve a static property from a specific type

I've encountered a dilemma with the code snippet below: class Action { public static DEPENDENCIES: (typeof Action)[] = []; public static MIN_USES: number | null = null; public static MAX_USES: number | null = null; } class SomeAction ext ...

Unable to sign out user from the server side using Next.js and Supabase

Is there a way to log out a user on the server side using Supabase as the authentication provider? I initially thought that simply calling this function would work: export const getServerSideProps: GetServerSideProps = withPageAuth({ redirectTo: &apos ...

Older versions of javascript offered the assurance of a promise

Working with TypeScript and the latest ECMAScript 6 feature Promise at the moment. I'm wondering if it's possible to use Promise even if my TypeScript code is compiled into an ECMAScript 3 js-file, considering that Promise wasn't available i ...

What is the proper way to arrange dates within strings in Angular?

I'm currently facing an issue with sorting two strings. The strings in question are: "2022 | Dec (V2 2022)" "2022 | Jul (V1 2022)" Although I am attempting to sort them using localeCompare, it is not yielding the correct result. T ...

Ways to deactivate inversify's automatic detection of controllers

Looking to set up two servers within the same source tree - one with extensive functionality, and the other more specialized. Both servers share common classes and require sharing of some source code between them. The issue arises when inversify/Express a ...

The Influence of Getter Performance in Angular Templates

As I delve into an existing Angular application, I've noticed a pattern where values used in templates across many components are actually properties that are being accessed through getters and setters without any additional logic: <input type="nu ...

Invoking a function from a collection of mixed data types

I have established a mapping for a discriminated union consisting of different types, each linked to a corresponding function that uses a member of the union as a parameter: export interface Truncate { type: 'truncate' maxLength: number } ex ...

Permitting hyperlinks in Helmets Content Security Policy (CSP

Recently, I've been encountering problems with my CSP header in Helmet. No matter what changes I make, the links always seem to be broken or return an error. How can I go about fixing this issue? Below is my current code: app.use( helmet.conte ...

Having trouble getting Node.js, express, socket.io, and ejs to work together?

Currently, I am working on improving my knowledge of java-script and had the idea to create a basic chat app using Express, stock.io, and ejs. Unfortunately, I am facing some challenges in getting it up and running smoothly. Below is the snippet from my ...

Dynamic URL used in TRPC queries`

Is there a way to query a single post in TRPC and Next JS based on a dynamic url without using SSR or SSG? I have tried adding as string to router.query.id but encountered a TRPC error (only happening during the first load) because router.query.id is ini ...

Retrieving the selected date from mat-datepicker into a FormControl

When creating a POST request to an API, I encountered an issue with the mat-datepicker field as it throws an error when inside the ngOnInit() call (since nothing is selected yet). Other fields like name, email, etc. work fine, but extracting a value from t ...

Removing API request in React.js

My approach: deleteSample = () => { this.sampleService .deleteCall(this.props.id) .then((response) => { window.location.reload(false); }) .catch((error) => { console.log ...

How to Use ngFor to Create a Link for the Last Item in an Array in Angular 7

I need help with adding a link to the last item in my menu items array. Currently, the menu items are generated from a component, but I'm unsure how to make the last item in the array a clickable link. ActionMenuItem.component.html <div *ngIf= ...

Parsing error encountered while trying to handle an unexpected token at line 214, character 33. It appears that an appropriate loader is missing to process this particular file type

I've been developing a Typescript React project for the past few months without any issues. However, things took a turn yesterday when I decided to run npm audit fix and npm audit fix --force in order to address some security concerns that appeared ou ...

Heroku App push was unsuccessful due to compilation failure of the Node.js application

I made sure to include node_modules in .gitignore so that's not causing any issues! Does anyone have a solution for these errors? I've specified versions for both in the engines section. https://i.stack.imgur.com/tMDOd.png Here is the code : ...

Simple steps to transform the "inputs" syntax into the "@Input" property decorator

There's this code snippet that I need to modify: @Component({ selector: 'control-messages', inputs: ['controlName: control'], template: `<div *ngIf="errorMessage !== null">{{errorMessage}}</div>` }) Is the ...

Is there a specific side effect that warrants creating a new Subscription?

Recently, I had a discussion on Stack Overflow regarding RxJS and the best approach for handling subscriptions in a reactive application. The debate was whether it's better to create a subscription for each specific side effect or minimize subscriptio ...

"Obtaining a refresh token for the 'Sign In With Google' feature: A step-by-step guide

My access token keeps expiring in 1hr, so I've been attempting to generate a refresh token. window.onload = function () { google.accounts.id.initialize({ client_id: , callback: handleCredentialResponse, }); google.accounts.i ...