WDI-SEA / project-4-issues

Open an issue to receive help on project 4 issues
0 stars 0 forks source link

post routes aren't working for both tags and apartments #29

Closed isaac8069 closed 2 years ago

isaac8069 commented 2 years ago

What stack are you using?

(ex: MERN(mongoose + react), DR(django + react), PEN, etc.)

MERN

What's the problem you're trying to solve?

requireToken is having to be removed throughout my routes and I am running into a server error

Post any code you think might be relevant (one fenced block per file)

import { useEffect, useState } from 'react'
import apiUrl from '../../../apiConfig'

const CreateTag = (props) => {
    const [newTag, setNewTag] = useState({
        name: '',
    })

    const handleChange = (e) => {
        setNewTag({ ...newTag, [e.target.name]: e.target.value })
    }

    // const handleCheck = (e) => {
    //     setNewTag({ ...newTag, [e.target.name]: e.target.checked })
    // }

    const postTag = (e) => {
        e.preventDefault()
        let preJSONBody = {
            name: newTag.name
        }
        fetch(`${apiUrl}/tags`, {
            method: 'POST',
            body: JSON.stringify(preJSONBody),
            headers: { 'Content-Type': 'application/json' }
        })
            .then(response => response.json())
            .then(postedTag => {
                console.log('POSTED TAG', postedTag)
                // props.refreshTags()
                setNewTag({
                    name: ''
                })
            })
            .catch(err => console.error(err))
    }

    return (
        <form onSubmit={postTag}>
            <div>
                <label htmlFor="name">Name:</label>
                <input type="text" name="name" id="name" onChange={handleChange} value={newTag.name} />
            </div>

            <input type="submit" value="Post" />
        </form>
    )
}

export default CreateTag

If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?

500 (Internal Server error)

What is your best guess as to the source of the problem?

The 500 Internal Server error could be caused by an error during the execution of any policy within Edge or by an error on the target/backend server. The HTTP status code 500 is a generic error response. It means that the server encountered an unexpected condition that prevented it from fulfilling the request.

What things have you already tried to solve the problem?

Restarting the server/client in terminal, restructuring my code numerous times, and using other examples to help fix the post routes

Screen Shot 2022-01-12 at 12 00 27 AM

.

isaac8069 commented 2 years ago
Screen Shot 2022-01-12 at 12 05 16 AM
isaac8069 commented 2 years ago

Screen Shot 2022-01-12 at 10 26 06 AM

DoireannJane commented 2 years ago

First maybe clear your chrome data just to make sure it's not a browser issue? Then we can look at those lines that are flagged as well as the type error.

isaac8069 commented 2 years ago

Its cleared

isaac8069 commented 2 years ago

Resolved!