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