Hi,
I'm currently developing an application using the following stack:
- Backend: ASP.NET Core (.NET 8.0)
- Frontend: Angular (v13.3.0)
In my application, users log in exclusively with a One-Time Password (OTP) sent via email—passwords are not used at any stage. I’ve implemented a custom function to verify the user’s email during the login process using a 6-digit OTP.
After this OTP verification, the user needs to complete two additional steps. Upon completing these steps, I want the user to be logged in automatically. Ideally, the login process should be triggered in the backend method CompleteRegistration.
I attempted to implement this behavior using the following code:
var principal = await _signInManager.CreateUserPrincipalAsync(user);
await _httpContextAccessor.HttpContext.SignInAsync(IdentityConstants.ApplicationScheme, principal);
await _signInManager.SignInAsync(user, isPersistent: false);
However, while this appears to log the user in successfully on the backend, the frontend does not recognize the user as logged in. When the CompleteRegistration process on the frontend is completed and the user is redirected to a protected route, they are sent back to the login page.
Could you please help me ensure that the frontend recognizes the user as logged in after the CompleteRegistration process is complete?
Thank you!
3 Answer(s)
-
0
Hi benjamin.edinger
Are you experiencing this problem when using passwordless login? Related document. If you do not mean a passwordless login, but have logged in without a custom password, can you share with us the changes you made in login.service on the Angular side and Authenticate in TokenAuthController?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi benjamin.edinger
Are you experiencing this problem when using passwordless login? Related document. If you do not mean a passwordless login, but have logged in without a custom password, can you share with us the changes you made in login.service on the Angular side and Authenticate in TokenAuthController?
Haven't made any changes in login.service nor Authenticate in the TokenAuthController.
What I want is that my user instantly gets logged in after the registration process (couple of steps) in my application without any password. But no interaction with the user so additional email with a OTP because the user already entered a EmailConfirmationCode
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi
Do you also set refreshToken, accessToken and signInTokens according to the user's login result so that the user can authenticate? After the OTP has been successfully executed, the login attempt must also be recorded. Here, you can take a similar approach to the TwoFactor authenticate in TokenAuthController. You can enable Two-Factor Login if you want to use OTP.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image)