Convex.Client.Extensions.Clerk.Blazor 3.0.0-alpha

This is a prerelease version of Convex.Client.Extensions.Clerk.Blazor.
The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Convex.Client.Extensions.Clerk.Blazor" Version="3.0.0-alpha" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Convex.Client.Extensions.Clerk.Blazor" Version="3.0.0-alpha" />
                    
Directory.Packages.props
<PackageReference Include="Convex.Client.Extensions.Clerk.Blazor" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Convex.Client.Extensions.Clerk.Blazor --version 3.0.0-alpha
                    
#r "nuget: Convex.Client.Extensions.Clerk.Blazor, 3.0.0-alpha"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Convex.Client.Extensions.Clerk.Blazor@3.0.0-alpha
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Convex.Client.Extensions.Clerk.Blazor&version=3.0.0-alpha&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Convex.Client.Extensions.Clerk.Blazor&version=3.0.0-alpha&prerelease
                    
Install as a Cake Tool

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 - BlazorClerkTokenService included 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

  1. Automatic JavaScript Injection: When BlazorClerkTokenService is first used, it automatically injects the required Clerk JavaScript interop code from embedded resources.

  2. No Manual Setup: You don't need to:

    • Copy JavaScript files to wwwroot
    • Add script tags to index.html
    • Manually configure JavaScript interop
  3. 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:

  1. Remove the clerk.js file from wwwroot/js/
  2. Remove the script tag from index.html
  3. Remove your custom BlazorClerkTokenService implementation
  4. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.