36 lines
770 B
Go
36 lines
770 B
Go
package user
|
|
|
|
import (
|
|
"janex/admin-dashboard-backend/modules/database"
|
|
"janex/admin-dashboard-backend/modules/structs"
|
|
"janex/admin-dashboard-backend/modules/utils"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
// Requested on web startup
|
|
func User(c *fiber.Ctx) error {
|
|
xAuthorization := utils.GetXAuhorizationHeader(c)
|
|
|
|
var userSession structs.UserSession
|
|
|
|
database.DB.First(&userSession, "id = ?", xAuthorization)
|
|
|
|
if len(userSession.Id) != utils.LenHeaderXAuthorization {
|
|
return fiber.ErrInternalServerError
|
|
}
|
|
|
|
var user structs.User
|
|
|
|
database.DB.First(&user, "id = ?", userSession.UserId)
|
|
|
|
if len(user.Id) != utils.LenUserId {
|
|
return fiber.ErrInternalServerError
|
|
}
|
|
|
|
return c.JSON(structs.UserResponse{
|
|
Username: user.Username,
|
|
Email: user.Email,
|
|
})
|
|
}
|