I currently have a two-module AngularJS application. The first module is responsible for handling authentication processes such as login and register functionalities. The second module, known as "chat," is protected on the Node.js backend using the passport-jwt strategy. Each module has its own separate index.html
file.
In the authentication module, there is a register()
method in the register controller that appears as follows:
$scope.register = function () {
$http({
method: 'post',
url: '/api/register',
data: {
username: $scope.username,
email: $scope.email,
password: $scope.password
},
headers: {
'Content-Type': 'application/json'
}
})
The route /api/register
is responsible for all registration-related actions. Additionally, there is a login()
method in the login controller which looks like this:
$scope.login = function () {
$http({
method: 'post',
url: '/api/login',
data: {
username: $scope.username,
password: $scope.password
},
headers: {
'Content-Type': 'application/json'
}
}).then(function success(res) {
//TODO redirect to '/chat' with auth token
}
};
If the user exists in the database, the API will return a JWT token accessible via res.body.token. This token should be utilized to retrieve the secure chat page available at the 'localhost:3000/chat' URL. However, I am facing difficulty in sending the proper request from the Angular client with an Authorization
header containing the token to access the chat page.