User login functionality implemented
This commit is contained in:
parent
f9d737169d
commit
556614a2d8
|
@ -2,31 +2,32 @@ import React from 'react'
|
|||
import LoginStyle from './Login.style'
|
||||
import AccountCircleIcon from '@mui/icons-material/AccountCircle'
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||
import {
|
||||
faUser,
|
||||
faEnvelope,
|
||||
faLock,
|
||||
} from '@fortawesome/free-solid-svg-icons'
|
||||
import { UserContext } from '../../helpers/user/usercontext'
|
||||
import { faUser, faEnvelope, faLock } from '@fortawesome/free-solid-svg-icons'
|
||||
import UserAuth, { UserContext } from '../../helpers/user/usercontext'
|
||||
import { useState } from 'react'
|
||||
import Link from 'next/link'
|
||||
import { useContext } from 'react'
|
||||
|
||||
function Login() {
|
||||
const context = useContext(UserAuth)
|
||||
const [userData, setUserData] = useState({
|
||||
email: '',
|
||||
password: '',
|
||||
})
|
||||
const handleSubmit = (e) => {
|
||||
e.preventDefault()
|
||||
setUserData(userData)
|
||||
context.login(userData)
|
||||
}
|
||||
|
||||
const handleInput = (event) => {
|
||||
const name = event.target.name
|
||||
const value = event.target.value
|
||||
setUserData({ ...userData, [name]: value })
|
||||
}
|
||||
|
||||
return (
|
||||
<LoginStyle>
|
||||
<form className="form-wrapper">
|
||||
<form className="form-wrapper" onSubmit={handleSubmit}>
|
||||
<p className="reg-title">Sign in</p>
|
||||
|
||||
<img src="/images/user.png"></img>
|
||||
|
@ -61,11 +62,9 @@ function Login() {
|
|||
/>
|
||||
</div>
|
||||
|
||||
<Link href="/">
|
||||
<button type="submit" className="submit-button">
|
||||
Submit
|
||||
</button>
|
||||
</Link>
|
||||
<button type="submit" className="submit-button">
|
||||
Submit
|
||||
</button>
|
||||
|
||||
<p className="foot-text">
|
||||
New here?
|
||||
|
|
|
@ -4,18 +4,28 @@ import axios from 'helpers/Axios'
|
|||
|
||||
const UserAuthProvider = ({ children }) => {
|
||||
const [user, setUser] = useState(null)
|
||||
const login = () => {
|
||||
setUser('default')
|
||||
const login = (data) => {
|
||||
axios
|
||||
.post(`http://localhost:5000/user/login`, {
|
||||
email: data.email,
|
||||
password: data.password,
|
||||
})
|
||||
.then((data) => {
|
||||
console.log(data.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log(error)
|
||||
})
|
||||
}
|
||||
const createAcc = (data) => {
|
||||
axios
|
||||
.post(`/user/register`, {
|
||||
.post(`http://localhost:5000/user/register`, {
|
||||
email: data.email,
|
||||
password: data.password,
|
||||
name: data.name,
|
||||
})
|
||||
.then(function (response) {
|
||||
console.log(response)
|
||||
.then((data) => {
|
||||
console.log(data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log(error)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue