-
Notifications
You must be signed in to change notification settings - Fork 445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mai, Sofie & Wen | Project Authentication #333
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well working authentication with a cute frontend! Good job 🚀
username: { type: String, unique: true, required: true, minLength: 8 }, | ||
email: { | ||
type: String, | ||
unique: true, | ||
required: true, | ||
match: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/, | ||
}, | ||
password: { type: String, required: true }, | ||
accessToken: { type: String, default: () => bcrypt.genSaltSync() }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice if all properties were formatted like the email one 😄
app.post("/signup", async (req, res) => { | ||
try { | ||
const { username, email, password } = req.body; | ||
const user = new User({ | ||
username, | ||
email, | ||
password: bcrypt.hashSync(password, 10), | ||
}); | ||
await user.save(); | ||
res.status(201).json({ message: "Sign up successfully", success: true }); | ||
} catch (error) { | ||
console.log(error.message); | ||
res.status(400).json({ | ||
message: "Could not sign up.", | ||
success: false, | ||
error: error.message, | ||
}); | ||
} | ||
}); | ||
|
||
// Log-in | ||
app.post("/login", async (req, res) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually endpoints are named in plural nouns, after what they return or in this case create. So a name suggestion is: POST /users and POST /sessions
Netlify link
Frontend: https://team-peace-auth.netlify.app
Backend: https://project-auth-lh3p.onrender.com
Collaborators
[maikanetaka, SofieFerrari]