Conversation
hamid-JTG
force-pushed
the
login
branch
2 times, most recently
from
March 3, 2025 12:28
d07f6ba to
8ef3ab2
Compare
rahulgarg03
suggested changes
Mar 4, 2025
Comment on lines
+44
to
+62
| user, err := services.VerifyUserCredentials(req.Email, req.Password) | ||
| if err != nil { | ||
| c.JSON(http.StatusUnauthorized, gin.H{"error": constants.ErrInvalidCredentials}) | ||
| return | ||
| } | ||
|
|
||
| token, expiryTime, err := utils.GenerateJWT(user.ID) | ||
| if err != nil { | ||
| c.JSON(http.StatusInternalServerError, gin.H{"error": constants.ErrFailedToGenerateToken}) | ||
| return | ||
| } | ||
|
|
||
| c.SetCookie("token", token, int(expiryTime-time.Now().Unix()), "/", "localhost", false, true) | ||
|
|
||
| userResponse := serializers.SerializeLoginResponse(*user) | ||
| tokenResponse := serializers.SerializeToken(token, expiryTime) |
Comment on lines
+61
to
+65
| "user_details": userResponse, | ||
| "token": tokenResponse, |
| return | ||
| } | ||
|
|
||
| c.SetCookie("token", token, int(expiryTime-time.Now().Unix()), "/", "localhost", false, true) |
|
|
||
| type LoginRequest struct { | ||
| Email string `json:"email" binding:"required,email"` | ||
| Password string `json:"password" binding:"required,min=6"` |
There was a problem hiding this comment.
are you only making len 6 validation. you can also add a custom validator and make validator for a special character and max len too
| func VerifyUserCredentials(email, password string) (*models.User, error) { | ||
| var user models.User | ||
| if err := db.DB.Where("email = ?", email).First(&user).Error; err != nil { | ||
| if err.Error() == "record not found" { |
There was a problem hiding this comment.
gorm also give error message constant for record not found use that here
| var user models.User | ||
| if err := db.DB.Where("email = ?", email).First(&user).Error; err != nil { | ||
| if err.Error() == "record not found" { | ||
| return nil, errors.New("user not found") |
There was a problem hiding this comment.
create a constant for this check below too
| return signedToken, expiryTime, nil | ||
| } | ||
|
|
||
| func ValidateJWT(tokenString string) (uint, error) { |
rahulgarg03
reviewed
Mar 4, 2025
| c.JSON(http.StatusCreated, response) | ||
| } | ||
|
|
||
| func Login(c *gin.Context) { |
There was a problem hiding this comment.
create method instead of functions check for service too
hamid-JTG
force-pushed
the
login
branch
6 times, most recently
from
March 5, 2025 11:59
e384f5e to
28cf247
Compare
hamid-JTG
force-pushed
the
login
branch
3 times, most recently
from
March 6, 2025 12:21
fa9e66f to
ed52549
Compare
hamid-JTG
force-pushed
the
login
branch
2 times, most recently
from
March 7, 2025 09:10
aa77f55 to
6507910
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.