Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why do I get ':' expected.ts(1005) as a Typescript error?

Within the handleLogin function on my login page of my Next.js project I am getting this Typesricpt error: ‘:’ expected.ts(1005)

Here is the function which is supposed to handle the login:

 const handleLogin = useCallback(async (credentials) => {

        if (!credentials.email) {
            return setError('email is missing')
        }
        if (!credentials.password) {
            return setError('password is missing')
        }
        try {
            setLoading(true)
            const response: SignInResponse | undefined = await signIn('credentials', { ...credentials, redirect: false })
            if (response?error && response.error === 'CredentialsSignin') {
                setError('email or password are wrong')
            } else {
                setError('')
                router.push('/')
            }
        } catch {
            setError('login failed')
        } finally {
            setLoading(false)
            console.log(error)
        }
    }, [router, error])

On this image you can see on which section of the code the error is showing up:
errorLocation

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I have no clue which this error is showing up.

>Solution :

I think you have a typo.

The condition is looking like a ternary or conditional operator (a ? b : c) So the following line is expecting the colon:

response?error && response.error === 'CredentialsSignin'

However, that is not what you are intending. I think you have a typo and instead want optional chaining:

response?.error && response.error === 'CredentialsSignin'

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading