szoe-pontok/api/auth/middleware.go

38 lines
596 B
Go
Raw Normal View History

2024-10-10 19:41:49 +00:00
package auth
import (
"net/http"
"git.tek.govt.hu/dowerx/szoe-pontok/database/auth"
"github.com/gin-gonic/gin"
)
func LoggedIn(c *gin.Context) {
token, err := c.Cookie("token")
if err != nil {
c.JSON(http.StatusUnauthorized, gin.H{
"status": http.StatusUnauthorized,
"error": "missing token",
})
c.Abort()
return
}
neptun, err := auth.LoggedIn(token)
if err != nil {
c.JSON(http.StatusUnauthorized, gin.H{
"status": http.StatusUnauthorized,
"error": "not logged in",
})
c.Abort()
return
}
c.Set("neptun", neptun)
}
func IsAdmin(c *gin.Context) {
}