package com.izouma.immall.utils;

import com.izouma.immall.domain.BackUser;
import com.izouma.immall.security.JwtBackUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public class SecurityUtils {
    public static BackUser getAuthenticatedUser() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        BackUser user = null;
        if (authentication != null && authentication.getPrincipal() instanceof JwtBackUser) {
            user = ((JwtBackUser) authentication.getPrincipal()).getUser();
        }
        return user;
    }
}
