Is the delete functionality in the $resource not performing as anticipated?

After creating a basic Angular application that consumes an API made with Laravel, I have encountered an issue. The login process sets a token in a cookie, but the success method is not triggering after sending a DELETE request to log out.

The system has only one user with these credentials:

Email: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="402b2c202726082b2c202726666b2725">[email protected]</a>
Password: admin12345

In the 'app.js' file, the code for setting the active status, authentication, and logout functions can be found. Despite the logic being correct, there seems to be a syntax error or some other issue causing the success method to fail on logout.

Note: The application is currently functioning better on Firefox rather than Chrome. Any insights into this would be appreciated.

For anyone interested in checking the repositories, they are public:

AngulAir Application:

AngulAirAPI:

Answer №1

Below is the solution provided:

$scope.logout = function () {
    //var auth_token = $cookieStore.get('auth_token');
    Auth.delete(
    {'auth_token': $cookieStore.get('auth_token')}, // parameters
    {},//postData, which you don't need for this
    function(data){
      $scope.isLoggedIn = false;
      $cookieStore.remove('auth_token');
    },
    // error callback
    function (httpResponse) {
       // Implement your own error handling logic here
    }
  );  
  };

Note:-> (The following points addressed the issue)

  1. The second option (postdata) in $resource.delete API was missing. It should be provided as a blank {} when not required.
  2. The delete method must return a 204 Status Code to trigger the success callback.

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

Dynamically loading JSON language files in AngularJS

Just starting out with angular and feeling a bit lost... I want to be able to load different JSON files for data based on the language selected (e.g. json/Agenda-nl.json). Currently, I have separate controller and HTML files for each language. Is there a ...

Where should we place the JavaScript reference in our CSHTML file in an MVC framework?

At the beginning of our .cshtml page in our current web application, we have included the following: @using Carwale.UI.PresentationLogic; @model Carwale.Entity.ViewModels.HomeModel @{ ViewBag.CustomJS = "~/Views/StaticPartials/HomeScripts.cshtml"; ...

Navigate to an external website and then seamlessly transition back to my own web content

Here is an example of a URL I utilize to send SMS through an external platform: However, redirecting the user to this URL does not bring them back to my website. I do have code in place for executing/pages to show the message being sent. Is there a way t ...

Change the appearance of a bootstrap dropdown menu button when clicked on, whether it's the button itself or anywhere on the

Looking at this bootstrap dropdown example, I am trying to change the button's background color to blue only when the dropdown menu is expanded. Although I managed to achieve this by adding a click listener to the button, a problem arises when the use ...

Learn how to hide elements on print pages conditionally in Vue.js using CSS or JavaScript

I am currently using the Vue framework to work on printing webpages for my application. I have an issue that needs a solution, which I will explain below. <template> <div id = "intro" style = "text-align:center;"> <div ...

Having trouble with implementing sparklines in the AngularJS version of the SmartAdmin template

I recently initiated an angularjs seed project using the SmarrAdmin template. One feature I would like to implement is a sparkline in a view, similar to the example below: <div class="sparkline" data-sparkline-type="bar" data-sparkline-width="50px" ...

Using JavaScript to show content in a textarea field

In my index.jsp file, I have implemented the following code to populate two textareas, INPUT_TEXT and INPUT_TEXT2, with processed data. This involves passing the text through a servlet, a Java class, and finally displaying the preprocessed results in the s ...

Tips for displaying unformatted text using HTML

Is there a way to display a string in HTML with all of its escape sequences preserved? For example: eipt No. : 1995,\nmount 935\nAdm. : 17/06/2016 INSTRUCTIONS : 1) This card is valid only for the student's name & for the period indic ...

Variables in an Angular application are not appearing in the HTML rendering

Currently learning AngularJS as I develop a web application. After going through tutorials, I started with a basic list but am baffled as to why my browser only shows {{title}}. In my app.js module, here's the snippet where I defined the controller: ...

Exploring the world of unit testing for Sails JS 1.0 helper functions

Currently, I am in the process of setting up unit testing for my SailsJS 1.0 application. My goal is to simulate the DB without needing to execute 'sails lift' to run tests. In my application, there is a straightforward actions2 (node machine) h ...

jwplayer - track viewing time - monetize by the minute - trigger action based on duration

My goal is to track the time duration that someone watches a video, ideally by triggering an action every minute. I'm aiming to create a pay-per-minute system where a credit is withdrawn from the user for each minute they watch. If this setup isn&apo ...

Error message: Failure to define class methods when exporting the class from a file

In my project, I have defined a class called BinarySearchTree in a file named a.js. This class has been exported and then imported into another file where it is used as the parent class for a different class called Traversal. However, I encountered an issu ...

Sending a PDF document to a function that specifically calls for a file location or URL

Currently, I am developing a web application for an online library where I need to extract metadata from PDF files that are uploaded. To achieve this, I am utilizing the nodejs libraries pdf.js-extract and multer-gridfs-storage for file uploads. However, I ...

Strategies for Managing Output Event Prioritization in Angular Using RxJs Based on Trigger Sequence

Within my Angular Application, there is a widget with two event outputs originating from a third-party library. Unfortunately, I am unable to modify its behavior. <myWidget (onAlwaysEvent)="onAlwaysEvent($event)" (onSometimesEvent)="onSometimesEven ...

Creating a full-screen loading animation that appears when a button is clicked is a great way to enhance user experience. This animation can flow seamlessly from right to left before disappearing, providing a visually engaging transition for users as they

Despite anticipating more negative responses than positive ones, I believe that even one correct answer outweighs it all! So, I'm trying to figure out how to create a loading animation that covers the entire screen whenever a button on the navigation ...

What is the most effective way to showcase my JSON response in a table with Laravel?

I am currently attempting to implement a live search feature in Laravel using AJAX with one of my tables. While following a tutorial on YouTube, I managed to reach the 18-minute mark out of a 21-minute video. However, at this point, the live search functio ...

Begin the directive once the API has been completed

My dilemma lies in a directive whose data relies on the API response. The issue is that the $compile of the directive occurs before the API is fully processed, resulting in an incorrect state for the directive. Is there a way to address this problem? Is t ...

Is there an AngularJS directive specifically designed to capture only the scroll down event?

I received a directive for capturing scrolling events, but I am only interested in the scroll down event. .directive('whenScrolled', function() { return function(scope, elm, attr) { var raw = elm[0]; elm.bind('scroll&ap ...

javascript - Include new parameter in object literal and retrieve

I have a base object that I define using an object literal: var obj = { key1 : 'value1', key2 : 'value2' } Now, I want to pass this object to a function and extend it like this: myFunction( obj + { key3 : 'value3' ...

Displaying dynamic data in Django without the need for refreshing the page

I've created a Django application that performs traceroute on multiple Cisco devices simultaneously. Although everything is functioning properly, the output is currently only displayed after receiving results from all devices. I would like the output ...