Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $.ajax({
- url: '/api/login',
- type: 'GET',
- dataType: 'json',
- ContentType: 'application/json',
- data: {formData},
- success: (data) => {
- console.log('SUCCESS')
- console.log(data)
- this.setState({
- isInProcess: false
- })
- },
- error: (jqXHR) => {
- console.log(jqXHR)
- console.log('ERROR')
- this.setState({isInProcess: false})
- }
- })
- async function findUser(data) {
- try {
- const user = await User.findOne({email: data.email,
- password: data.password})
- console.log('User was found')
- return { user }
- } catch (err) {
- console.log('error', err)
- throw err
- }
- }
- app.get('/api/login', async (req, res) => {
- const data = req.query
- try {
- const foundUserData = await findUser(data.formData)
- return res.json(foundUserData)
- } catch (err) {
- return res.status(400).json(err)
- }
- })
Add Comment
Please, Sign In to add comment