Add JWT authentication for admin dashboard login

This commit is contained in:
2025-05-16 14:41:16 +03:30
parent 855c778654
commit 1abc05ecd9
6 changed files with 93 additions and 13 deletions
+12 -2
View File
@@ -47,8 +47,18 @@ func (appContext *AdminDashboardHandler) Login(c *gin.Context) {
}
if input.Password == appContext.AppContext.AdminPassword {
c.JSON(200, gin.H{
"YouAreOn": "AdminDashboardHomePage",
token, err := appContext.AppContext.Jwt.GenerateToken(map[string]interface{}{"role": "admin"})
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Token generation failed"})
return
}
c.SetCookie("token", token, 3600, "/", "", false, true)
c.JSON(http.StatusOK, gin.H{"message": "Login successful"})
} else {
c.JSON(401, gin.H{
"YouAreOn": "Unauthorized",
})
}