< Summary - Syki

Information
Class: Syki.Back.Features.Cross.Login.LoginService
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Cross/Login/LoginService.cs
Tag: 21_17346963026
Line coverage
100%
Covered lines: 22
Uncovered lines: 0
Coverable lines: 22
Total lines: 36
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Login()100%66100%

File(s)

/home/runner/work/syki/syki/Back/Features/Cross/Login/LoginService.cs

#LineLine coverage
 1using System.IdentityModel.Tokens.Jwt;
 2using Syki.Back.Features.Cross.CreateUser;
 3using Syki.Back.Features.Cross.GenerateJWT;
 4
 5namespace Syki.Back.Features.Cross.Login;
 6
 9567public class LoginService(GenerateJWTService service, SignInManager<SykiUser> signInManager) : ICrossService
 8{
 9    public async Task<OneOf<LoginOut, SykiError>> Login(LoginIn data)
 10    {
 95611        var result = await signInManager.PasswordSignInAsync(
 95612            userName: data.Email,
 95613            password: data.Password,
 95614            isPersistent: false,
 95615            lockoutOnFailure: false
 95616        );
 17
 95618        if (!result.Succeeded && !result.RequiresTwoFactor)
 819            return new LoginWrongEmailOrPassword();
 20
 94821        if (result.RequiresTwoFactor)
 622            return new LoginRequiresTwoFactor();
 23
 94224        var jwt = await service.Generate(data.Email);
 94225        var claims = new JwtSecurityToken(jwt).Claims.ToList();
 26
 94227        return new LoginOut
 94228        {
 94229            AccessToken = jwt,
 376830            Name = claims.First(x => x.Type == "name").Value,
 471031            Email = claims.First(x => x.Type == "email").Value,
 188432            Id = Guid.Parse(claims.First(x => x.Type == "sub").Value),
 282633            Role = Enum.Parse<UserRole>(claims.First(x => x.Type == "role").Value),
 94234        };
 95635    }
 36}