Skip to content
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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

manosriram
Copy link

@manosriram manosriram commented Nov 5, 2023

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

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
@manosriram manosriram changed the title Added login API Add Login API Nov 5, 2023
@manosriram
Copy link
Author

I have assumed getting user by ID is a public API and updating the user will be a private API here.

router.Post("/", registerUser)
router.Post("/login", loginUser)
router.Get("/:id", auth.MandatoryAuthMiddleware, getUserInfo)
router.Get("/:id", getUserInfo)
Copy link
Owner

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

Comment on lines +50 to +53
res := c.db.First(user)
if res.Error != nil {
return nil, res.Error
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[api] POST /users/login to login
3 participants