Add JWT authentication for admin dashboard login
This commit is contained in:
@@ -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",
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user