🔊 Add logging to server.log when token generation fails
This commit is contained in:
parent
8563c80ffe
commit
b681395287
|
@ -1,7 +1,22 @@
|
|||
// Copyright 2024 Florian Beisel
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package auth
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"git.beisel.it/florian/hostname-service/db"
|
||||
|
@ -11,19 +26,19 @@ import (
|
|||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// LoginHandler godoc
|
||||
// LoginHandler godoc
|
||||
//
|
||||
// @Summary User login
|
||||
// @Description Authenticate user and return JWT token
|
||||
// @Tags Authentication
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param loginCredentials body models.LoginCredentials true "Login Credentials"
|
||||
// @Success 200 {object} models.TokenResponse "Successfully authenticated, JWT token returned"
|
||||
// @Failure 400 {object} models.ErrorResponse "Invalid request body"
|
||||
// @Failure 401 {object} models.ErrorResponse "Invalid login credentials"
|
||||
// @Failure 500 {object} models.ErrorResponse "Internal server error"
|
||||
// @Router /login [post]
|
||||
// @Summary User login
|
||||
// @Description Authenticate user and return JWT token
|
||||
// @Tags Authentication
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param loginCredentials body models.LoginCredentials true "Login Credentials"
|
||||
// @Success 200 {object} models.TokenResponse "Successfully authenticated, JWT token returned"
|
||||
// @Failure 400 {object} models.ErrorResponse "Invalid request body"
|
||||
// @Failure 401 {object} models.ErrorResponse "Invalid login credentials"
|
||||
// @Failure 500 {object} models.ErrorResponse "Internal server error"
|
||||
// @Router /login [post]
|
||||
func LoginHandler(c *gin.Context) {
|
||||
var creds models.LoginCredentials
|
||||
|
||||
|
@ -58,6 +73,7 @@ func LoginHandler(c *gin.Context) {
|
|||
token, err := GenerateToken(storedCreds.Username)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to generate token"})
|
||||
log.Printf("Error generating token %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue