0

I'm trying to redirect to the user after of do an API process, I have this error:

Uncaught (in promise) ReferenceError: Cannot access 'redirect' before initialization
    at HTMLFormElement.<anonymous> (completedetails.js:18)
(anonymous) @ completedetails.js:18
async function (async)
(anonymous) @ completedetails.js:16

I'm not sure why it is happening, the process of the API is working, the problem is at the moment of the redirect to the user with the submit buton

I'm leaving my JS code

document.addEventListener('DOMContentLoaded', () => {
    console.log('Document is ready');
    const $form = document.querySelector('#completedetails');
    const $inputName = document.querySelector('#name');
    const $inputPassword = document.querySelector('#password');
    const $inputCompany = document.querySelector('#company');
    const $btn_completedetails = document.querySelector('#btn-completedetails');

    const url = "http://localhost:3000/register/";

    $form.addEventListener('submit', async (e) => {
        e.preventDefault();
        let name = $inputName.value;
        let password = $inputPassword.value;
        let company = $inputCompany.value;
        const response = await fetch(`${url}${company}${name}${password}`, { method: 'POST' });
        const result = await response.json();
        return const redirect = await redirect('http://seth.com/dashboard.html?ftime=1');

        
        
    })
})

0 Answers0