package middlewares

import (
	"bssapp-backend/auth"
	"bssapp-backend/models"
	"bssapp-backend/utils"
	"net/http"
)

func CurrentUser(r *http.Request) (*models.User, bool) {

	claims, ok := auth.GetClaimsFromContext(r.Context())

	if !ok || claims == nil {
		return nil, false
	}

	user := utils.UserFromClaims(claims)
	if user == nil {
		return nil, false
	}

	return user, true
}
