C
C#β€’4mo ago
TrattTratt

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
Pobiega
Pobiegaβ€’4mo ago
compare it yourself. You can see the token in the database, and you can see the token in the email/url
TrattTratt
TrattTrattβ€’4mo ago
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
Lebanese Putin
Lebanese Putinβ€’4mo ago
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.
Lebanese Putin
Lebanese Putinβ€’4mo ago
not sure if this helps
TrattTratt
TrattTrattβ€’4mo ago
thanks a lot, ill try it
Lebanese Putin
Lebanese Putinβ€’4mo ago
hope it helps though
TrattTratt
TrattTrattβ€’4mo ago
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
Kao
Kaoβ€’4mo ago
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
Lebanese Putin
Lebanese Putinβ€’4mo ago
πŸ˜‚ πŸ˜‚ good to hear
TrattTratt
TrattTrattβ€’4mo ago
yeah thanks
Want results from more Discord servers?
Add your server
More Posts