Integrated user's name in dashboard with email (#154)
* integrated User name in dashboard with email * changed brand name in dashboard * changed username to name in state in reg.jsx
This commit is contained in:
parent
6ac076f7bc
commit
ef76047a10
|
@ -2,14 +2,14 @@ const User = require('../models/user')
|
|||
const { customAlphabet } = require('nanoid')
|
||||
const nanoid = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz', 25)
|
||||
|
||||
module.exports.register = async ({ body: { email, password } }, res) => {
|
||||
module.exports.register = async ({ body: { email, password,name } }, res) => {
|
||||
try {
|
||||
if (!email || !password) return res.sendStatus(400)
|
||||
let oldUser = await User.findOne({ email }).catch((err) => {
|
||||
console.error(err)
|
||||
})
|
||||
if (oldUser) return res.status(400).send('Already Exists')
|
||||
let user = new User({ email })
|
||||
let user = new User({ email,name })
|
||||
user.setPassword(password)
|
||||
let validationError = false
|
||||
await user.save().catch((err) => {
|
||||
|
|
|
@ -51,6 +51,7 @@ UsersSchema.methods.generateJWT = function () {
|
|||
|
||||
return jwt.sign(
|
||||
{
|
||||
name : this.name,
|
||||
email: this.email,
|
||||
hash: this.hash,
|
||||
id: this._id,
|
||||
|
|
|
@ -27,20 +27,23 @@ function changePageContent(e){
|
|||
}
|
||||
|
||||
function Sidebar1() {
|
||||
|
||||
const {user:{name,email}} = useContext(UserAuth)
|
||||
|
||||
return (
|
||||
<div className="sidebar">
|
||||
<CloseIcon className="close_icon" onClick={toggleSidebar1} />
|
||||
|
||||
<ul>
|
||||
<div className="nav-item mb-2 brand-name">
|
||||
<h1>Brand Name</h1>
|
||||
<h1>URL Minify</h1>
|
||||
</div>
|
||||
<div className="profile">
|
||||
<div className="profile-image">
|
||||
<img src="https://png.pngtree.com/png-vector/20190307/ourlarge/pngtree-vector-edit-profile-icon-png-image_760869.jpg" />
|
||||
</div>
|
||||
<p className="name">Hayat</p>
|
||||
<p className="profession">Product Designer</p>
|
||||
<p className="name">{name}</p>
|
||||
<p className="profession">{email}</p>
|
||||
</div>
|
||||
<div className="creatButton">
|
||||
<button>Create Link</button>
|
||||
|
|
|
@ -11,7 +11,7 @@ function Reg() {
|
|||
const router = useRouter()
|
||||
const context = useContext(UserAuth)
|
||||
const [userData, setUserData] = useState({
|
||||
username: '',
|
||||
name: '',
|
||||
email: '',
|
||||
password: '',
|
||||
repassword: '',
|
||||
|
@ -45,10 +45,10 @@ function Reg() {
|
|||
</div>
|
||||
<input
|
||||
className="reg-input"
|
||||
name="username"
|
||||
name="name"
|
||||
autoComplete="off"
|
||||
type="text"
|
||||
value={userData.username}
|
||||
value={userData.name}
|
||||
onChange={handleInput}
|
||||
placeholder="Full Name"
|
||||
/>
|
||||
|
|
|
@ -80,6 +80,7 @@ const UserAuthProvider = ({ children }) => {
|
|||
url: '/user/me',
|
||||
})
|
||||
.then((user) => {
|
||||
console.log(user);
|
||||
setUser(user.data)
|
||||
})
|
||||
.catch((err) => {
|
||||
|
@ -94,7 +95,7 @@ const UserAuthProvider = ({ children }) => {
|
|||
setJwt(null)
|
||||
storeJWT(null)
|
||||
}
|
||||
const context = { jwt, user, mode, login, logout, createAcc, handleLightMode, handleDarkMode }
|
||||
const context = { jwt, user, mode, login, logout, createAcc, handleLightMode, handleDarkMode,fetchUser }
|
||||
useEffect(() => {
|
||||
let jwt = fetchJWT()
|
||||
if (jwt) {
|
||||
|
|
Loading…
Reference in New Issue