npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@daveyplate/better-auth-tauri

v0.1.6

Published

Better Auth Tauri Plugin

Downloads

509

Readme

Better Auth Tauri Plugin

A plugin for Better Auth that provides seamless integration with Tauri applications.

Installation

# npm
npm install @daveyplate/better-auth-tauri

# pnpm
pnpm add @daveyplate/better-auth-tauri

# yarn
yarn add @daveyplate/better-auth-tauri

# bun
bun add @daveyplate/better-auth-tauri

Prerequisites

This plugin requires the following Tauri plugins:

  • @tauri-apps/plugin-deep-link
  • @tauri-apps/plugin-http
  • @tauri-apps/plugin-os

Make sure these are installed and properly configured in your Tauri application.

Server Setup

1. Configure the Tauri Plugin in your auth.ts file

import { betterAuth } from "better-auth";
import { tauri } from "@daveyplate/better-auth-tauri/plugin";

export const auth = betterAuth({
  // Your existing Better Auth configuration
  plugins: [
    // Your existing plugins
    tauri({
      scheme: "your-app", // Your app's deep link scheme
      callbackURL: "/", // Optional: Where to redirect after auth (default: "/")
      successText: "Authentication successful! You can close this window.", // Optional
      successURL: "/auth/success", // Optional: Custom success page URL that will receive a ?redirectTo search parameter
      debugLogs: false, // Optional: Enable debug logs
    }),
  ],
});

2. Register the Deep Link Scheme in Tauri

In your tauri.conf.json file, add your deep link scheme:

{
    "plugins": {
        "deep-link": {
            "desktop": {
                "schemes": ["my-app"]
            }
        }
    }
}

Client Setup

Option 1: Standard JavaScript/TypeScript Setup

import { setupBetterAuthTauri } from "@daveyplate/better-auth-tauri";
import { authClient } from "./your-auth-client";

// Initialize in your app's entry point
setupBetterAuthTauri({
  authClient, // Your Better Auth client instance
  scheme: "your-app", // Must match the scheme in your server config
  debugLogs: false, // Optional: Enable debug logs
  mainWindowLabel: "main", // Optional: Your main window label (default: "main")
  onRequest: (href) => {
    console.log("Auth request:", href);
  },
  onSuccess: (callbackURL) => {
    console.log("Auth successful, callback URL:", callbackURL);
    // Handle successful authentication
    window.location.href = callbackURL
  },
  onError: (error) => {
    console.error("Auth error:", error);
    // Handle authentication error
  },
});

Option 2: React Setup

import { useBetterAuthTauri } from "@daveyplate/better-auth-tauri/react";
import { authClient } from "./your-auth-client";

function App() {
  useBetterAuthTauri({
    authClient,
    scheme: "your-app",
    debugLogs: false,
    onRequest: (href) => {
      console.log("Auth request:", href);
    },
    onSuccess: (callbackURL) => {
      console.log("Auth successful");
      // Navigate or update UI as needed
    },
    onError: (error) => {
      console.error("Auth error:", error);
      // Show error notification
    },
  });

  return (
    // Your app components
  );
}

Option 3: Svelte Setup

<script>
  import { onMount, onDestroy } from "svelte";
  import { setupBetterAuthTauri } from "@daveyplate/better-auth-tauri";
  import { authClient } from "./your-auth-client";
  
  let cleanup;
  
  onMount(() => {
    cleanup = setupBetterAuthTauri({
      authClient,
      scheme: "your-app",
      debugLogs: false,
      onRequest: (href) => {
        console.log("Auth request:", href);
      },
      onSuccess: (callbackURL) => {
        console.log("Auth successful");
        // Update your app state

        goto(callbackURL)
      },
      onError: (error) => {
        console.error("Auth error:", error);
        // Show error notification
      },
    });
  });
  
  onDestroy(() => {
    cleanup?.();
  });
</script>

Social Sign In

First install the official Tauri Opener plugin: https://v2.tauri.app/plugin/opener/

To properly use Social Sign in with the Opener plugin we provide a helper function:

import { signInSocial } from "@daveyplate/better-auth-tauri"
import { authClient } from "@/lib/auth-client"

export function Page() {
  return (
    <button onClick={() => {
      signInSocial({
        authClient,
        provider: "google"
      })
    }}>
      Sign in with Google
    </button>
  )
}

macOS Cookies

You must update your auth-client.ts to use Tauri HTTP plugin for macOS in production in order for cookies to work:

import { isTauri } from "@tauri-apps/api/core"
import { fetch as tauriFetch } from "@tauri-apps/plugin-http"
import { platform } from "@tauri-apps/plugin-os"
import { createAuthClient } from "better-auth/react"

export const authClient = createAuthClient({
    fetchOptions: {
        customFetchImpl: (...params) =>
            isTauri() && platform() === "macos" && window.location.protocol === "tauri:"
                ? tauriFetch(...params)
                : fetch(...params)
    }
})

How It Works

This plugin enables seamless authentication in Tauri apps by:

  1. Handling Deep Links: Properly processes authentication redirects through your app's custom URL scheme.
  2. Managing Authentication State: Ensures that your app's auth state remains consistent across the authentication flow.
  3. Simplifying Tauri Integration: Removes the boilerplate needed to make authentication work in desktop applications.

License

MIT