Skip to content

Commit

Permalink
uint pointers in the wild is not a good idea
Browse files Browse the repository at this point in the history
Signed-off-by: Arnav Gupta <[email protected]>
  • Loading branch information
championswimmer committed Nov 5, 2023
1 parent 4e85ad6 commit a5ed5a9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/auth/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func CreateJWTFromUser(u *models.User) string {
return lo.Must(token.SignedString([]byte(JWT_KEY)))
}

func ValidateJWT(t string) (*uint, error) {
func ValidateJWT(t string) (*models.User, error) {
claims := jwt.MapClaims{}
_, err := jwt.ParseWithClaims(t, claims, func(token *jwt.Token) (interface{}, error) {
return []byte(JWT_KEY), nil
Expand All @@ -36,5 +36,5 @@ func ValidateJWT(t string) (*uint, error) {
if exp.Before(time.Now()) {
return nil, jwt.ErrTokenExpired
}
return &sub, nil
return &models.User{ID: sub}, nil
}
6 changes: 3 additions & 3 deletions tests/auth/jwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func TestJwt_ParseToken(t *testing.T) {
log.Info("jwt: ", jwt)
assert.NotNil(t, jwt)

userID, err := auth.ValidateJWT(jwt)
user, err := auth.ValidateJWT(jwt)
assert.Nil(t, err)
assert.NotNil(t, userID)
assert.Equal(t, testUser.ID, *userID)
assert.NotNil(t, user)
assert.Equal(t, testUser.ID, user.ID)
}

0 comments on commit a5ed5a9

Please sign in to comment.