38 lines
887 B
Go
38 lines
887 B
Go
package router
|
|
|
|
import (
|
|
"janex/admin-dashboard-backend/modules/database"
|
|
"janex/admin-dashboard-backend/modules/structs"
|
|
"janex/admin-dashboard-backend/modules/utils"
|
|
"janex/admin-dashboard-backend/routers/router/api/v1/user"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
func SetupRoutes(app *fiber.App) {
|
|
v1 := app.Group("/v1")
|
|
|
|
u := v1.Group("/user")
|
|
u.Post("/auth/login", user.UserLogin)
|
|
u.Delete("/auth/logout", user.UserLogout)
|
|
u.Get("/", userSessionValidation, user.User)
|
|
}
|
|
|
|
func userSessionValidation(c *fiber.Ctx) error {
|
|
xAuthorization := utils.GetXAuhorizationHeader(c)
|
|
|
|
if len(xAuthorization) != utils.LenHeaderXAuthorization {
|
|
return fiber.ErrUnauthorized
|
|
}
|
|
|
|
var userSession structs.UserSession
|
|
|
|
database.DB.First(&userSession, "id = ?", xAuthorization)
|
|
|
|
if len(userSession.Id) != utils.LenHeaderXAuthorization {
|
|
return fiber.ErrUnauthorized
|
|
}
|
|
|
|
return c.Next()
|
|
}
|