Skip to content

Commit aac75ca

Browse files
fix(GIST-39): set cookie for production (#13)
* fix(GIST-39): set cookie in production * docs(GIST-39): updated readme
1 parent 285fb5a commit aac75ca

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ MAIL_PASSWORD="<REDACTED>"
5454
SMTP_PORT="<REDACTED>"
5555
SMTP_HOST="<REDACTED>"
5656
APP_KEY="<REDACTED>"
57+
ENV="development"
5758
```
5859

5960
4. Run the server in development mode
@@ -85,6 +86,7 @@ All the configuration is done through env variables :
8586
- `SMTP_PORT` : your smtp port
8687
- `SMTP_HOST` : your smtp host
8788
- `APP_KEY` : your app key, which is a random string that is used to encrypt access tokens
89+
- `ENV`: the environment in which the app is running (development, production)
8890

8991
## Tests
9092

user/auth_controller.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ func (a *AuthControllerImpl) Callback() fiber.Handler {
3333
}
3434
token_cookie := new(fiber.Cookie)
3535
token_cookie.Name = "gists.access_token"
36-
token_cookie.HTTPOnly = false
36+
token_cookie.HTTPOnly = true
37+
if utils.Get("ENV") == "development" {
38+
token_cookie.Secure = false
39+
} else {
40+
token_cookie.Domain = ".gists.app" // hardcoded
41+
token_cookie.Secure = true
42+
}
3743
token_cookie.Value = token
3844
c.Cookie(token_cookie)
3945
return c.Redirect(utils.Get("FRONTEND_URL"))
@@ -82,6 +88,13 @@ func (a *AuthControllerImpl) VerifyAuthToken() fiber.Handler {
8288
token_cookie.Name = "gists.access_token"
8389
token_cookie.HTTPOnly = true
8490
token_cookie.Value = jwt_token
91+
92+
if utils.Get("ENV") == "development" {
93+
token_cookie.Secure = false
94+
} else {
95+
token_cookie.Domain = ".gists.app" // hardcoded
96+
token_cookie.Secure = true
97+
}
8598
c.Cookie(token_cookie)
8699
return c.Status(200).JSON(fiber.Map{"message": "You are now logged in"})
87100
}

0 commit comments

Comments
 (0)