aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backend/controllers/loginController.go18
-rw-r--r--main.go10
2 files changed, 13 insertions, 15 deletions
diff --git a/backend/controllers/loginController.go b/backend/controllers/loginController.go
index 4de4c00..c533757 100644
--- a/backend/controllers/loginController.go
+++ b/backend/controllers/loginController.go
@@ -62,7 +62,7 @@ func Login(c *gin.Context) {
62 // Generate JWT token 62 // Generate JWT token
63 token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{ 63 token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
64 "sub": steamID, 64 "sub": steamID,
65 "exp": time.Now().Add(time.Hour * 24 * 365).Unix(), 65 "exp": time.Now().Add(time.Hour * 24 * 30).Unix(),
66 }) 66 })
67 // Sign and get the complete encoded token as a string using the secret 67 // Sign and get the complete encoded token as a string using the secret
68 tokenString, err := token.SignedString([]byte(os.Getenv("SECRET_KEY"))) 68 tokenString, err := token.SignedString([]byte(os.Getenv("SECRET_KEY")))
@@ -70,13 +70,15 @@ func Login(c *gin.Context) {
70 c.JSON(http.StatusBadRequest, models.ErrorResponse("Failed to generate token.")) 70 c.JSON(http.StatusBadRequest, models.ErrorResponse("Failed to generate token."))
71 return 71 return
72 } 72 }
73 c.JSON(http.StatusOK, models.Response{ 73 c.SetCookie("token", tokenString, 3600*24*30, "/", "", true, true)
74 Success: true, 74 c.Redirect(http.StatusTemporaryRedirect, "/")
75 Message: "Successfully generated token.", 75 // c.JSON(http.StatusOK, models.Response{
76 Data: models.LoginResponse{ 76 // Success: true,
77 Token: tokenString, 77 // Message: "Successfully generated token.",
78 }, 78 // Data: models.LoginResponse{
79 }) 79 // Token: tokenString,
80 // },
81 // })
80 return 82 return
81 } 83 }
82} 84}
diff --git a/main.go b/main.go
index 915955a..991f3c0 100644
--- a/main.go
+++ b/main.go
@@ -5,7 +5,6 @@ import (
5 "log" 5 "log"
6 "os" 6 "os"
7 7
8 "github.com/gin-gonic/contrib/cors"
9 "github.com/gin-gonic/gin" 8 "github.com/gin-gonic/gin"
10 "github.com/joho/godotenv" 9 "github.com/joho/godotenv"
11 "github.com/pektezol/leastportals/backend/database" 10 "github.com/pektezol/leastportals/backend/database"
@@ -20,8 +19,8 @@ import (
20// @license.name GNU General Public License, Version 2 19// @license.name GNU General Public License, Version 2
21// @license.url https://www.gnu.org/licenses/old-licenses/gpl-2.0.html 20// @license.url https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22 21
23// @host lp.ardapektezol.com/api 22// @host lp.ardapektezol.com/api
24// @BasePath /v1 23// @BasePath /v1
25func main() { 24func main() {
26 if os.Getenv("ENV") == "PROD" { 25 if os.Getenv("ENV") == "PROD" {
27 gin.SetMode(gin.ReleaseMode) 26 gin.SetMode(gin.ReleaseMode)
@@ -31,12 +30,9 @@ func main() {
31 log.Fatal("Error loading .env file") 30 log.Fatal("Error loading .env file")
32 } 31 }
33 router := gin.Default() 32 router := gin.Default()
34 router.Use(cors.New(cors.Config{
35 AllowedOrigins: []string{"https://steamcommunity.com"},
36 }))
37 database.ConnectDB() 33 database.ConnectDB()
38 // For frontend static serving - only for local debug 34 // For frontend static serving - only for local debug
39 // router.Use(static.Serve("/", static.LocalFile("./frontend/dist", true))) 35 // router.Use(static.Serve("/", static.LocalFile("./frontend/build", true)))
40 routes.InitRoutes(router) 36 routes.InitRoutes(router)
41 router.Run(fmt.Sprintf(":%s", os.Getenv("PORT"))) 37 router.Run(fmt.Sprintf(":%s", os.Getenv("PORT")))
42} 38}