skip to Main Content

I’m testing a webapi that sends email with a link for user verification, I receive the email, but when I click the link, it does not verify the user via the email link, instead I get the below error

No webpage was found for the web address: http://localhost:4000/account/verify-email?token={token}

see below code in controller for the verification

[HttpPost("verify-email")]
        public IActionResult VerifyEmail(VerifyEmailRequest model)
        {
            _accountService.VerifyEmail(model.Token);
            return Ok(new { message = "Verification successful, you can now login" });
        }

see code in services class

public void VerifyEmail(string token)
{
    var account = _context.Accounts.SingleOrDefault(x => x.VerificationToken == token);

    if (account == null) throw new AppException("Verification failed");

    account.Verified = DateTime.UtcNow;
    account.VerificationToken = null;

    _context.Accounts.Update(account);
    _context.SaveChanges();
}

2

Answers


  1. Make sure you have:

    [Route("account")]
    

    At the top

    Login or Signup to reply.
  2. Code true working,
    You need check http://localhost:4000/account/verify-email?token={token} url.

    You send this url. Your project working in Localhost:4000?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search