tauri-plugin-better-auth 0.1.1 → 0.2.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # tauri-plugin-better-auth
2
2
 
3
- [Better Auth](https://better-auth.com) for [Tauri 2](https://tauri.app). Users
3
+ [Better Auth](https://better-auth.com) for [Tauri 3](https://tauri.app). Users
4
4
  sign in through the system browser with PKCE. The session lives in Rust, and
5
5
  webview code never sees a token.
6
6
 
7
- > **Tauri 2 line (`0.1.x`).** For Tauri 3 (alpha), install
8
- > `tauri-plugin-better-auth@next` and use crate version `0.2.0-alpha.1`
9
- > ([`v3` branch](https://github.com/laakal/tauri-plugin-better-auth/tree/v3)).
7
+ > **Tauri 3 line (`0.2.x` pre-releases).** For Tauri 2, install
8
+ > `tauri-plugin-better-auth@latest` and use crate version `0.1`
9
+ > ([`main` branch](https://github.com/laakal/tauri-plugin-better-auth)).
10
10
  > Keep the npm package and the crate on the same line.
11
11
 
12
12
  This npm package is one half of the plugin. The other half is the Rust crate
@@ -51,5 +51,6 @@ const authClient = asTauriClient(
51
51
  await requestAuth();
52
52
  ```
53
53
 
54
- Requires `better-auth` >= 1.7.4 and, for `/client`, `@tauri-apps/api` >= 2.11.
54
+ Requires `better-auth` >= 1.7.4 and, for `/client`, `@tauri-apps/api` 3 (alpha). For Tauri 2,
55
+ use `0.1.x`.
55
56
  MIT licensed.
package/dist/client.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { UnlistenFn } from "@tauri-apps/api/event";
2
2
  import { BetterAuthClientOptions } from "@better-auth/core";
3
+ //#region src/client/commands.d.ts
3
4
  /** How the browser hands the sign-in back to the app. */
4
5
  type Transport = 'auto' | 'deep-link' | 'loopback';
5
6
  /** The signed-in user (Better Auth user object). */
@@ -59,6 +60,8 @@ export declare function getSession<U = TauriUser>(options?: {
59
60
  }): Promise<TauriSessionSnapshot<U> | null>;
60
61
  /** Signs out locally (always) and on the server (best effort). */
61
62
  export declare function signOut(): Promise<void>;
63
+ //#endregion
64
+ //#region src/client/events.d.ts
62
65
  /** Why the user is no longer signed in. */
63
66
  type SignOutReason = 'user' | 'revoked' | 'expired';
64
67
  /** Payload of the error event. */
@@ -77,6 +80,8 @@ export declare function onSignedOut(callback: (event: {
77
80
  }) => void): Promise<UnlistenFn>;
78
81
  /** Fires when a background sign-in (deep link or loopback) fails. */
79
82
  export declare function onAuthError(callback: (error: TauriAuthErrorEvent) => void): Promise<UnlistenFn>;
83
+ //#endregion
84
+ //#region src/client/fetch.d.ts
80
85
  /**
81
86
  * A `fetch` that sends the request through the plugin's Rust bridge.
82
87
  *
@@ -89,6 +94,8 @@ export declare function onAuthError(callback: (error: TauriAuthErrorEvent) => vo
89
94
  * `fetch` of your API client. Bodies are buffered (no streaming).
90
95
  */
91
96
  export declare const tauriFetch: typeof fetch;
97
+ //#endregion
98
+ //#region src/client/plugin.d.ts
92
99
  /**
93
100
  * Better Auth client plugin for the Tauri webview. Refreshes `useSession()`
94
101
  * when a browser sign-in completes or the session ends, and adds
@@ -145,6 +152,8 @@ type WithTauri<O extends BetterAuthClientOptions> = Omit<O, 'plugins' | 'fetchOp
145
152
  * ```
146
153
  */
147
154
  export declare function withTauri<O extends BetterAuthClientOptions>(options: O): WithTauri<O>;
155
+ //#endregion
156
+ //#region src/client/types.d.ts
148
157
  /**
149
158
  * Types that describe a Better Auth client as it behaves inside a Tauri
150
159
  * webview: sessions carry no token, and only the operations the Rust bridge
@@ -219,4 +228,5 @@ type TauriAuthClient<C, ExtraSignIn extends string = never> = Omit<C, 'useSessio
219
228
  * Runtime no-op: the bridge already enforces all of this.
220
229
  */
221
230
  export declare function asTauriClient<C, ExtraSignIn extends string = never>(client: C): TauriAuthClient<C, ExtraSignIn>;
231
+ //#endregion
222
232
  export type { RequestAuthOptions, RequestAuthResult, SignOutReason, TauriAuthClient, TauriAuthErrorEvent, TauriSessionSnapshot, TauriSignInMethod, TauriUnsupportedAction, TauriUser, Tokenless, Transport, WithTauri };
package/dist/client.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { invoke, isTauri } from "@tauri-apps/api/core";
2
2
  import { listen } from "@tauri-apps/api/event";
3
- // src/client/commands.ts
3
+ //#region src/client/commands.ts
4
4
  /** Error raised by the plugin commands; `code` is stable (see the README). */
5
5
  var TauriAuthError = class extends Error {
6
6
  code;
@@ -57,7 +57,8 @@ function getSession(options = {}) {
57
57
  function signOut() {
58
58
  return call("sign_out");
59
59
  }
60
- // src/client/events.ts
60
+ //#endregion
61
+ //#region src/client/events.ts
61
62
  const EVENT_AUTHENTICATED = "better-auth://authenticated";
62
63
  const EVENT_SIGNED_OUT = "better-auth://signed-out";
63
64
  const EVENT_ERROR = "better-auth://error";
@@ -73,7 +74,8 @@ function onSignedOut(callback) {
73
74
  function onAuthError(callback) {
74
75
  return listen(EVENT_ERROR, (event) => callback(event.payload));
75
76
  }
76
- // src/client/fetch.ts
77
+ //#endregion
78
+ //#region src/client/fetch.ts
77
79
  const NULL_BODY_STATUSES = /* @__PURE__ */ new Set([
78
80
  101,
79
81
  204,
@@ -167,7 +169,8 @@ const tauriFetch = async (input, init) => {
167
169
  signal?.removeEventListener("abort", onAbort);
168
170
  }
169
171
  };
170
- // src/client/plugin.ts
172
+ //#endregion
173
+ //#region src/client/plugin.ts
171
174
  /**
172
175
  * Better Auth client plugin for the Tauri webview. Refreshes `useSession()`
173
176
  * when a browser sign-in completes or the session ends, and adds
@@ -228,7 +231,8 @@ function withTauri(options) {
228
231
  plugins: [...options.plugins ?? [], tauriClient()]
229
232
  };
230
233
  }
231
- // src/client/types.ts
234
+ //#endregion
235
+ //#region src/client/types.ts
232
236
  /**
233
237
  * Narrows a client created with `withTauri` to {@link TauriAuthClient}.
234
238
  * Runtime no-op: the bridge already enforces all of this.
@@ -236,4 +240,5 @@ function withTauri(options) {
236
240
  function asTauriClient(client) {
237
241
  return client;
238
242
  }
243
+ //#endregion
239
244
  export { EVENT_AUTHENTICATED, EVENT_ERROR, EVENT_SIGNED_OUT, TauriAuthError, asTauriClient, authenticate, cancelAuth, getSession, isTauriAuthError, onAuthError, onAuthenticated, onSignedOut, requestAuth, signOut, tauriClient, tauriFetch, withTauri };
@@ -1,5 +1,6 @@
1
1
  import "zod";
2
2
  import { User } from "better-auth";
3
+ //#region src/types.d.ts
3
4
  /** Options of the {@link tauri} server plugin. */
4
5
  interface TauriOptions {
5
6
  /**
@@ -43,6 +44,8 @@ interface ResolvedTauriOptions {
43
44
  max: number;
44
45
  } | false;
45
46
  }
47
+ //#endregion
48
+ //#region src/error-codes.d.ts
46
49
  /**
47
50
  * Error codes returned by the `/tauri/*` endpoints. Stable within protocol v1:
48
51
  * the Rust plugin and apps switch on `code`, never on `message`.
@@ -59,6 +62,8 @@ declare const TAURI_ERROR_CODES: {
59
62
  STATE_MISMATCH: import("better-auth").RawError<"STATE_MISMATCH">;
60
63
  USER_NOT_FOUND: import("better-auth").RawError<"USER_NOT_FOUND">;
61
64
  };
65
+ //#endregion
66
+ //#region src/protocol.d.ts
62
67
  /**
63
68
  * Wire protocol v1, shared by the server plugin, the web hand-off client and
64
69
  * the Rust plugin. Documented in PROTOCOL.md. Within v1, changes are additive
@@ -92,6 +97,8 @@ type CallbackTarget = {
92
97
  kind: 'loopback';
93
98
  redirectUri: string;
94
99
  };
100
+ //#endregion
101
+ //#region src/routes.d.ts
95
102
  /** Response body of `POST /tauri/token`. */
96
103
  interface TauriTokenResponse {
97
104
  /** Session token, used as `Authorization: Bearer` by the app. */
@@ -101,11 +108,15 @@ interface TauriTokenResponse {
101
108
  /** Wire protocol version (see PROTOCOL.md). */
102
109
  protocol: typeof PROTOCOL_VERSION;
103
110
  }
111
+ //#endregion
112
+ //#region src/version.d.ts
104
113
  /**
105
114
  * Package version. Released in lockstep with the Rust crate; CI fails when this
106
115
  * constant, `package.json` and `Cargo.toml` disagree.
107
116
  */
108
- declare const VERSION = "0.1.1";
117
+ declare const VERSION = "0.2.0-alpha.1";
118
+ //#endregion
119
+ //#region src/index.d.ts
109
120
  /** What `init` needs from Better Auth's context. */
110
121
  interface InitContext {
111
122
  hasPlugin(pluginId: string): boolean;
@@ -277,4 +288,5 @@ declare module '@better-auth/core' {
277
288
  };
278
289
  }
279
290
  }
291
+ //#endregion
280
292
  export { PROTOCOL_VERSION as a, isValidScheme as c, TauriOptions as d, CallbackTarget as i, TAURI_ERROR_CODES as l, VERSION as n, TauriConfigError as o, TauriTokenResponse as r, isLoopbackRedirectUri as s, tauri as t, ResolvedTauriOptions as u };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as PROTOCOL_VERSION, c as isValidScheme, d as TauriOptions, l as TAURI_ERROR_CODES, n as VERSION, o as TauriConfigError, r as TauriTokenResponse, s as isLoopbackRedirectUri, t as tauri, u as ResolvedTauriOptions } from "./index-CyIlgWoG.js";
1
+ import { a as PROTOCOL_VERSION, c as isValidScheme, d as TauriOptions, l as TAURI_ERROR_CODES, n as VERSION, o as TauriConfigError, r as TauriTokenResponse, s as isLoopbackRedirectUri, t as tauri, u as ResolvedTauriOptions } from "./index-DZZMJtAS.js";
2
2
  export { PROTOCOL_VERSION, type ResolvedTauriOptions, TAURI_ERROR_CODES, TauriConfigError, type TauriOptions, type TauriTokenResponse, VERSION, isLoopbackRedirectUri, isValidScheme, tauri };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as CODE_VERIFIER_PATTERN, c as PROTOCOL_VERSION, d as TauriConfigError, f as assertClientId, g as isValidScheme, h as isLoopbackRedirectUri, i as CODE_PATTERN, n as CODE_CHALLENGE_PATTERN, r as CODE_IDENTIFIER_PREFIX, u as STATE_PATTERN } from "./protocol-BMPEciOV.js";
1
+ import { a as CODE_VERIFIER_PATTERN, c as PROTOCOL_VERSION, d as TauriConfigError, f as assertClientId, g as isValidScheme, h as isLoopbackRedirectUri, i as CODE_PATTERN, n as CODE_CHALLENGE_PATTERN, r as CODE_IDENTIFIER_PREFIX, u as STATE_PATTERN } from "./protocol-Fcr7NzIh.js";
2
2
  import { defineErrorCodes } from "@better-auth/core/utils/error-codes";
3
3
  import { APIError } from "@better-auth/core/error";
4
4
  import { createAuthEndpoint, sensitiveSessionMiddleware } from "better-auth/api";
@@ -7,7 +7,7 @@ import { constantTimeEqual, generateRandomString } from "better-auth/crypto";
7
7
  import { parseUserOutput } from "better-auth/db";
8
8
  import { generateCodeChallenge } from "better-auth/oauth2";
9
9
  import * as z from "zod";
10
- // src/error-codes.ts
10
+ //#region src/error-codes.ts
11
11
  /**
12
12
  * Error codes returned by the `/tauri/*` endpoints. Stable within protocol v1:
13
13
  * the Rust plugin and apps switch on `code`, never on `message`.
@@ -24,7 +24,8 @@ const TAURI_ERROR_CODES = defineErrorCodes({
24
24
  USER_NOT_FOUND: "The user for this authorization no longer exists",
25
25
  SESSION_REJECTED: "The server rejected the new session"
26
26
  });
27
- // src/routes.ts
27
+ //#endregion
28
+ //#region src/routes.ts
28
29
  const authorizeBody = z.object({
29
30
  client_id: z.string().max(64),
30
31
  state: z.string().max(256),
@@ -149,13 +150,15 @@ const createTokenEndpoint = (opts) => createAuthEndpoint("/tauri/token", {
149
150
  protocol: 1
150
151
  });
151
152
  });
152
- // src/version.ts
153
+ //#endregion
154
+ //#region src/version.ts
153
155
  /**
154
156
  * Package version. Released in lockstep with the Rust crate; CI fails when this
155
157
  * constant, `package.json` and `Cargo.toml` disagree.
156
158
  */
157
- const VERSION = "0.1.1";
158
- // src/index.ts
159
+ const VERSION = "0.2.0-alpha.1";
160
+ //#endregion
161
+ //#region src/index.ts
159
162
  function resolveOptions(options = {}) {
160
163
  const clientID = assertClientId(options.clientID ?? "tauri");
161
164
  const codeExpiresIn = options.codeExpiresIn ?? 300;
@@ -228,4 +231,5 @@ const tauri = (options) => {
228
231
  $ERROR_CODES: TAURI_ERROR_CODES
229
232
  };
230
233
  };
234
+ //#endregion
231
235
  export { PROTOCOL_VERSION, TAURI_ERROR_CODES, TauriConfigError, VERSION, isLoopbackRedirectUri, isValidScheme, tauri };
@@ -1,4 +1,4 @@
1
- // src/protocol.ts
1
+ //#region src/protocol.ts
2
2
  /**
3
3
  * Wire protocol v1, shared by the server plugin, the web hand-off client and
4
4
  * the Rust plugin. Documented in PROTOCOL.md. Within v1, changes are additive
@@ -107,4 +107,5 @@ function buildCallbackUrl(target, params) {
107
107
  if (target.kind === "loopback") return `${target.redirectUri}?${search}`;
108
108
  return `${target.scheme}://${target.callbackPath.slice(1)}?${search}`;
109
109
  }
110
+ //#endregion
110
111
  export { normalizeCallbackPath as _, CODE_VERIFIER_PATTERN as a, PROTOCOL_VERSION as c, TauriConfigError as d, assertClientId as f, isValidScheme as g, isLoopbackRedirectUri as h, CODE_PATTERN as i, PROVIDER_PATTERN as l, buildCallbackUrl as m, CODE_CHALLENGE_PATTERN as n, DEFAULT_CALLBACK_PATH as o, assertScheme as p, CODE_IDENTIFIER_PREFIX as r, DEFAULT_CLIENT_ID as s, CLIENT_ID_PATTERN as t, STATE_PATTERN as u };
package/dist/proxy.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { i as CallbackTarget, t as tauri } from "./index-CyIlgWoG.js";
1
+ import { i as CallbackTarget, t as tauri } from "./index-DZZMJtAS.js";
2
2
  import { BetterFetch, BetterFetchOption } from "@better-fetch/fetch";
3
+ //#region src/proxy.d.ts
3
4
  /** Options of {@link tauriProxyClient}. */
4
5
  export interface TauriProxyClientOptions {
5
6
  /** Custom URI scheme the app registers, e.g. `"com.example.app"`. */
@@ -119,4 +120,5 @@ export declare const tauriProxyClient: (options: TauriProxyClientOptions) => {
119
120
  tauri: TauriProxyActions;
120
121
  };
121
122
  };
123
+ //#endregion
122
124
  export type { CallbackTarget };
package/dist/proxy.js CHANGED
@@ -1,5 +1,5 @@
1
- import { _ as normalizeCallbackPath, f as assertClientId, h as isLoopbackRedirectUri, l as PROVIDER_PATTERN, m as buildCallbackUrl, n as CODE_CHALLENGE_PATTERN, p as assertScheme, t as CLIENT_ID_PATTERN, u as STATE_PATTERN } from "./protocol-BMPEciOV.js";
2
- // src/proxy.ts
1
+ import { _ as normalizeCallbackPath, f as assertClientId, h as isLoopbackRedirectUri, l as PROVIDER_PATTERN, m as buildCallbackUrl, n as CODE_CHALLENGE_PATTERN, p as assertScheme, t as CLIENT_ID_PATTERN, u as STATE_PATTERN } from "./protocol-Fcr7NzIh.js";
2
+ //#region src/proxy.ts
3
3
  const QUERY_KEYS = [
4
4
  "client_id",
5
5
  "state",
@@ -213,4 +213,5 @@ const tauriProxyClient = (options) => {
213
213
  }
214
214
  };
215
215
  };
216
+ //#endregion
216
217
  export { tauriProxyClient };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tauri-plugin-better-auth",
3
- "version": "0.1.1",
4
- "description": "Better Auth for Tauri 2: browser sign-in with PKCE, a Rust-held session and a token-free webview.",
3
+ "version": "0.2.0-alpha.1",
4
+ "description": "Better Auth for Tauri 3: browser sign-in with PKCE, a Rust-held session and a token-free webview.",
5
5
  "keywords": [
6
6
  "auth",
7
7
  "authentication",
@@ -49,7 +49,8 @@
49
49
  },
50
50
  "publishConfig": {
51
51
  "access": "public",
52
- "provenance": true
52
+ "provenance": true,
53
+ "tag": "next"
53
54
  },
54
55
  "scripts": {
55
56
  "build": "tsdown",
@@ -65,7 +66,7 @@
65
66
  "@arethetypeswrong/cli": "0.18.5",
66
67
  "@better-auth/core": "1.7.14",
67
68
  "@better-fetch/fetch": "1.3.3",
68
- "@tauri-apps/api": "2.12.4",
69
+ "@tauri-apps/api": "3.0.0-alpha.3",
69
70
  "@types/node": "24.19.2",
70
71
  "@types/pg": "8.23.1",
71
72
  "better-auth": "1.7.14",
@@ -80,7 +81,7 @@
80
81
  "peerDependencies": {
81
82
  "@better-auth/core": ">=1.7.4 <2",
82
83
  "@better-fetch/fetch": "^1.3.1",
83
- "@tauri-apps/api": ">=2.11.0 <3",
84
+ "@tauri-apps/api": ">=3.0.0-alpha.0 <4",
84
85
  "better-auth": ">=1.7.4 <2",
85
86
  "better-call": "^1.4.0"
86
87
  },