-
Notifications
You must be signed in to change notification settings - Fork 447
project auth #328
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
base: master
Are you sure you want to change the base?
project auth #328
Conversation
HIPPIEKICK
left a comment
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 done 🔑 ⭐
| @@ -0,0 +1,21 @@ | |||
| import jwt from "jsonwebtoken" | |||
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.
Fun that you tried out jwt 👍
| password: { type: String, required: true } | ||
| }); | ||
|
|
||
| userSchema.pre('save', async function(next) { |
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.
In your routes you're using arrow functions, try to be consistent with that throughout the whole code base
| authRouter.get("/signup", async (req, res) => { | ||
| try { | ||
| const users = await User.find() | ||
| res.status(200).json(users) | ||
| } catch (error) { | ||
| res.status(500).json({ error: error.message }) | ||
| } | ||
| }) |
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.
What's the thought behind this route? And how about security?
| console.log(username) | ||
| console.log(password) |
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.
Remove logs
| const db = mongoose.connection | ||
| db.on("error", console.error.bind(console, "Anslutningsfel:")) | ||
| db.once("open", () => { | ||
| console.log("Ansluten till databasen") | ||
| }) |
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.
Nice! Just remember that even logs and comments should be in English
| import Home from "./components/Home" | ||
| import { AuthProvider } from "./context/AuthContext" | ||
|
|
||
| function App() { |
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.
Same here, arrow function
| return | ||
| } | ||
|
|
||
| console.log("User exists. Proceeding with login...") |
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.
Alerts are enough, no need for logs
|
|
||
| const authRouter = express.Router() | ||
|
|
||
| authRouter.post("/signup", 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.
Endpoints are most often named nouns in plural, so instead of signup and login, it could be POST /users and POST /sessions
Netlify link
https://master--radiant-lollipop-9f6f69.netlify.app
https://project-auth-7ju7.onrender.com