I get Invalid Token at ConfirmEmailAsync(user, token)
I get an error: Invalid Token. Ive tried with and without Encode and decode, what Im I doing wrong?
var token = await _userManager.GenerateEmailConfirmationTokenAsync(viewModel);
token = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(token));
var result = await _userManager.ConfirmEmailAsync(viewModel, token);
10 Replies
compare it yourself. You can see the token in the database, and you can see the token in the email/url
do u mean on the first and last rows? if I hover over them and put a breakpoint they seem to be exaclty the same
Here's an answer I got using Microsoft Copilot, the world's first AI-powered answer engine. Select to see the full answer or try it yourself. https://sl.bing.net/dFypsaacw0G
Bing
What is the Microsoft Copilot? - Bing
Intelligent search from Bing makes it easier to quickly find what youβre looking for and rewards you.
not sure if this helps
thanks a lot, ill try it
hope it helps though
still the same error, I dont understand im not changing the userEntity or anything
this fixed it, I almost got an hearrt attach when I saw the succeded message : var user = await _userManager.FindByEmailAsync(viewModel.Email);
var token = await _userManager.GenerateEmailConfirmationTokenAsync(user); // Ensure you're using the user object
var encodedToken = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(token));
var decodedToken = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(encodedToken));
var result = await _userManager.ConfirmEmailAsync(user, decodedToken);
thanks for the help guys
Pretty sure you can remove the encode/decode part
And yeah I arrived too late to help you but indeed you need the user object not your view model
But if the user is authenticated you can get a user object from the Http Context
Iirc
I worked on that few months ago but don't have the code close to me
π π good to hear
yeah thanks