-
-
-
+
+
)
}
+
diff --git a/components/RegisterForm.js b/components/RegisterForm.js
index a6ef2e3..5fde890 100644
--- a/components/RegisterForm.js
+++ b/components/RegisterForm.js
@@ -2,9 +2,13 @@ import React, { useState } from 'react'
import axios from '../utils/axios'
import { useAuth } from '../context/auth'
import { useRouter } from 'next/router'
+import { no_auth_required } from '../middlewares/no_auth_required'
+import {toast} from 'react-toastify'
+import 'react-toastify/dist/ReactToastify.css'
export default function Register() {
- const { setToken } = useAuth()
+ no_auth_required()
+ const { setToken} = useAuth()
const router = useRouter()
const [firstName, setFirstName] = useState('')
@@ -12,6 +16,7 @@ export default function Register() {
const [email, setEmail] = useState('')
const [password, setPassword] = useState('')
const [username, setUsername] = useState('')
+ const [confpass, setConfPass] = useState("")
const registerFieldsAreValid = (
firstName,
@@ -27,11 +32,12 @@ export default function Register() {
username === '' ||
password === ''
) {
- console.log('Please fill all the fields correctly.')
+
+ toast.warn("Please fill the field correctly")
return false
}
if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) {
- console.log('Please enter a valid email address.')
+ toast.warn("Invalid email address")
return false
}
return true
@@ -43,8 +49,8 @@ export default function Register() {
if (
registerFieldsAreValid(firstName, lastName, email, username, password)
) {
- console.log('Please wait...')
-
+ if(confpass===password){
+ toast.info("Wait..!!")
const dataForApiRequest = {
name: firstName + ' ' + lastName,
email: email,
@@ -58,24 +64,27 @@ export default function Register() {
)
.then(function ({ data, status }) {
setToken(data.token)
- router.push('/')
+ router.reload()
+ toast.info("Wait..!!")
})
.catch(function (err) {
- console.log(
- 'An account using same email or username is already created'
- )
+ toast.error("Email or Username already exists")
})
}
+ else{
+ toast.error("Passwords dont match!!!")
+ }
+ }
}
return (
-
+
Register
setPassword(e.target.value)}
placeholder='Password'
/>
+
{setConfPass(e.target.value)}}
+ />