package com.izouma.dingdong.utils;

import com.izouma.dingdong.domain.User;
import com.izouma.dingdong.security.JwtUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

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