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

Commit

Permalink
Update accessToken
Browse files Browse the repository at this point in the history
  • Loading branch information
EloToJaa committed Jul 31, 2023
1 parent 1d9e070 commit 1b0f070
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions controllers/auth/loginController.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ func LoginController(ctx *fiber.Ctx) error {

// Send response
ctx.Status(fiber.StatusOK).JSON(fiber.Map{
"message": "Success",
"token": accessToken,
"message": "Success",
"accessToken": accessToken,
})
return nil
}
4 changes: 2 additions & 2 deletions controllers/auth/registerController.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func RegisterController(ctx *fiber.Ctx) error {
// Check if user exists
err := userCollection.FindOne(ctx.Context(), bson.M{"username": body.Username}).Decode(&userModel)
if err == nil {
ctx.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
ctx.Status(fiber.StatusConflict).JSON(fiber.Map{
"message": "Username already exists",
})
return nil
Expand All @@ -56,7 +56,7 @@ func RegisterController(ctx *fiber.Ctx) error {
// Check if email exists
err = userCollection.FindOne(ctx.Context(), bson.M{"email": body.Email}).Decode(&userModel)
if err == nil {
ctx.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
ctx.Status(fiber.StatusConflict).JSON(fiber.Map{
"message": "Email already in use",
})
return nil
Expand Down
4 changes: 2 additions & 2 deletions controllers/auth/tokenController.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func TokenController(ctx *fiber.Ctx) error {
}

ctx.Status(fiber.StatusOK).JSON(fiber.Map{
"access_token": accessToken,
"message": "Token refreshed",
"accessToken": accessToken,
"message": "Token refreshed",
})

return nil
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 * 15)
return time.Now().Add(time.Minute * 5)
}

func GetRefreshTokenSecret(passwordHash string) string {
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ func main() {
app.Use(recover.New())
app.Use(cors.New(cors.Config{
AllowCredentials: true,
AllowOrigins: "http://localhost:5173",
AllowHeaders: "Origin, Content-Type, Accept, Cookie",
AllowOrigins: "http://localhost:5173, http://localhost",
AllowHeaders: "Origin, Content-Type, Accept, Cookie, Authorization, X-CSRF-Token",
}))
// app.Use(csrf.New())
app.Use(limiter.New(limiter.Config{
Max: 2000,
Max: 200,
Expiration: time.Minute,
LimitReached: func(c *fiber.Ctx) error {
return c.Status(fiber.StatusTooManyRequests).JSON(fiber.Map{
Expand Down

0 comments on commit 1b0f070

Please sign in to comment.