From 3be6a02ba0a6200e71bd0b97a040075966dfc302 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Sat, 6 May 2023 17:41:12 +0300 Subject: feat: get token endpoint --- backend/controllers/loginController.go | 24 ++++++++++++++++++++++++ backend/routes/routes.go | 1 + 2 files changed, 25 insertions(+) (limited to 'backend') diff --git a/backend/controllers/loginController.go b/backend/controllers/loginController.go index c533757..06cc0ba 100644 --- a/backend/controllers/loginController.go +++ b/backend/controllers/loginController.go @@ -83,6 +83,30 @@ func Login(c *gin.Context) { } } +// GET Token +// +// @Summary Gets the token cookie value from the user. +// @Tags auth +// @Produce json +// +// @Success 200 {object} models.Respnose{data=models.LoginResponse} +// @Failure 404 {object} models.Response +// @Router /token [get] +func GetCookie(c *gin.Context) { + cookie, err := c.Cookie("token") + if err != nil { + c.JSON(http.StatusNotFound, models.ErrorResponse("No token cookie found.")) + return + } + c.JSON(http.StatusOK, models.Response{ + Success: true, + Message: "Token cookie successfully retrieved.", + Data: models.LoginResponse{ + Token: cookie, + }, + }) +} + func GetPlayerSummaries(steamId, apiKey string) (*models.PlayerSummaries, error) { url := fmt.Sprintf("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v2/?key=%s&steamids=%s", apiKey, steamId) resp, err := http.Get(url) diff --git a/backend/routes/routes.go b/backend/routes/routes.go index 2554fa4..19382ab 100644 --- a/backend/routes/routes.go +++ b/backend/routes/routes.go @@ -16,6 +16,7 @@ func InitRoutes(router *gin.Engine) { v1.GET("/", func(c *gin.Context) { c.File("docs/index.html") }) + v1.GET("/token", controllers.GetCookie) v1.GET("/home", middleware.CheckAuth, controllers.Home) v1.GET("/login", controllers.Login) v1.GET("/profile", middleware.CheckAuth, controllers.Profile) -- cgit v1.2.3