Convex.Client.Extensions.Clerk.Blazor
3.0.0-alpha
dotnet add package Convex.Client.Extensions.Clerk.Blazor --version 3.0.0-alpha
NuGet\Install-Package Convex.Client.Extensions.Clerk.Blazor -Version 3.0.0-alpha
<PackageReference Include="Convex.Client.Extensions.Clerk.Blazor" Version="3.0.0-alpha" />
<PackageVersion Include="Convex.Client.Extensions.Clerk.Blazor" Version="3.0.0-alpha" />
<PackageReference Include="Convex.Client.Extensions.Clerk.Blazor" />
paket add Convex.Client.Extensions.Clerk.Blazor --version 3.0.0-alpha
#r "nuget: Convex.Client.Extensions.Clerk.Blazor, 3.0.0-alpha"
#:package Convex.Client.Extensions.Clerk.Blazor@3.0.0-alpha
#addin nuget:?package=Convex.Client.Extensions.Clerk.Blazor&version=3.0.0-alpha&prerelease
#tool nuget:?package=Convex.Client.Extensions.Clerk.Blazor&version=3.0.0-alpha&prerelease
Convex.Client.Extensions.Clerk.Blazor
Blazor WebAssembly support for Convex Clerk authentication. Zero-configuration setup with automatic JavaScript injection.
Features
- ✅ Zero Configuration - No manual JavaScript files needed
- ✅ Automatic Injection - Clerk JavaScript interop code is automatically injected
- ✅ One-Line Setup - Single method call to configure everything
- ✅ Default Implementation -
BlazorClerkTokenServiceincluded out of the box
Installation
dotnet add package Convex.Client.Extensions.Clerk.Blazor
Quick Start
1. Add Configuration
Add your Clerk and Convex configuration to appsettings.json:
{
"Clerk": {
"PublishableKey": "pk_test_YOUR_CLERK_PUBLISHABLE_KEY_HERE",
"TokenTemplate": "convex"
},
"Convex": {
"DeploymentUrl": "https://your-deployment.convex.cloud"
}
}
2. Register Services
In your Program.cs, add one line:
using Convex.Client.Extensions.Clerk.Blazor;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
// That's it! One line to set up everything
builder.Services.AddConvexWithClerkForBlazor(
builder.Configuration.GetSection("Clerk"),
builder.Configuration.GetSection("Convex")
);
await builder.Build().RunAsync();
3. Use in Components
Inject BlazorClerkTokenService in your components:
@inject BlazorClerkTokenService ClerkTokenService
@code {
protected override async Task OnInitializedAsync()
{
// Initialize Clerk (automatically injects JavaScript)
await ClerkTokenService.InitializeAsync();
// Check authentication state
if (ClerkTokenService.IsAuthenticated)
{
var userId = await ClerkTokenService.GetUserIdAsync();
var email = await ClerkTokenService.GetUserEmailAsync();
}
}
private async Task SignIn()
{
await ClerkTokenService.OpenSignInAsync();
}
private async Task SignOut()
{
await ClerkTokenService.SignOutAsync();
}
}
How It Works
Automatic JavaScript Injection: When
BlazorClerkTokenServiceis first used, it automatically injects the required Clerk JavaScript interop code from embedded resources.No Manual Setup: You don't need to:
- Copy JavaScript files to
wwwroot - Add script tags to
index.html - Manually configure JavaScript interop
- Copy JavaScript files to
Seamless Integration: The service handles all the complexity of loading and initializing the Clerk SDK.
Advanced Usage
Using Action-Based Configuration
Instead of configuration sections, you can use actions:
builder.Services.AddConvexWithClerkForBlazor(
clerkOptions => {
clerkOptions.PublishableKey = "pk_test_...";
clerkOptions.TokenTemplate = "convex";
},
convexOptions => {
convexOptions.DeploymentUrl = "https://your-app.convex.cloud";
}
);
Custom Token Service
If you need a custom implementation, you can still register your own IClerkTokenService:
builder.Services.AddScoped<IClerkTokenService, MyCustomClerkTokenService>();
builder.Services.AddConvexWithClerkForBlazor(...);
Migration from Manual Setup
If you're currently using the manual setup with clerk.js:
- Remove the
clerk.jsfile fromwwwroot/js/ - Remove the script tag from
index.html - Remove your custom
BlazorClerkTokenServiceimplementation - Replace service registration with
AddConvexWithClerkForBlazor
That's it! Everything else stays the same.
Requirements
- .NET 8.0 or later
- Blazor WebAssembly
- Convex.Client.Extensions.Clerk (automatically included)
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Convex.Client.Extensions.Clerk (>= 3.0.0-alpha)
- Microsoft.AspNetCore.Components.Web (>= 8.0.11)
-
net9.0
- Convex.Client.Extensions.Clerk (>= 3.0.0-alpha)
- Microsoft.AspNetCore.Components.Web (>= 8.0.11)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|
Initial release (0.0.1) of Blazor-specific Clerk authentication package with automatic JavaScript injection for WebAssembly apps. See CHANGELOG.md for full details.