Managing timeouts and errors in a Spring and Vue login systemIn this system,

I am currently working on developing a back-end using Spring and a front-end with Vue. Both projects are separate but running on the same machine. I have managed to resolve or disable all cors, csrf, and login issues except for one that has left me completely puzzled.

Here is an excerpt from my SecurityConfig.java file in the Spring project:

(Code snippet goes here)

And from my LoginController.java file:

(Code snippet goes here)

In my Vue side, I have an axios call within the API:

(Code snippet goes here)

The issue arises when I provide unauthorized credentials through the axios call, leading to a timeout error instead of displaying relevant information about the error:

Error: timeout of 1000ms exceeded
    at createError (createError.js?2d83:16)
    at XMLHttpRequest.handleTimeout (xhr.js?b50d:95)

Furthermore, there is a strange behavior observed in Vue where an odd alert form appears before the timeout error, causing confusion and frustration.

If anyone can provide some guidance on where I could start troubleshooting this issue, it would be greatly appreciated as I am currently feeling quite baffled.

UPDATE1

Upon further investigation, it seems that the problem lies within the axios call, specifically with the withCredentials: true option. Enabling this option was intended to handle session cookie management seamlessly. However, disabling it results in normal login behavior without session management, while enabling it triggers the undesirable alert form that I cannot seem to rectify.

Answer №1

When it comes down to it, the issue arises when axios sends a request to the API with an incorrect username and/or password. The server responds with a 401 error code and sets the WWW-Authenticate header to Authentication: Basic realm.

Interestingly, Google Chrome takes it upon itself to prompt the user until axios times out in this situation.

To handle this more effectively, you can change either the status code (e.g., to 400 or 403) or modify the authentication part in the WWW-Authenticate header while keeping the 401 code (indicating an unauthorized request).

The following snippet demonstrates a simple authentication tweak added to my spring's httpBasic():

@Override
protected void configure(final HttpSecurity http) throws Exception {

    http
        .authorizeRequests()
            [...]
            .httpBasic().authenticationEntryPoint(new BasicAuthenticationEntryPoint() {

                { setRealmName("codrev"); }

                @Override
                public void commence(HttpServletRequest request, HttpServletResponse response,
                        AuthenticationException authException) throws IOException {

                    response.setStatus(HttpStatus.UNAUTHORIZED.value());

                    response.setHeader("WWW-Authenticate", getRealmName());
                    response.setHeader("Accept", "application/json, text/plain, */*");
                    response.setHeader("Content-Type", "application/json;charset=utf-8");
                    response.setHeader("cache-control", "no-cache, no-store, max-age=0, must-revalidate");

                    Map<String, Object> data = new HashMap<String, Object>();
                    data.put("logged", false);

                    response.getOutputStream().println(new ObjectMapper().writeValueAsString(data));
                }
            })
    ;
}

!! Avoid calling

super.commence(request, response, authException)
as it leads to redundant response modifications. !!

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

What is the method for retrieving the index of an array from an HTML element?

Howdy! Within my Vue application, I have the ability to create multiple individuals: <div v-for="newContent in temp" :key="newContent.id" @click="showId(newContent.id)" v-show="true"> <!-- ...

Encountering difficulties inputting text in email body on Selenium using Java

I am trying to implement a function that sends emails using Gmail, but I am facing an issue where the code only sends emails with empty bodies. I suspect that the frame switch is not done correctly. Can someone please guide me on which frame is used for co ...

It is not possible to make a comparison between two Strings within a JSP file

I have this unique JSP file that contains the following code: <SELECT name="brandsFrom" onchange="as()"> <c:forEach items="${brandsSelectedList}" var="brands"> <c:if test="${brands.name == nam}"> <option value="${b ...

`I encountered difficulty in finding the radio button element using Selenium WebDriver`

I am a beginner trying to grasp automation using the tool Selenium. My goal is to automate operations on this website - Specifically, I am attempting to log in and interact with a radio button (for selecting one way or round trip) in the flight finder sec ...

During the compilation process, V8Js encountered an error (ReferenceError) on line 9272, specifying that the

<?php namespace App\Http\Controllers\Auth; use Illuminate\Support\Str; use Illuminate\Support\Facades\DB; use Illuminate\Http\Request; use App\Http\Controllers\Contro ...

Localization translation in a user interface

I want to create a form with i18n translation. I've attempted it, but it's not functioning properly: <div id="form" align="center" justify="center"> <v-col sm="4" align="center" ...

How to convert Firebase snapshot JSON data to text format instead of an object in Vue.js

After successfully pulling the data, it shows up as an object in my view: { "-MH8EpUbn1Eu3LdT0Tj0": { "code": "https://www.apesyntax.com", "content": "This is the tut content", "date": "2020- ...

How can you extract path information from an SVG file and utilize it as a marker on Google Maps?

I want to implement a custom SVG icon as a marker on Google Maps. I have obtained this SVG file: <svg xmlns="http://www.w3.org/2000/svg" width="510px" height="510px" viewBox="0 0 510 510"> <g stroke="black" stroke-width="10" ...

Vue: Do not process property until axios response

When making API calls using axios, I encounter an issue where I have to specify blank values for mustache properties before they are populated. For example, {{page_data.title}} generates an error even though axios will eventually populate the value. To o ...

The type 'WebDriver' from Selenium cannot be resolved, and the type 'FirefoxDriver' cannot be resolved as well. This is not a duplicate issue

My first experience using this forum has been quite frustrating. My questions keep getting deleted as duplicates, even though the suggested solutions are not working for me. The initial problem was caused by incorrect jars, but I believe I have the correct ...

Vue components failing to render in Laravel application

Currently experiencing an issue in Laravel where Vue components are displaying/updating locally but not on the server. Despite having all necessary packages of Vue and Node installed on the server, I can't seem to figure out what the problem is. Here ...

retrieve a property value using a Vue directive

I've been working on a Vue directive that should return true if a permission matches with the user permissions stored in Vuex. However, I'm facing difficulties accessing the state properly. Within Vue components, I have no trouble accessing the ...

Flask Blueprints cannot overwrite the static path

I am attempting to utilize Flask Blueprints for serving a multipage web application. Webapp structure: Landing page html->login->Vuejs SPA Flask structure: app/ client/ dist/ static/ js/ css/ ...

`CSS Content Placeholder Issue When Used Alongside JavaScript`

Let me explain a bit, I have a master page named UserProfile.master which has a content placeholder linked to UserProfileWall.aspx. Now, I am trying to incorporate some additional JavaScript and a second CSS file in the userprofilewall page. However, whene ...

Create a loop in Vue.js 3 without the need for a query

Can someone help me understand how to fetch data using a loop in Vue.js version 3 when working with queries? I am trying to retrieve an object based on its id, which is obtained from the URL. However, I seem to be facing some difficulties. Any guidance wou ...

Tips on integrating data from Vuex into your component

How can I effectively utilize the data fetched using the Vuex store's action in a specific component? import axios from 'axios' export default { namespaced: true, state: { items: [] }, actions: { fetchCategories ({state, c ...

choose a selection hopscotch

Is there a way to prevent the input field from jumping out of alignment when an option is selected in these q-select inputs? I want to fix this issue so that the field remains in line with the horizontal alignment. https://codepen.io/kiggs1881/pen/RwENYEX ...

Display the value in Vue.js as a price format while maintaining it as an integer

I have created a Vue component called "formatted-number" which takes in an integer value (e.g. 1234) and currently displays it as a string (e.g. "12.34") to represent a price in a textfield, with the appropriate "," or "." based on the country. However, I ...

Mastering Inter-Composable Communication in Vue 3: A Guide

Composables in Vue documentation demonstrate how small composition functions can be used for organizing code by composing the app. Discover More About Extracting Composables for Code Organization "Extracted composables act as component-scoped servi ...

Elements are automatically removed from default.vue once they have been compiled in Nuxt

Looking to add a header in my Nuxt application within Nuxt/layouts/default.vue <template> <div> <Navigation/> <Nuxt /> </div> </template> But the code: <template> <Nuxt /> </template> ...