Docker db volume - learnsteam
This commit is contained in:
		@@ -61,10 +61,10 @@ func (controller *authController) Register(c *gin.Context) {
 | 
			
		||||
	c.JSON(http.StatusOK, gin.H{"user": user, "token": token.Token, "refresh_token": token.RefreshToken})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Login
 | 
			
		||||
// Login 사용자 로그인
 | 
			
		||||
//
 | 
			
		||||
// @Summary 			로그인
 | 
			
		||||
// @Description		username, password 를 입력하여 로그인
 | 
			
		||||
// @Summary 			사용자 로그인 로그인
 | 
			
		||||
// @Description		사용자가 로그인합니다.
 | 
			
		||||
// @Tags					로그인
 | 
			
		||||
// @Accept				json
 | 
			
		||||
// @Produce				json
 | 
			
		||||
@@ -76,8 +76,8 @@ func (controller *authController) Register(c *gin.Context) {
 | 
			
		||||
// @Router				/auth/login [post]
 | 
			
		||||
func (controller *authController) Login(c *gin.Context) {
 | 
			
		||||
	var request models.LoginRequest
 | 
			
		||||
	if c.BindJSON(&request) != nil {
 | 
			
		||||
		c.JSON(http.StatusBadRequest, gin.H{"error": "bad request"})
 | 
			
		||||
	if err := c.BindJSON(&request); err != nil {
 | 
			
		||||
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -93,5 +93,32 @@ func (controller *authController) Login(c *gin.Context) {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	c.JSON(http.StatusOK, gin.H{"user": user, "token": token.Token, "refresh_token": token.RefreshToken})
 | 
			
		||||
	c.JSON(http.StatusOK, gin.H{
 | 
			
		||||
		"user":          user,
 | 
			
		||||
		"token":         token.Token,
 | 
			
		||||
		"refresh_token": token.RefreshToken,
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Logout
 | 
			
		||||
func (controller *authController) Logout(c *gin.Context) {
 | 
			
		||||
	token := c.GetHeader("Authorization")
 | 
			
		||||
	if token == "" {
 | 
			
		||||
		c.JSON(http.StatusBadRequest, gin.H{"error": "bad request"})
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	err := controller.tokenService.Delete(token)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	c.SetCookie("Authorization", "", -1, "/", "localhost", false, true)
 | 
			
		||||
	c.SetCookie("RefreshToken", "", -1, "/", "localhost", false, true)
 | 
			
		||||
	c.SetCookie("ExpiresAt", "", -1, "/", "localhost", false, true)
 | 
			
		||||
	c.SetCookie("RefreshExpiresAt", "", -1, "/", "localhost", false, true)
 | 
			
		||||
	c.SetCookie("RefreshTokenExpiresAt", "", -1, "/", "localhost", false, true)
 | 
			
		||||
	c.SetCookie("RefreshTokenExpiresAt", "", -1, "/", "localhost", false, true)
 | 
			
		||||
	c.SetCookie("RefreshTokenExpiresAt", "", -1, "/", "localhost", false, true)
 | 
			
		||||
	c.JSON(http.StatusOK, gin.H{"message": "logout"})
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user