-
Notifications
You must be signed in to change notification settings - Fork 70
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
Add Login API #19
base: main
Are you sure you want to change the base?
Add Login API #19
Conversation
Added JWT login auth API and middleware to restrict authenticated routes. Added ErrorResponse struct to return during caught errors Added a recovery middleware to recover from panics
I have assumed getting user by ID is a public API and updating the user will be a private API here. |
src/routes/api/users.go
Outdated
router.Post("/", registerUser) | ||
router.Post("/login", loginUser) | ||
router.Get("/:id", auth.MandatoryAuthMiddleware, getUserInfo) | ||
router.Get("/:id", getUserInfo) |
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.
the get
path should also be private here
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.
fixed.
res := c.db.First(user) | ||
if res.Error != nil { | ||
return nil, res.Error | ||
} |
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.
res := c.db.First(user) | |
if res.Error != nil { | |
return nil, res.Error | |
} | |
if res := c.db.First(user); res.Error!=nil{ | |
return nil, res.Error | |
} | |
You can have one liner error return statements. just a suggestion ;) looks neat and cute!
Added JWT login auth API and middleware to restrict authenticated routes.
Added ErrorResponse struct to return during caught errors
Added a recovery middleware to recover from panics
fixes #13