public async Task <IActionResult> Post([FromBody] TripPlannerLoginDTO loginDto)
        {
            if (ModelState.IsValid)
            {
                var appUser = await _context.Users.Include(x => x.UserRoles)
                              .ThenInclude(y => y.Role)
                              .FirstOrDefaultAsync(x => x.Email == loginDto.Username && x.Pwd == loginDto.Password);

                if (appUser == null)
                {
                    return(Unauthorized());
                }

                DateTime           expiry          = DateTime.UtcNow.AddHours(24);
                LoggedinAppUserDTO loggedInAppUser = new LoggedinAppUserDTO {
                    Name  = appUser.Fname + " " + appUser.Lname,
                    Email = appUser.Email,
                    Roles = appUser.UserRoles.Select(x => x.Role).Select(y => y.Name).ToArray(),
                    Id    = appUser.Id
                };
                loggedInAppUser.CurrentTokenExpiry = expiry;
                var token = GetToken(loggedInAppUser, expiry);

                loggedInAppUser.Token = new JwtSecurityTokenHandler().WriteToken(token);

                return(Ok(loggedInAppUser));
            }
            return(BadRequest());
        }
        private JwtSecurityToken GetToken(LoggedinAppUserDTO loggedInAppUser, DateTime expiry)
        {
            var claims = new[]
            {
                new Claim(JwtRegisteredClaimNames.Sub, loggedInAppUser.Email),
                new Claim(ClaimTypes.Role, "AppUser")
            };

            claims.Concat(loggedInAppUser.Roles.Select(x => new Claim(ClaimTypes.Role, x)));
            var token = new JwtSecurityToken
                        (
                issuer: _configuration[WebConfig.TOKEN_ISSUER],
                audience: _configuration[WebConfig.TOKEN_AUDIENCE],
                claims: claims,
                expires: expiry,
                notBefore: DateTime.UtcNow,
                signingCredentials: new SigningCredentials(new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration[WebConfig.TOKEN_SIGNING_KEY])),
                                                           SecurityAlgorithms.HmacSha256)
                        );

            return(token);
        }