diff --git a/samples/BlazorWebAssembly/Pages/Index.razor b/samples/BlazorWebAssembly/Pages/Index.razor
index 623d9ba..bb6f4ae 100644
--- a/samples/BlazorWebAssembly/Pages/Index.razor
+++ b/samples/BlazorWebAssembly/Pages/Index.razor
@@ -10,7 +10,12 @@
Theme="@TurnstileTheme.light"
OnCallback="@TurnstileCallback"
OnErrorCallback="@TurnstileErrorCallback"
- ResponseField="@false" />
+ ResponseField="@false"
+ @ref="turnstile"/>
+
+
Token
@if (_turnstileToken != null)
@@ -23,6 +28,8 @@ else
}
@code {
+ private Turnstile turnstile = default!;
+
private string? _turnstileToken;
private void TurnstileCallback(string token)
@@ -34,4 +41,10 @@ else
{
Console.WriteLine($"Turnstile Error: {message}");
}
+
+ private async void ResetTurnstile()
+ {
+ await turnstile.ResetAsync();
+ }
+
}
diff --git a/src/BlazorTurnstile/Interop.cs b/src/BlazorTurnstile/Interop.cs
index e46c77b..7da51e6 100644
--- a/src/BlazorTurnstile/Interop.cs
+++ b/src/BlazorTurnstile/Interop.cs
@@ -22,6 +22,12 @@ public async ValueTask RenderAsync(
await module.InvokeVoidAsync("render", component, widgetElement, parameters);
}
+ public async ValueTask ResetAsync()
+ {
+ var module = await moduleTask.Value;
+ await module.InvokeVoidAsync("reset");
+ }
+
public async ValueTask DisposeAsync()
{
if (moduleTask.IsValueCreated)
diff --git a/src/BlazorTurnstile/Turnstile.razor b/src/BlazorTurnstile/Turnstile.razor
index f9c9b0c..f6cd44f 100644
--- a/src/BlazorTurnstile/Turnstile.razor
+++ b/src/BlazorTurnstile/Turnstile.razor
@@ -109,6 +109,17 @@
await OnErrorCallback.InvokeAsync(message);
}
+ public async Task ResetAsync()
+ {
+ if (_interop is not null)
+ {
+ Token = null;
+ await TokenChanged.InvokeAsync(Token);
+
+ await _interop.ResetAsync();
+ }
+ }
+
public async ValueTask DisposeAsync()
{
if (_interop is not null)
diff --git a/src/BlazorTurnstile/wwwroot/interop.js b/src/BlazorTurnstile/wwwroot/interop.js
index 57a5cdf..8894b9f 100644
--- a/src/BlazorTurnstile/wwwroot/interop.js
+++ b/src/BlazorTurnstile/wwwroot/interop.js
@@ -5,3 +5,7 @@ export function render(obj, element, parameters) {
turnstile.render(element, parameters);
}
+
+export function reset() {
+ turnstile.reset();
+}