Skip to content
This repository has been archived by the owner on Dec 25, 2023. It is now read-only.

Commit

Permalink
Update jwt
Browse files Browse the repository at this point in the history
  • Loading branch information
EloToJaa committed Aug 3, 2023
1 parent 1b0f070 commit a28230d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
7 changes: 3 additions & 4 deletions controllers/auth/loginController.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ func LoginController(ctx *fiber.Ctx) error {
{"email": body.UsernameOrEmail},
}}).Decode(&userModel)
if err != nil {
return ctx.Status(fiber.StatusNotFound).JSON(fiber.Map{
return ctx.Status(fiber.StatusConflict).JSON(fiber.Map{
"message": "Wrong username or password",
})
}

// Check if password is correct
argon2id := utils.NewArgon2ID()
if ok, err := argon2id.Verify(body.Password, userModel.Password); !ok || err != nil {
return ctx.Status(fiber.StatusNotFound).JSON(fiber.Map{
return ctx.Status(fiber.StatusConflict).JSON(fiber.Map{
"message": "Wrong username or password",
})
}
Expand Down Expand Up @@ -115,9 +115,8 @@ func LoginController(ctx *fiber.Ctx) error {
Name: "refresh_token",
Value: refreshToken,
Expires: jwt.GetRefreshTokenExpirationTime(),
Secure: false,
HTTPOnly: true,
SameSite: "None",
Secure: true,
})

// Send response
Expand Down
1 change: 1 addition & 0 deletions controllers/auth/tokenController.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

func TokenController(ctx *fiber.Ctx) error {
refreshToken := ctx.Cookies("refresh_token")

if refreshToken == "" {
ctx.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
"message": "Unauthorized",
Expand Down
2 changes: 1 addition & 1 deletion jwt/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func GetRefreshTokenExpirationTime() time.Time {
}

func GetAccessTokenExpirationTime() time.Time {
return time.Now().Add(time.Minute * 5)
return time.Now().Add(time.Second * 5)
}

func GetRefreshTokenSecret(passwordHash string) string {
Expand Down

0 comments on commit a28230d

Please sign in to comment.