NestJS authentication guard is malfunctioning

While implementing jwt with @nestjs/passport, I followed the instructions to use @UseGuards(AuthGuard()). However, I encountered the following exception:

common_1.Optional is not a function

Any ideas on what could be causing this issue?

Dependencies:

"@nestjs/common": "^5.0.0",

"@nestjs/core": "^5.0.0",
"@nestjs/cqrs": "^5.1.1",
"@nestjs/jwt": "^0.2.0",
"@nestjs/mongoose": "^5.1.0",
"@nestjs/passport": "^5.1.0",
"@nestjs/swagger": "^2.4.4",
"@nestjs/typeorm": "^5.2.2",
"automapper-ts": "^1.9.0",
"config": "^2.0.1",
"fastify-formbody": "^2.0.0",
"lodash": "^4.17.10",
"mongodb": "^3.1.6",
"mongoose": "^5.2.9",
"mysql": "^2.16.0",
"nestjs-rmq": "^0.1.3",
"nestjs-typegoose": "^5.0.1",
"passport": "^0.4.0",
"passport-jwt": "^4.0.0",
"reflect-metadata": "^0.1.12",
"rxjs": "^6.0.0",
"typegoose": "^5.4.0",
"typeorm": "^0.2.7",
"typescript": "^2.6.2",

Answer №1

Your dependencies are not up to date. You might want to consider executing the command npm update.

Answer №2

Maybe there is some confusion around the question, but when using a guard, you have the option to provide a guard instance or simply provide the class and let Nest create the instance for you. It's important to note that a guard is not a function.

@UseGuards(AuthGuard()) can be written as: @UseGuards(new AuthGuard()) or @UseGuards(AuthGuard)

Answer №4

issue with dependencies

solution to consider:

$ sudo npm install -g npm-check

$ npm-check -u

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

The issue with the custom ng-enter directive is that it fails to transmit the $event data from the

In my current setup, I have implemented a custom directive that detects when the user presses enter and then triggers the same function as ngSubmit in the surrounding form element. I am facing an issue where I need access to the event from within the cont ...

What is the most efficient way to extract dynamically generated JavaScript content from a webpage?

Currently, my method involves using selenium alongside PhantomJS to scrape dynamic content generated by JavaScript on a website. Although it provides me with the desired results, the process is quite slow as I have to wait for the entire page to load befor ...

Updating and eliminating text within an array of objects using Vue JS

My Axios request pulls in an array of objects named 'uniquecolors'. Here is what it looks like: mycolors color: [GREEN, RED, BLUE, YELLOW, ORANGE,ORANGE,GREEN,] color: [GREEN, RED, BLUE, YELLOW, ORANGE,ORANGE,GREEN,] color ...

Enhancing the functionality of an existing framework through the integration of a

My coding style involves a lot of ASP.NET MVC and jQuery, particularly with ajax calls that return json. Lately, I've been tinkering with organizing my code structure by creating an object within the global object which contains success and fail callb ...

struggling with the predictive text feature, need some assistance

Currently, I am utilizing the material-table library and I have made the decision to incorporate a feature similar to Google's "typeahead" functionality. Here is an example of what I am trying to achieve: https://i.sstatic.net/r6jCd.png In order to ...

What is the best way to bring data into the server.js file in Express.js?

Whenever I attempt to import in server.js like this: import SalaryService from '/components/utils/SalaryService'; and then try to use it as follows: const salaryService = new SalaryService(); res.send(salaryService.getSalaries('test' ...

Generating empty elements with ng-repeat in AngularJS

I am facing an issue with an array that has improper key order, such as: 1: Array[1] 2: Array[2] 4: Array[3] 7: Array[14] 21: Array[1] 22: Array[1] 23: Array[1] When I use ng-repeat to iterate through this array, it generates empty elements for key value ...

When functions are sent to children of a react component, they do not inherit the context of the parent

I'm facing an issue while working with React where I am encountering difficulty passing a function from a parent component to multiple children components. The function calls other functions that are also housed within the parent component. Although ...

The functionality of one button triggering the opening of two dropdown menus simultaneously is being successfully implemented

My issue is that I have created two different dropdowns, but they both open the same dropdown menu. Here is my code; <div class="d-flex"> <button class="btn btn-icon btn-group-nav shadow-sm btn-secondary dropdown-toggle" type="butto ...

Image not displayed when JavaScript adds <IMG SRC=

While I am dynamically adding rows to a table, each new table item's innerHTML is set as follows: picCell.innerHTML = '<label for="checkbox-a" data-form="ui-btn-up-a" class="'+uncheckedClassString+'" ...

Step-by-step guide to performing an AJAX request in JavaScript while using Ubuntu

My current setup involves using a JavaScript file in conjunction with NodeJS to execute AJAX calls. To accomplish this, I have installed and imported jQuery as demonstrated below: var http = require("http"); $ = require("jquery"); test(); funct ...

Leveraging JavaScript and Thymeleaf to manipulate a list

I am trying to access an object from a list in JavaScript, which is being passed from the controller. Currently, I am working with Thymeleaf and Spring Boot. The list is named ${collaborateurs}. The following code snippet is functional: <script th: ...

What is the best way to create spacing between fields in Material UI?

I just started using material UI and I'm trying to add spacing between my text fields. I've tried adding the spacing but it doesn't seem to be working. Can someone help me figure out how to add space in between textfields? Below is the code ...

unable to import angular js script into ejs template

Having trouble including a JavaScript file in my EJS page while using the Express.js framework. //Below is the code for my index.ejs page <!DOCTYPE html> <html> <head> <script type='text/javascript' src= "order.js">&l ...

Tips for Setting a Value in Apex Using Javascript

I recently implemented the following code snippet. Here is a snippet of my Visualforce page code: <Script> //Window Load document.getElementById("Today_Date").value = "2014-02-02"; </Script> <input type="date" value="{!myDate}" id ...

Issue with Bootstrap datepicker functionality within a modal

I've searched extensively on Google and Stack Overflow for a similar question, but so far haven't been successful. The issue I'm facing is when I create and open a modal from jQuery and try to access a date picker, the datepicker's Java ...

Can you explain the distinction between document.body.ononline and navigator.onLine?

Can you explain the distinction between document.body.ononline and navigator.onLine? Do they utilize the same JavaScript API for checking network connectivity status (online/offline)? I have searched on Google but couldn't find a definitive answer. If ...

Add the element to a fresh collection of objects using an associative array

Can you help me figure out what's causing an issue when attempting to add a new element to an associative array of objects? var storeData3 = [ { 'key1' : 'value1' }, { 'key2' : 'value2' }, { 'key3&ap ...

ExpressJS: Elevating Bread to New Heights

I've been struggling with adding a toast using expressjs. I attempted to use the npm package "toastr" but encountered an error stating that $.extend is not a function. In an attempt to resolve this, I replaced it with Object.assign but still couldn&ap ...

No text appearing on iOS simulator when typing

I recently started learning React-Native and decided to follow a tutorial to create a login screen. I encountered an issue where the code in the tutorial was outdated. I am working on a login screen that consists of multiple components. However, one specif ...