The console logs indicate true, yet contradicts with a false assertion in the if statement

I am facing an issue with this code

router.get("/timecard", ensureAuthenticated, async(req, res)=>{
    users = await User.find();
    console.log(req.user.cwlEmployee);
    if(req.user.cwlEmployee !== true){
        req.flash('error_msg', 'You do not have access to that page, sorry.');
        res.render('dashboard', {
            name: req.user.name
        })
    }else{
        res.render('ep/timecard', {
            name: req.user.name,
            users: users
        });
}});

Although the console.log() outputs true, the if statement below is behaving as if req.user.cwlEmployee is false.

I am puzzled by this behavior. This code snippet has always worked fine in other parts of my application.

Answer №1

It is possible that the variable req.user.cwlEmployee exists, but it may not be a boolean data type with the value of true.

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

Display the returned view following an AJAX request

Currently, I am trying to search for a specific date in the database using ajax to trigger the function. However, I am encountering a 404 error when I should be receiving the desired outcome, and the ajax call is entering an error mode. Here is the snippet ...

reasons why the keypress event may not be triggered

Hello there, I am trying to create a function that simulates pressing the 'tab' key. The function is supposed to restrict input within specific ranges and return the cursor to another range once the limit is reached. Additionally, if a user input ...

Changes in props do not automatically update children via Ref

I'm working on a React component that needs to update whenever the width changes: import { useRef, useEffect, useState } from "react"; function Child({ containerWidth }) { console.log("CHILD", containerWidth); return <div&g ...

AWS Application load balancer is displaying a 502 error message

Exploring AWS has been my current focus, and I have managed to set up a single EC2 instance running a nodejs server on port 3000. Additionally, there is an Application load balancer configured with SSL listening on ports 80 and 443 for both http and http ...

What is the best way to configure redux-sagas and organize file hierarchy?

After learning how to install JWT and apply it to my React Native project, I realized that without proper state management, I had to pass the JWT token fetched from the login authentication as props down multiple levels, which became quite cumbersome. This ...

Accessing form objects in Typescript with AngularJS

I am currently working with AngularJS and Typescript. I have encountered an issue while trying to access the form object. Here is the HTML snippet: <form name="myForm" novalidate> <label>First Name</label> <input type="text" ...

Looking to retrieve the value of an input element within an ng-select in Angular 6?

Currently, I am working on a project where I aim to develop a customized feature in ng-select. This feature will enable the text entered in ng-select to be appended to the binding item and included as part of the multiselect function. If you want to see a ...

Explore search results that include values nested within map arrays

I have an array with multiple objects, each containing a nested array of subValues. My goal is to filter components based on search criteria. While I can successfully search the parent level objects' values, I am struggling with filtering based on the ...

Contrasting VSCode Live Server and Node Live Server

Recently delving into the world of JS, I've come across the need to set up a live server using npm. One popular extension in VSCode known as Live Server by Ritwick Dey caught my attention. I'm curious about the distinctions between utilizing this ...

Leverage regular expressions to extract numbers preceding the final matched instance

Within my string of logs, I have the following: rgb(255, 255, 255) 0px 0px 0px 16px inset I am interested in extracting the dynamic value, which in this case is 16. How can I create a regex pattern that will capture the last instance of px, and then retr ...

Update the directory path for Angular ui-bootstrap templates

Currently, I am attempting to utilize ui-bootstrap.min.js in conjunction with external templates. An issue has arisen where the error message reads as follows: http://localhost:13132/Place/template/timepicker/timepicker.html 404 (Not Found) I desire fo ...

Matching multiline input with RegExp and grouping matches from consecutive lines

Imagine having a text file with the following content: AAAA k1="123" k2="456" several lines of other stuff AAAA k1="789" k2="101" AAAA k1="121" k2="141" The objective is to extract the values of k1 and k2 while keeping them grouped together. For instance ...

Tips for effectively sorting data in the 'model' using StrongLoopIf you want assistance in filtering data in the

I'm currently attempting to connect table ABC with XYZ, and filter the data from the linked table 'xyz' using the Strongloop framework. Here is my code: return ABC.find({filter:{ where: {abcPropertyName: {neq: '1 ...

Steps to successfully retrieve an image using JavaScript on the client side while circumventing any CORS errors

I have a React application where I am displaying an image (an SVG) and I want the user to be able to download it by clicking on a button. The image is stored in Firebase Storage. However, I am encountering an issue with CORS error: Access to fetch at &ap ...

Unable to deactivate button using JavaScript following an AJAX request

Within my JS file, I am attempting to disable a button after making an AJAX call: $('document').ready(function() { const runField = $('input[id=run]') const runButton = $('.btn-run') const saveButton = $('.btn-save ...

Exploring the Dynamics of AngularJS: Leveraging ng-repeat and ng-show

Recently, I came across this code snippet: <div class="map" ng-controller="DealerMarkerListCtrl"> <a ng-click="showdetails=!showdetails" href="#/dealer/{{marker.id}}" class="marker" style="left:{{marker.left}}px;top:{{marker.top}}px" ng-rep ...

Trigger page load upon closing a popup window by utilizing the "beforeunload" event

I'm attempting to assign an event handler to beforeunload using JavaScript. This is the code I am currently using: $(window).on("beforeunload", function() { $("#popupin1").load("new.html"); }) I receive the alert, but the loading div does not a ...

jQuery animation that smoothly fades out from the left and fades in from the right

This survey is designed to assist individuals in determining where they should go with a specific type of ticket. Currently, everything is functioning smoothly, but I would like to add a sleek animation to each ul transition. Whenever a button is clicked ...

Is it possible to execute "green arrow" unit tests directly with Mocha in IntelliJ IDEA, even when Karma and Mocha are both installed?

My unit tests are set up using Karma and Mocha. The reason I use Karma is because some of the functionality being tested requires a web browser, even if it's just a fake headless one. However, most of my code can be run in either a browser or Node.js. ...

Ways to retrieve the mapState property within a method

Is there a way to access the count property within the method while working with vuex? Take a look at my code provided below: Screenshot of Code: https://i.stack.imgur.com/xNUHM.png Error Message [Vue warn]: Computed property "count" was assigned to bu ...