Auth middleware with JWT

This commit is contained in:
Leons Aleksandrovs
2025-07-06 18:13:26 +03:00
parent 3003a961b6
commit d18f9f9706
5 changed files with 90 additions and 0 deletions
+10
View File
@@ -1,6 +1,8 @@
package responses
import (
"net/http"
"github.com/gin-gonic/gin"
)
@@ -19,3 +21,11 @@ func Error(c *gin.Context, err string, code int) {
"error": err,
})
}
func NeedsToLogin(c *gin.Context) {
c.JSON(http.StatusUnauthorized, gin.H{
"success": false,
"error": "Authentication required",
"needsAuthentication": true, // only appears in this error
})
}