Switch from cookie to Bearer token auth and add CORS support - Semi finished

This commit is contained in:
2025-05-16 16:20:30 +03:30
parent 2e4b97e4bc
commit cb5149b7bc
8 changed files with 61 additions and 27 deletions
+8 -7
View File
@@ -45,10 +45,15 @@ func (appContext *AdminDashboardHandler) RejectMedia(c *gin.Context) {
}
}
func (appContext *AdminDashboardHandler) GetMedia(c *gin.Context) {
media := appContext.AppContext.PostService.GetMedia()
c.JSON(http.StatusOK, media)
}
func (appContext *AdminDashboardHandler) Login(c *gin.Context) {
var input requestmodels.LoginInput
// Validate data
if err := c.ShouldBindJSON(&input); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
@@ -62,17 +67,13 @@ func (appContext *AdminDashboardHandler) Login(c *gin.Context) {
return
}
c.SetCookie("token", token, 3600, "/", "", false, true)
c.JSON(http.StatusOK, gin.H{"message": "Login successful"})
c.JSON(http.StatusOK, gin.H{"message": "Login successful", "token": token})
} else {
c.JSON(401, gin.H{
"YouAreOn": "Unauthorized",
"error": "wrong password",
})
return
}
c.JSON(200, gin.H{
"YouAreOn": "Login",
})
}