Accessing CouchDB using AngularJS requires users to sign in, with the authentication cookie only being sent to the `/_

Check out my previous posts on this topic here: 1, 2

I currently have an AngularJS app with two controllers. The first one interacts with CouchDB documents, while the second handles sign-in requests to example.com/demo/_session.

Upon opening the application, I encounter an issue where I am unable to edit CouchDB data in the first controller because certain actions are restricted to logged-in users only. In the second controller, a simple POST request using $http is made to obtain an Http-only auth cookie called AuthSession. This cookie should be bound to the CouchDB address and ideally any request from the page to the CouchDB address should include this cookie.

However, this is not happening as expected. No calls are being made to CouchDB, except for those to /_session that come with the AuthSession cookie. For example, example.com/demo/_session works with AuthSession, but example.com/demo/records does not.

You can view screenshots of the issue here: https://i.sstatic.net/pSrKO.png https://i.sstatic.net/uBhT2.png https://i.sstatic.net/n7MBR.png

While learning about Angular and CouchDB, I've reached a roadblock.

What am I doing wrong? I prefer not to obscure CouchDB behind custom authentication methods as it seems overly complex and not advisable.

UPDATE: I'm also facing difficulties in obtaining the Set-Cookie header—it doesn't seem to be available in

HttpPromise.success(function (data, status, headers, config))
under headers. Even trying to access it via headers("Set-Cookie") has been unsuccessful.

Could there be an issue with my CouchDB configuration? I have shared it on pastebin for reference: uploaded it to pastebin.

Answer №1

  1. Validate if CORS is enabled (using * in my case)
  2. Verify the setting for cors/credentials in the configuration, it should be set to true
  3. Include {withCredentials:true} in Angular's $http method

These steps have resolved the issue.

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 button's onclick function is failing to save the record in the database

Hello everyone, I am facing an issue with the ONCLICK button functionality. I have written code to save a form to the database. In the image, there are 2 buttons: Save button (type="submit") Save and New button (type="button") The Save button is ...

The geolocation navigator is not defined

Currently, I am in the process of developing an AngularJS application that I plan to convert into a mobile app using Cordova. My goal is to incorporate Cordova's geolocation plugin into the app, but I have encountered an issue where it returns undefin ...

What could be causing my React button to stop functioning as a link to an external website when using anchor tags?

I recently created some buttons for my website using React. Initially, everything was working perfectly with the buttons, but suddenly they stopped functioning. Strangely, I didn't make any alterations to the code and I'm puzzled as to why they a ...

Leveraging promises with node.js and couched/nano for asynchronous operations

Currently experimenting with the Q promises library in conjunction with couchDB and Nano. The code below is able to display messages in the console, however, it seems that the database is not being created as expected. var nano = require('nano') ...

I am attempting to utilize Ajax in order to transfer information to a different webpage

It's a bit complex and I can't figure out why it's not working. My goal is to create a page with textboxes, dropdown lists, and a datagrid using easyui. The issue arises when I select something from the dropdown list - I want two actions to ...

Tips for efficiently storing and accessing data obtained from the "RESTBuilder" tool on the Total.js platform

After stumbling upon this informative tutorial on how to build a cryptocurrency comparison site with VueJs, I was inspired to create a single-page application using the total.js platform. My goal is to fetch the list of coins from the "coinmarketcap.com" A ...

Using the textbox input to trigger an alert message

Just starting out with JavaScript and I'm attempting to create an alert box that not only displays the message "Thank You For Visiting" when you click the Enter button, but also includes the name entered into the text box. While I have successfully im ...

React does not always remove event listeners when using the useEffect hook's return callback

I have a functionality in my component where it initializes a key event listener. This event is supposed to trigger an API call to fetch random data. useEffect(() => { const keyUpEvent = (event) => { if (event.code === "Enter") { ...

utilizing the active class with react js

Apologies for the question, but I am facing an issue where adding an active class to a button is affecting all buttons when clicked. How can this be fixed? Here is the code snippet: <div className=""> {category.items.length === 0 ? ( ...

Having trouble with my bootstrap carousel not functioning properly - issue with jQuery line causing the rest of the code to disable

I've been facing some challenges with this Bootstrap slider for quite some time now. Despite my best efforts and thorough research on the forum, I just can't seem to make it function properly. Here's the code snippet in question: <!DOCTY ...

What is the best way to execute JavaScript on the main MVC page when an AJAX request in a partial view has finished?

My Asp.net MVC partial view is designed for searching and makes an Ajax call to retrieve results. After the results are displayed, the user can select a search result by clicking on a link in one of the rows. Upon selecting a search result, an Ajax post re ...

The callback function fails to execute the click event following the .load() method

Hey there, I've hit a roadblock and could really use some help figuring out where I went wrong. Let me break down my script for you. On page1.html, I have a div that gets replaced by another div from page2.html using jQuery's .load() method. Here ...

The integration of socket.io with static file routing in node.js is encountering issues

I am currently developing a chat application and I have encountered an issue. When the static file routing is functioning correctly, the socket.io for the chat feature throws a "not found" error in the console. http://localhost/socket.io/?EIO=3&tran ...

The ID Token could not be verified due to an invalid jwt.split function

I'm currently working on validating a Google ID Token on my Node.js server. Unfortunately, I've encountered the following error: The ID Token cannot be verified: jwt.split is not a function For reference, here is the link to the code that I am ...

Utilizing lodash and JavaScript for data normalization techniques

Converting data from two dimensions to one dimension using lodash rel href link1 url1 link2 url2 link3 url3 url4 link4 url4 url5 Expected output after normalization rel href link1 url1 link2 url2 link3 url3 link ...

Utilizing Sequelize to Convert and Cast Data in iLike Queries

When using Sequelize for a full-text search, I encountered an issue with applying the iLike operator to columns of INTEGER or DATE type. How can I cast off a column in this case? To illustrate, here is an example of what I am trying to achieve with a Post ...

Disable sessionStorage property when closing tabs on all pages

I am brand new to the world of .NET development, currently immersing myself in an ASP application with web forms. One particular page in the application contains a table. When a user clicks on a row within this table, it triggers the opening of a new tab. ...

The ReactDom reference is not defined when working with React and webpack

After following a tutorial on React and webpack from jslog.com, I encountered issues with using updated syntax such as using ReactDom to call render instead of the deprecated 'React.renderComponent'. I tried running: npm install --save react-do ...

Testing the functionality of a video player using Protractor

Exploring the world of front end development is a new adventure for me, so please bear with me. I have created an HTML page that includes an embedded video using the HTML video tag as shown below: <video id=... class=...> <source src=... type ...

Check if a rotated rectangle lies within the circular boundary of the canvas

I have a rectangular shape that has been rotated using the ctx.rotate method, and there is also an arc on the canvas. My goal is to determine if any part of the rectangle lies within the boundaries of the arc. See the example below: https://i.sstatic.net/ ...