From e22baeaf6e3ea7661798f099a57726fc8cf2db06 Mon Sep 17 00:00:00 2001 From: Jonas Hendrickx Date: Fri, 15 Dec 2023 12:07:48 +0100 Subject: [PATCH] PAS290: Demo example is returning the wrong status code in the response (#97) --- .../Passwordless.Example/PasswordlessController.cs | 5 +++-- examples/Passwordless.Example/wwwroot/client-signin.js | 10 +++++++++- src/Passwordless/PasswordlessApiException.cs | 4 ++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/examples/Passwordless.Example/PasswordlessController.cs b/examples/Passwordless.Example/PasswordlessController.cs index 54d101c..a7ec552 100644 --- a/examples/Passwordless.Example/PasswordlessController.cs +++ b/examples/Passwordless.Example/PasswordlessController.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Net; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; @@ -45,7 +46,7 @@ public async Task GetRegisterToken(string alias) { return new JsonResult(e.Details) { - StatusCode = (int?)e.StatusCode + StatusCode = e.Details.Status }; } } @@ -71,7 +72,7 @@ public async Task VerifySignInToken(string token) { return new JsonResult(e.Details) { - StatusCode = (int?)e.StatusCode + StatusCode = e.Details.Status }; } } diff --git a/examples/Passwordless.Example/wwwroot/client-signin.js b/examples/Passwordless.Example/wwwroot/client-signin.js index 4179911..009bb2a 100644 --- a/examples/Passwordless.Example/wwwroot/client-signin.js +++ b/examples/Passwordless.Example/wwwroot/client-signin.js @@ -28,10 +28,18 @@ async function handleSigninClick(e) { } console.log("Received token", token); + /** * Verify the sign in - Call your node backend to verify the token created from the sign in */ - const user = await fetch(BACKEND_URL + "/verify-signin?token=" + token).then((r) => r.json()); + const userResponse = await fetch(BACKEND_URL + "/verify-signin?token=" + token); + if (!userResponse.ok) { + const userError = await userResponse.json(); + Status("Your backend failed while verifying the token: " + JSON.stringify(userError, null, 2)); + return; + } + + const user = await userResponse.json() /** * Done - you can now check the user result for status, userid etc diff --git a/src/Passwordless/PasswordlessApiException.cs b/src/Passwordless/PasswordlessApiException.cs index ba886fb..9b39cdd 100644 --- a/src/Passwordless/PasswordlessApiException.cs +++ b/src/Passwordless/PasswordlessApiException.cs @@ -1,11 +1,11 @@ +using System; using System.Collections.Generic; -using System.Net.Http; using System.Text.Json; using System.Text.Json.Serialization; namespace Passwordless; -public sealed class PasswordlessApiException : HttpRequestException +public sealed class PasswordlessApiException : Exception { public PasswordlessProblemDetails Details { get; }