Redirect after successful authentification in node js vanilla javascript and axios

I am building my web app and just finished the login controllers where once user put valid credentials, a JWT is created and set in the headers authorization then the client side will do the redirection with location.replace . however it does not work at all indeed once I put the username and password I am not redirect and nothing is shown on the network section of my brother but if I only do a post request I can see it on the network’s browser tab.

The other solution was with axios in client side, first do a post request then a get request but it only works on the network tab but not redirecting to the dashboard page.

I’ve read many thread but it seems that none of them have an answer for that or I may have been missing something

Here example of my code:

First my auth middleware:

const auth = async (req,res) => {
    const {username , password} = req.body

    if (!username || !password) {
        return  res.status(404).json({
            message: `Veuilliez entrez un mot de passe et/ou un nom d'utilisateur`

    const user = await User.findOne({ username });

    if (!user) {
        return res.status(404).json({
            message : `Les informatios entrées ne sont pas correctes`

    const isSamePassword = await user.comparePassword(password);
    if (!isSamePassword) {
        return res.status(404).json({
            message : `Les informatios entrées ne sont pas correctes`

    const token = user.createJWT();
    res.header('authorization', 'Bearer '.concat(token)).json({
        username : username,
        token : token

my client side js:

submitForm.addEventListener('submit', async function(e) {
    try {
        const response = await'/user/login',{
            username: username.value,
            password: password.value
            () => {
    } catch (error) {

Can anyone help me please

This code redirects the client to {current_host}/transferts without adding a token.

y it goes directly to /transferts and doing the post request why ? how should I do it ? I’ve tried many solution and none of them worked so far. How should I add a token before hand so my redirect work ?

The link should be something like