|
5 | 5 | "net/http"
|
6 | 6 |
|
7 | 7 | "github.com/gin-gonic/gin"
|
| 8 | + "github.com/shaikrasheed99/golang-user-jwt-authentication/configs" |
| 9 | + "github.com/shaikrasheed99/golang-user-jwt-authentication/constants" |
8 | 10 | "github.com/shaikrasheed99/golang-user-jwt-authentication/helpers"
|
9 | 11 | "github.com/shaikrasheed99/golang-user-jwt-authentication/requests"
|
10 | 12 | "github.com/shaikrasheed99/golang-user-jwt-authentication/services"
|
@@ -64,8 +66,27 @@ func (ah *authHandler) SignupHandler(c *gin.Context) {
|
64 | 66 | return
|
65 | 67 | }
|
66 | 68 |
|
67 |
| - savedUserRes := helpers.CreateAuthenticationResponse(savedUser, accessToken, refreshToken) |
68 |
| - res := helpers.CreateSuccessResponse(http.StatusOK, "successfully saved user details", savedUserRes) |
| 69 | + res := helpers.CreateSuccessResponse(http.StatusOK, "successfully saved user details", nil) |
| 70 | + |
| 71 | + c.SetCookie( |
| 72 | + constants.AccessTokenCookie, |
| 73 | + accessToken, |
| 74 | + int(configs.JWT_ACCESS_TOKEN_EXPIRATION_IN_MINUTES), |
| 75 | + constants.HomePath, |
| 76 | + constants.LocalHost, |
| 77 | + true, |
| 78 | + true, |
| 79 | + ) |
| 80 | + |
| 81 | + c.SetCookie( |
| 82 | + constants.RefreshTokenCookie, |
| 83 | + refreshToken, |
| 84 | + int(configs.JWT_REFRESH_TOKEN_EXPIRATION_IN_MINUTES), |
| 85 | + constants.HomePath, |
| 86 | + constants.LocalHost, |
| 87 | + true, |
| 88 | + true, |
| 89 | + ) |
69 | 90 |
|
70 | 91 | fmt.Println("[SignupHandler] Finished execution of signup handler")
|
71 | 92 | c.JSON(http.StatusCreated, res)
|
@@ -106,8 +127,27 @@ func (ah *authHandler) LoginHandler(c *gin.Context) {
|
106 | 127 | return
|
107 | 128 | }
|
108 | 129 |
|
109 |
| - userRes := helpers.CreateAuthenticationResponse(user, accessToken, refreshToken) |
110 |
| - res := helpers.CreateSuccessResponse(http.StatusOK, "successfully logged in", userRes) |
| 130 | + res := helpers.CreateSuccessResponse(http.StatusOK, "successfully logged in", nil) |
| 131 | + |
| 132 | + c.SetCookie( |
| 133 | + constants.AccessTokenCookie, |
| 134 | + accessToken, |
| 135 | + int(configs.JWT_ACCESS_TOKEN_EXPIRATION_IN_MINUTES), |
| 136 | + constants.HomePath, |
| 137 | + constants.LocalHost, |
| 138 | + true, |
| 139 | + true, |
| 140 | + ) |
| 141 | + |
| 142 | + c.SetCookie( |
| 143 | + constants.RefreshTokenCookie, |
| 144 | + refreshToken, |
| 145 | + int(configs.JWT_REFRESH_TOKEN_EXPIRATION_IN_MINUTES), |
| 146 | + constants.HomePath, |
| 147 | + constants.LocalHost, |
| 148 | + true, |
| 149 | + true, |
| 150 | + ) |
111 | 151 |
|
112 | 152 | fmt.Println("[LoginHandler] Finished execution of login handler")
|
113 | 153 | c.JSON(http.StatusOK, res)
|
|
0 commit comments