Skip to content

Commit

Permalink
Allow Magic.cshtml to Use Magic LInks (#118)
Browse files Browse the repository at this point in the history
* Changing DIY magic links to work with new magic links.
  • Loading branch information
jrmccannon authored Feb 26, 2024
1 parent 6a7c2eb commit 72d00b5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public Magic(PasswordlessClient passwordlessClient,

public bool Success { get; set; }

public async Task<ActionResult> OnGet(string token, string email)
public async Task<ActionResult> OnGet(string token)
{
if (User.Identity is { IsAuthenticated: true }) return RedirectToPage("/Authorized/HelloWorld");

Expand All @@ -30,17 +30,21 @@ public async Task<ActionResult> OnGet(string token, string email)
return Page();
}

var user = await _signInManager.UserManager.FindByEmailAsync(email);
var response = await _passwordlessClient.VerifyAuthenticationTokenAsync(token);

if (user == null || !(await _signInManager.CanSignInAsync(user)))
if (!response.Success)
{
Success = false;
return Page();
}

var response = await _passwordlessClient.VerifyAuthenticationTokenAsync(token);
var user = await _signInManager.UserManager.FindByIdAsync(response.UserId);

if (!response.Success) return Page();
if (user == null || !(await _signInManager.CanSignInAsync(user)))
{
Success = false;
return Page();
}

await _signInManager.SignInAsync(user, true);
Success = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public async Task<IActionResult> OnPostAsync(RecoveryForm form, CancellationToke
var uriBuilder = new UriBuilder(url);
var query = HttpUtility.ParseQueryString(uriBuilder.Query);
query["token"] = token.Token;
query["email"] = user.Email;
uriBuilder.Query = query.ToString();

var message = $"""
Expand Down

0 comments on commit 72d00b5

Please sign in to comment.