Issue encountered while retrieving JWT

Currently, I am tackling the challenge of implementing JWT authentication using Angular and Java Jersey. I have successfully managed to send the JWT token from the server to the client, which can be observed as a POST response with a status code of 200 in the Chrome console.

However, my hurdle lies in storing the token in a variable for decoding purposes. Whenever I attempt to save it, an error crops up:

TypeError: href is null
e/<()angular.min.js (line 107)
Ze/this.$get</<()angular.min.js (line 81)
f/<()angular.min.js (line 119)
lf/this.$get</r.prototype.$eval()angular.min.js (line 133)
lf/this.$get</r.prototype.$digest()angular.min.js (line 130)
lf/this.$get</r.prototype.$apply()angular.min.js (line 134)
g()angular.min.js (line 87)
T()angular.min.js (line 92)
Uf/</w.onload()angular.min.js (line 93)
stackFrame.js (line 357)
 <System>
error is:undefined

Take a look at the snippet of my code below:

myApp.controller('loginController', ['$scope', '$http', function ($scope, $http) {
$scope.email = "";
$scope.password = "";

$scope.loginForm = function () {
    var data = {email: $scope.email, password: $scope.password};
    var url = 'rs/loginResource';
        $http.post(url, data).success(function (response) {
            console.log("token is: " + response);
        }).error(function (error) {
            console.log("error is:" + error);
        });
};
}]);

Answer №1

How do you typically send tokens - in JSON format or as plain text?

In my recent experience with HAM stack authentication using JWT, I sent the token within an object structure like this: { token: 'asdasds.sdadad.asdad' }. When making server calls in Angular, I follow a similar pattern:

$http({
    method: 'POST',
    url: 'rs/loginResource',
    data: {
        email: $scope.email,
        password: $scope.password
    }
})
.then(function (resp) {
    var token = resp.data.token
})
.catch(function(error){
    return error;
});

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

Angular: Leveraging Nested Callbacks for Efficient HTTP Queries

I'm currently facing an issue with structured English. GET HTTP Resource FOR every data item received do GET another HTTP Resource Alter the original data from the outer loop with data from the inner GET RETURN altered data How can ...

How about rejuvenating a Div with some PHP magic inside?

My goal is to automatically update a div every x seconds by using the following code: The div only contains a small PHP timezone code. This is the code snippet I am implementing: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/ li ...

Is there a way to retrieve data from the host URL within the getStaticPaths function in Next.js?

In my Next.js application, there is a serverless function responsible for fetching data from the host. The host URL is configured in a .env file where it is set to http://localhost:3000/api/data during development and https://productionurl.com/api/data in ...

Filtering in AngularJS based on a specific ID

Currently, I am dealing with a JSON encoded response from PHP that looks like this... [ {"ID":"149","IDusr":"4","aut_more_info":"good","doc_name":"img1838142879.jpeg","doc_type":"jpg"},{"ID":"149","IDusr":"4","aut_more_info":"good","img5733250433.jpeg","d ...

Unpacking Objects in JavaScript and TypeScript: The Power of Destructuring

I have a variable called props. The type includes VariantTheme, VariantSize, VariantGradient, and React.DOMAttributes<HTMLOrSVGElement> Now I need to create another variable, let's name it htmlProps. I want to transfer the values from props to ...

Whenever I try to utilize the "ng-list" in JavaScript, I encounter issues accessing the variable model

HTML <input type="text" ng-list ng-model="OtherHobby" />{{OtherHobby}} <br /> {{AllHobbys}} Javascript $scope.OtherHobby = []; $scope.AllHobbys = $scope.OtherHobby; I ran a test on this piece of code. The variable "OtherHobby" w ...

A div element springs forth into a new window and seamlessly transitions back to its original position with fresh content

Most of us are familiar with Gmail chat, where you can pop out the chat window into a new window with its content, and then pop it back in to its original position. However, I encountered an issue while working on replicating this functionality. While I w ...

SCRIPT438: The operation failed because the object does not have the ability to use the 'forEach' property or method

Issue with IE8: Property or method 'forEach' not supported $('.tabs').tabs(); $('#search-consumables [data-ajax-call]').change(function() { var $this = $(this), settings = $this.data(), $target = $(setti ...

Issue with Index.js file due to incorrect syntax

'use strict'; var path = require('path'); var _ = require('lodash'); function ensureRequiredEnvVar(name) { if (!process.env[name]) { throw new Error('Please set the ' + name + ' environment variable'); } ...

streaming audio data from a MongoDB database to an HTML audio element

As part of my current project, I am delving into the realm of creating an audio player. The concept of database storage for files is relatively new to me, as my previous experience has mainly involved storing strings. Up to this point, here's what I ...

Leveraging $last in Angular for obtaining the final visible element with ng-show

My ng-repeat container div contains multiple images, each with a corresponding div next to it. Using $last, I can make sure only the div of the final image is visible after all images. However, I also have a filter button on the page that hides certain im ...

A method to use jQuery to replace newlines with commas in user input

Input Processing Challenge <input> Whenever there is multi-line text pasted into the input field, I need to replace newlines (\r, \n, and \r\n) as well as tabs \t with commas ,. This scenario mainly occurs when users copy c ...

changing the vertical position of an element using JavaScript

I'm currently working on a project where I have a canvas that animates upwards when a button is clicked. However, I'm facing an issue with making it go back down after the animation completes. It seems to be getting stuck and not returning to its ...

Obtain Relative URL with the help of Selenium using the PhantomJS driver

Utilizing Selenium along with the Phantom JS driver, I am attempting to load an HTML page and extract all of the HREF links from it. The issue arises when PhantomJS provides absolute URLs after resolving them entirely. My specific requirement is to extrac ...

Conditional jQuery actions based on the selected radio button - utilizing if/else statements

This task seemed simple at first, but I quickly realized it's more challenging than expected. Apologies in advance, as Javascript is not my strong suit. My goal is to have the main button (Get Your New Rate) perform different actions based on whether ...

Personalized payment fields: Revealing/concealing data using a selector

Following this successful solution: // Incorporating an external jQuery/JS file function cfields_scripts() { // IMPORTANT NOTE: // When using a child theme, replace get_template_directory_uri() with get_stylesheet_directory_uri() // Place th ...

Can someone explain to me the meaning of "var vm = $scope.vm = {}" in AngularJS?

While reading through the angularJS api, I came across some code that looked like this: myApp.controller('MyController', ['$scope', function($scope) { var vm = $scope.vm = {name:'savo'}; } ]); Initially, this mul ...

Exploring the use of jQuery/JS for parsing and working with JSON

Hi everyone, I need some assistance with displaying data from an array created by a PHP file using JS/jQuery. Currently, I am working on implementing a points system for ZetaBoards which you can check out here. The points will be shown below the user' ...

The ReactJS Ajax request returns a successful status code of 200 and retrieves the data, however, an error message

I have the following code snippet to fetch data from a backend API. When I paste the link into my browser's address bar, the API returns a result of '["2016-03-31T00:00:00"]'. However, when I use this AJAX call in my code, I receive a status ...

Navigating through the content of slots within recurring slots in a subcomponent in Vue.js

I am encountering an issue with a child component, where each row in an object is rendered inside a div with a specific slot. I need to pass data from the parent for each of these elements. I've been attempting to iterate through every element of the ...