tauri-plugin-better-auth 0.1.0 → 0.1.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 +5 -0
- package/dist/client.d.ts +0 -10
- package/dist/client.js +5 -10
- package/dist/{index-DYZxnm2f.d.ts → index-CyIlgWoG.d.ts} +1 -13
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -10
- package/dist/{protocol-Fcr7NzIh.js → protocol-BMPEciOV.js} +1 -2
- package/dist/proxy.d.ts +1 -3
- package/dist/proxy.js +2 -3
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -4,6 +4,11 @@
|
|
|
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)).
|
|
10
|
+
> Keep the npm package and the crate on the same line.
|
|
11
|
+
|
|
7
12
|
This npm package is one half of the plugin. The other half is the Rust crate
|
|
8
13
|
[`tauri-plugin-better-auth`](https://crates.io/crates/tauri-plugin-better-auth).
|
|
9
14
|
Full documentation:
|
package/dist/client.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { UnlistenFn } from "@tauri-apps/api/event";
|
|
2
2
|
import { BetterAuthClientOptions } from "@better-auth/core";
|
|
3
|
-
//#region src/client/commands.d.ts
|
|
4
3
|
/** How the browser hands the sign-in back to the app. */
|
|
5
4
|
type Transport = 'auto' | 'deep-link' | 'loopback';
|
|
6
5
|
/** The signed-in user (Better Auth user object). */
|
|
@@ -60,8 +59,6 @@ export declare function getSession<U = TauriUser>(options?: {
|
|
|
60
59
|
}): Promise<TauriSessionSnapshot<U> | null>;
|
|
61
60
|
/** Signs out locally (always) and on the server (best effort). */
|
|
62
61
|
export declare function signOut(): Promise<void>;
|
|
63
|
-
//#endregion
|
|
64
|
-
//#region src/client/events.d.ts
|
|
65
62
|
/** Why the user is no longer signed in. */
|
|
66
63
|
type SignOutReason = 'user' | 'revoked' | 'expired';
|
|
67
64
|
/** Payload of the error event. */
|
|
@@ -80,8 +77,6 @@ export declare function onSignedOut(callback: (event: {
|
|
|
80
77
|
}) => void): Promise<UnlistenFn>;
|
|
81
78
|
/** Fires when a background sign-in (deep link or loopback) fails. */
|
|
82
79
|
export declare function onAuthError(callback: (error: TauriAuthErrorEvent) => void): Promise<UnlistenFn>;
|
|
83
|
-
//#endregion
|
|
84
|
-
//#region src/client/fetch.d.ts
|
|
85
80
|
/**
|
|
86
81
|
* A `fetch` that sends the request through the plugin's Rust bridge.
|
|
87
82
|
*
|
|
@@ -94,8 +89,6 @@ export declare function onAuthError(callback: (error: TauriAuthErrorEvent) => vo
|
|
|
94
89
|
* `fetch` of your API client. Bodies are buffered (no streaming).
|
|
95
90
|
*/
|
|
96
91
|
export declare const tauriFetch: typeof fetch;
|
|
97
|
-
//#endregion
|
|
98
|
-
//#region src/client/plugin.d.ts
|
|
99
92
|
/**
|
|
100
93
|
* Better Auth client plugin for the Tauri webview. Refreshes `useSession()`
|
|
101
94
|
* when a browser sign-in completes or the session ends, and adds
|
|
@@ -152,8 +145,6 @@ type WithTauri<O extends BetterAuthClientOptions> = Omit<O, 'plugins' | 'fetchOp
|
|
|
152
145
|
* ```
|
|
153
146
|
*/
|
|
154
147
|
export declare function withTauri<O extends BetterAuthClientOptions>(options: O): WithTauri<O>;
|
|
155
|
-
//#endregion
|
|
156
|
-
//#region src/client/types.d.ts
|
|
157
148
|
/**
|
|
158
149
|
* Types that describe a Better Auth client as it behaves inside a Tauri
|
|
159
150
|
* webview: sessions carry no token, and only the operations the Rust bridge
|
|
@@ -228,5 +219,4 @@ type TauriAuthClient<C, ExtraSignIn extends string = never> = Omit<C, 'useSessio
|
|
|
228
219
|
* Runtime no-op: the bridge already enforces all of this.
|
|
229
220
|
*/
|
|
230
221
|
export declare function asTauriClient<C, ExtraSignIn extends string = never>(client: C): TauriAuthClient<C, ExtraSignIn>;
|
|
231
|
-
//#endregion
|
|
232
222
|
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
|
-
|
|
3
|
+
// 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,8 +57,7 @@ function getSession(options = {}) {
|
|
|
57
57
|
function signOut() {
|
|
58
58
|
return call("sign_out");
|
|
59
59
|
}
|
|
60
|
-
|
|
61
|
-
//#region src/client/events.ts
|
|
60
|
+
// src/client/events.ts
|
|
62
61
|
const EVENT_AUTHENTICATED = "better-auth://authenticated";
|
|
63
62
|
const EVENT_SIGNED_OUT = "better-auth://signed-out";
|
|
64
63
|
const EVENT_ERROR = "better-auth://error";
|
|
@@ -74,8 +73,7 @@ function onSignedOut(callback) {
|
|
|
74
73
|
function onAuthError(callback) {
|
|
75
74
|
return listen(EVENT_ERROR, (event) => callback(event.payload));
|
|
76
75
|
}
|
|
77
|
-
|
|
78
|
-
//#region src/client/fetch.ts
|
|
76
|
+
// src/client/fetch.ts
|
|
79
77
|
const NULL_BODY_STATUSES = /* @__PURE__ */ new Set([
|
|
80
78
|
101,
|
|
81
79
|
204,
|
|
@@ -169,8 +167,7 @@ const tauriFetch = async (input, init) => {
|
|
|
169
167
|
signal?.removeEventListener("abort", onAbort);
|
|
170
168
|
}
|
|
171
169
|
};
|
|
172
|
-
|
|
173
|
-
//#region src/client/plugin.ts
|
|
170
|
+
// src/client/plugin.ts
|
|
174
171
|
/**
|
|
175
172
|
* Better Auth client plugin for the Tauri webview. Refreshes `useSession()`
|
|
176
173
|
* when a browser sign-in completes or the session ends, and adds
|
|
@@ -231,8 +228,7 @@ function withTauri(options) {
|
|
|
231
228
|
plugins: [...options.plugins ?? [], tauriClient()]
|
|
232
229
|
};
|
|
233
230
|
}
|
|
234
|
-
|
|
235
|
-
//#region src/client/types.ts
|
|
231
|
+
// src/client/types.ts
|
|
236
232
|
/**
|
|
237
233
|
* Narrows a client created with `withTauri` to {@link TauriAuthClient}.
|
|
238
234
|
* Runtime no-op: the bridge already enforces all of this.
|
|
@@ -240,5 +236,4 @@ function withTauri(options) {
|
|
|
240
236
|
function asTauriClient(client) {
|
|
241
237
|
return client;
|
|
242
238
|
}
|
|
243
|
-
//#endregion
|
|
244
239
|
export { EVENT_AUTHENTICATED, EVENT_ERROR, EVENT_SIGNED_OUT, TauriAuthError, asTauriClient, authenticate, cancelAuth, getSession, isTauriAuthError, onAuthError, onAuthenticated, onSignedOut, requestAuth, signOut, tauriClient, tauriFetch, withTauri };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import "zod";
|
|
2
2
|
import { User } from "better-auth";
|
|
3
|
-
//#region src/types.d.ts
|
|
4
3
|
/** Options of the {@link tauri} server plugin. */
|
|
5
4
|
interface TauriOptions {
|
|
6
5
|
/**
|
|
@@ -44,8 +43,6 @@ interface ResolvedTauriOptions {
|
|
|
44
43
|
max: number;
|
|
45
44
|
} | false;
|
|
46
45
|
}
|
|
47
|
-
//#endregion
|
|
48
|
-
//#region src/error-codes.d.ts
|
|
49
46
|
/**
|
|
50
47
|
* Error codes returned by the `/tauri/*` endpoints. Stable within protocol v1:
|
|
51
48
|
* the Rust plugin and apps switch on `code`, never on `message`.
|
|
@@ -62,8 +59,6 @@ declare const TAURI_ERROR_CODES: {
|
|
|
62
59
|
STATE_MISMATCH: import("better-auth").RawError<"STATE_MISMATCH">;
|
|
63
60
|
USER_NOT_FOUND: import("better-auth").RawError<"USER_NOT_FOUND">;
|
|
64
61
|
};
|
|
65
|
-
//#endregion
|
|
66
|
-
//#region src/protocol.d.ts
|
|
67
62
|
/**
|
|
68
63
|
* Wire protocol v1, shared by the server plugin, the web hand-off client and
|
|
69
64
|
* the Rust plugin. Documented in PROTOCOL.md. Within v1, changes are additive
|
|
@@ -97,8 +92,6 @@ type CallbackTarget = {
|
|
|
97
92
|
kind: 'loopback';
|
|
98
93
|
redirectUri: string;
|
|
99
94
|
};
|
|
100
|
-
//#endregion
|
|
101
|
-
//#region src/routes.d.ts
|
|
102
95
|
/** Response body of `POST /tauri/token`. */
|
|
103
96
|
interface TauriTokenResponse {
|
|
104
97
|
/** Session token, used as `Authorization: Bearer` by the app. */
|
|
@@ -108,15 +101,11 @@ interface TauriTokenResponse {
|
|
|
108
101
|
/** Wire protocol version (see PROTOCOL.md). */
|
|
109
102
|
protocol: typeof PROTOCOL_VERSION;
|
|
110
103
|
}
|
|
111
|
-
//#endregion
|
|
112
|
-
//#region src/version.d.ts
|
|
113
104
|
/**
|
|
114
105
|
* Package version. Released in lockstep with the Rust crate; CI fails when this
|
|
115
106
|
* constant, `package.json` and `Cargo.toml` disagree.
|
|
116
107
|
*/
|
|
117
|
-
declare const VERSION = "0.1.
|
|
118
|
-
//#endregion
|
|
119
|
-
//#region src/index.d.ts
|
|
108
|
+
declare const VERSION = "0.1.1";
|
|
120
109
|
/** What `init` needs from Better Auth's context. */
|
|
121
110
|
interface InitContext {
|
|
122
111
|
hasPlugin(pluginId: string): boolean;
|
|
@@ -288,5 +277,4 @@ declare module '@better-auth/core' {
|
|
|
288
277
|
};
|
|
289
278
|
}
|
|
290
279
|
}
|
|
291
|
-
//#endregion
|
|
292
280
|
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-
|
|
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";
|
|
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-
|
|
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";
|
|
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
|
-
|
|
10
|
+
// 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,8 +24,7 @@ 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
|
-
|
|
28
|
-
//#region src/routes.ts
|
|
27
|
+
// src/routes.ts
|
|
29
28
|
const authorizeBody = z.object({
|
|
30
29
|
client_id: z.string().max(64),
|
|
31
30
|
state: z.string().max(256),
|
|
@@ -150,15 +149,13 @@ const createTokenEndpoint = (opts) => createAuthEndpoint("/tauri/token", {
|
|
|
150
149
|
protocol: 1
|
|
151
150
|
});
|
|
152
151
|
});
|
|
153
|
-
|
|
154
|
-
//#region src/version.ts
|
|
152
|
+
// src/version.ts
|
|
155
153
|
/**
|
|
156
154
|
* Package version. Released in lockstep with the Rust crate; CI fails when this
|
|
157
155
|
* constant, `package.json` and `Cargo.toml` disagree.
|
|
158
156
|
*/
|
|
159
|
-
const VERSION = "0.1.
|
|
160
|
-
|
|
161
|
-
//#region src/index.ts
|
|
157
|
+
const VERSION = "0.1.1";
|
|
158
|
+
// src/index.ts
|
|
162
159
|
function resolveOptions(options = {}) {
|
|
163
160
|
const clientID = assertClientId(options.clientID ?? "tauri");
|
|
164
161
|
const codeExpiresIn = options.codeExpiresIn ?? 300;
|
|
@@ -231,5 +228,4 @@ const tauri = (options) => {
|
|
|
231
228
|
$ERROR_CODES: TAURI_ERROR_CODES
|
|
232
229
|
};
|
|
233
230
|
};
|
|
234
|
-
//#endregion
|
|
235
231
|
export { PROTOCOL_VERSION, TAURI_ERROR_CODES, TauriConfigError, VERSION, isLoopbackRedirectUri, isValidScheme, tauri };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// 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,5 +107,4 @@ 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
|
|
111
110
|
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,6 +1,5 @@
|
|
|
1
|
-
import { i as CallbackTarget, t as tauri } from "./index-
|
|
1
|
+
import { i as CallbackTarget, t as tauri } from "./index-CyIlgWoG.js";
|
|
2
2
|
import { BetterFetch, BetterFetchOption } from "@better-fetch/fetch";
|
|
3
|
-
//#region src/proxy.d.ts
|
|
4
3
|
/** Options of {@link tauriProxyClient}. */
|
|
5
4
|
export interface TauriProxyClientOptions {
|
|
6
5
|
/** Custom URI scheme the app registers, e.g. `"com.example.app"`. */
|
|
@@ -120,5 +119,4 @@ export declare const tauriProxyClient: (options: TauriProxyClientOptions) => {
|
|
|
120
119
|
tauri: TauriProxyActions;
|
|
121
120
|
};
|
|
122
121
|
};
|
|
123
|
-
//#endregion
|
|
124
122
|
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-
|
|
2
|
-
|
|
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
|
|
3
3
|
const QUERY_KEYS = [
|
|
4
4
|
"client_id",
|
|
5
5
|
"state",
|
|
@@ -213,5 +213,4 @@ const tauriProxyClient = (options) => {
|
|
|
213
213
|
}
|
|
214
214
|
};
|
|
215
215
|
};
|
|
216
|
-
//#endregion
|
|
217
216
|
export { tauriProxyClient };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tauri-plugin-better-auth",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Better Auth for Tauri 2: browser sign-in with PKCE, a Rust-held session and a token-free webview.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"auth",
|
|
@@ -63,14 +63,14 @@
|
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@arethetypeswrong/cli": "0.18.5",
|
|
66
|
-
"@better-auth/core": "1.7.
|
|
67
|
-
"@better-fetch/fetch": "1.3.
|
|
66
|
+
"@better-auth/core": "1.7.14",
|
|
67
|
+
"@better-fetch/fetch": "1.3.3",
|
|
68
68
|
"@tauri-apps/api": "2.12.4",
|
|
69
69
|
"@types/node": "24.19.2",
|
|
70
70
|
"@types/pg": "8.23.1",
|
|
71
|
-
"better-auth": "1.7.
|
|
72
|
-
"better-call": "1.4.
|
|
73
|
-
"happy-dom": "21.0.
|
|
71
|
+
"better-auth": "1.7.14",
|
|
72
|
+
"better-call": "1.4.4",
|
|
73
|
+
"happy-dom": "21.0.4",
|
|
74
74
|
"pg": "8.23.1",
|
|
75
75
|
"publint": "0.3.25",
|
|
76
76
|
"tsdown": "0.23.1",
|