public AuthController(IFinancialGoalsRepository financialGoalsRepository, IMapper mapper, IJwtService jwtService) { _financialGoalsRepository = financialGoalsRepository ?? throw new ArgumentNullException(nameof(financialGoalsRepository)); _mapper = mapper ?? throw new ArgumentNullException(nameof(mapper)); _jwtService = jwtService; }
public async Task Invoke(HttpContext context, IFinancialGoalsRepository financialGoalsRepository, IJwtService jwtService) { var jwt = context.Request.Cookies["jwt"]; if (jwt != null) { try { var verifiedToken = jwtService.Verify(jwt); int userId = int.Parse(verifiedToken.Issuer); var userFromRepo = financialGoalsRepository.GetUserById(userId); context.Items["User"] = userFromRepo; } catch { // Nothing } } await _next(context); }
public GoalsController(IFinancialGoalsRepository financialGoalsRepository, IMapper mapper) { _financialGoalsRepository = financialGoalsRepository ?? throw new ArgumentNullException(nameof(financialGoalsRepository)); _mapper = mapper ?? throw new ArgumentNullException(nameof(mapper)); }