Access granted to endpoint

I decided to implement a custom decorator for authentication across all controllers in my nest application. Here's the code snippet:

export function AuthRequired(exposeOptions?: ExposeOptions): (arg0: Controller, arg1: string, arg3: TypedPropertyDescriptor<unknown>) => void {
  const exposeFn = Expose(exposeOptions);
  const apiBearerAuthFn = ApiBearerAuth();
  const guardFn = UseGuards(AuthGuard())

  return function (target: Controller, key: string, descriptor: TypedPropertyDescriptor<unknown>): void {
    apiBearerAuthFn(target, key, descriptor);
    guardFn(target, key, descriptor);
    exposeFn(target, key);
  }
}

Unfortunately, after implementing this decorator, I noticed that all endpoints have unrestricted access. The Swagger interface appears like this: https://i.sstatic.net/R4z4v.png

The padlock icon indicating secured access is missing.

I'm seeking help to identify what might be causing this issue. Below is the complete code of my AuthService, AuthModule, AppModule, and AppController with the implemented AuthRequired decorator.

Any guidance on resolving this would be greatly appreciated!

Answer №1

The guide states that you need to include a security definition in your DocumentBuilder. Make sure to include the following code snippet:

const options = new DocumentBuilder()
    .setTitle('My Title')
    .setDescription('Description here')
    .setVersion('1.0')
    .addServer('/api', 'Main server - current/local')
    .addBearerAuth() // <-- don't forget this
    .build();

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

Tips for Identifying Connection Type using JavaScript

My browser is not receiving the current connection type when using the following function. I don't think there is an issue with getting the value in ScriptNotify, as other functions are working fine with this method. It appears that navigator.connecti ...

Transitionend event fails to trigger when Chrome tab is not in focus

$("#element").addClass("myclass").on('webkitAnimationEnd oanimationend msAnimationEnd animationend', function (e) { $("#element").addClass('text-success'); $("#element2").addClass('myclass2'); setTimeout(function () { ...

Using NODEJS to send a POST request body to a web page

My current setup involves a NodeJs server and an External Application. I am trying to achieve the functionality where I can receive a POST request from the External Application and then visualize the body of that request on a web page. Successfully, I am ...

Tips for resolving Circular dependency issue in node.js?

While working on a post request, I encountered an issue with the code below: try{ const _id = await db.collection('UserInformation').insertOne(userObj); await db.collection('LoggedInUser').updateOne({ userId: _id }, { '$set&ap ...

A guide to automatically playing audio on a webpage using HTML and JavaScript

I'm currently in the process of developing a quiz application, and my goal is to have a sound play when a user enters the webpage to initiate the quiz. Initially, I attempted to use JavaScript to trigger the sound on page load, but unfortunately, the ...

Debug messages are not displaying in ExpressJS

I'm currently working with ExpressJS and I want to show internal debug messages, similar to what's described here at https://expressjs.com/en/guide/debugging.html. When I attempt to run the following command in VS Code (Windows Powershell): "`se ...

Vue.js using the v-for directive with index

Just started using Vue.js and I have a question: I'm working with an array to create a table. When I double click on a table row, I want the program to execute a JavaScript function that will retrieve the selected item based on its index. <di ...

Tips for correctly implementing the next() function within a middleware in a Node.js application

After successfully logging in and generating a bearer token, I attempted to verify the token by organizing the codes for controllers, middlewares, and routes. However, upon verification, I encountered the following error message: Error: Route.post() requir ...

Debugging and ensuring the functionality of Cordova (Phonegap) HTTPS connections

There is an HTTPS site with an API that needs to be accessed. I need to work from Cordova (AngularJS) with its HTTPS API. Additionally, I want to debug the AngularJS app in a web browser (Chrome) because it's much quicker compared to rebuilding and ...

Altering the status of a property in an object, at a specific position within a collection of objects, contained within another object?

Currently using React and having some trouble with the setState hook to update a value deep within an object structure ...

"Php makes it easy to organize seating arrangements with drag-and-drop functionality

We are currently in the process of developing a website dedicated to bus services and booking tickets. Our main goal is to allow the administrator to easily create and modify seating arrangements through drag-and-drop functionality, including the ability t ...

How come the rotation of my Three.js mesh gets thrown off when I adjust the scale?

I managed to achieve my goal of rotating a sphere around the x and y axes using the following code: // Update ball rotation. var tempMat = new THREE.Matrix4(); tempMat.makeRotationAxis(new THREE.Vector3(0,1,0), stepX/ballRadius); tempMat.multiplySelf(ball ...

Set a variable to represent a color for the background styling in CSS

My goal is to create an application that allows users to change the background color of a button and then copy the CSS code with the new background color from the <style> tags. To achieve this, I am utilizing a color picker tool from . I believe I ...

Show child component and its content in parent component based on certain conditions

To show a child component (along with its ContentChildren) within the template of a parent component based on certain conditions. app.component.html <parent> <child #initial> <span>Player</span> </child> <child ...

Update the color of navigation items to reflect their active status

Here is the snippet of HTML code: <header> <nav> <a href="#" id="menu-icon"></a> <ul> <li><a href="#"">Home</a></li> <li><a href="#">About</a></li> & ...

Using ReactJS to trigger a timer function on a button click

Kindly Note: This is a unique query and not related to ReactJS - Need to click twice to set State and run function. The suggested solution there does not resolve my issue. This represents my original state: constructor(props) { super(props) this. ...

Navigating to the default landing page using basic authentication middleware in Express

I'm currently working on implementing basic authorization for an entire website using Express. The goal is to have users enter their credentials, and if correct, they will be directed to the standard landing page. If the credentials are incorrect, the ...

Using AJAX for uploading files upon a change event rather than upon submission

Below is the code I have been using to implement an iframe for ajax file upload without refreshing the page upon form submission. The current code works as expected. window.onload=init; function init() { document.getElementById('form').onsubmi ...

Create Office Script calculations with quotations included

I am currently attempting to create an Excel office script formula for a cell. Are there any tips on how to insert a formula with quotes into a cell? For example, the following works fine: wsWa.getCell(WaRangeRowCount, 9).setFormula("= 1 + 1"); ...

The jQuery autocomplete feature is malfunctioning, as it is unable to display any search

Creating a country list within an ajax call involves working with an array of objects: $.ajax({ url: '//maps.googleapis.com/maps/api/geocode/json?address=' + zipCode + '&region=AT', type: 'GET', dataType: &apo ...