Local mode
In local mode the desktop app carries its own server. The production build of your Nuxt app (pages, SSR, API routes
and every frigear server module) is compiled with Bun into one executable. The Tauri shell starts it
as a sidecar on 127.0.0.1 and opens the window on it. The app works
offline: data lives in a sqlite file in the user's app-data folder, and users sign in with a cookie session on the
same origin, so no OAuth is involved. To sign in at a remote issuer, see
Sign in at an issuer with server auth (cookie sessions on the bundled
server) or Sign in at a remote issuer (resource mode, tokens).
Set up the module first: Overview.
export default defineNuxtConfig({
modules: ['@nuxthub/core', '@frigear-nu/users', '@frigear-nu/desktop'],
desktop: {
appId: 'nu.frigear.desk',
appName: 'Desk',
mode: 'local',
},
// Auth in server mode, which is the default, or resource mode (see below). Client mode fails the build.
hub: {
db: { dialect: 'sqlite', driver: 'libsql', connection: { url: 'file:./.data/db/sqlite.db' } },
},
})
npx frigear-desktop doctor --fix # also installs Bun in local mode
npx frigear-desktop init # src-tauri/ with the shell plugin and the sidecar code in src/lib.rs
npx frigear-desktop dev # nuxt dev in a Tauri window, without the sidecar
npx frigear-desktop build # nuxt build, the server compiled with Bun, then tauri build
frigear-desktop build writes src-tauri/binaries/<binaryName>-<target triple> before
Tauri bundles. Run that binary with DATA_DIR=/tmp/desk PORT=0 and it prints READY <port>, then serves your app on
http://127.0.0.1:<port>.How it works
- The shell starts the sidecar with
PORT(desktop.local.port, default0),HOST=127.0.0.1andDATA_DIR. The data folder is<app-data folder>/<dataDirName>, for example~/Library/Application Support/nu.frigear.desk/dataon macOS. The window shows a small loading page meanwhile. - Before Nitro reads its runtime config, the server creates the data folder, makes it its working directory, loads
the secrets (see Secrets) and forces
127.0.0.1as the host. - It applies the pending migrations. Requests wait until they are done.
- Once it listens and the migrations are applied, it prints exactly
READY <port>on stdout. With port0the OS picks a free port, so the port in that line is the only reliable one. - The shell reads that line and navigates the
mainwindow tohttp://127.0.0.1:<port>/. If the server exits before it is ready, the loading page shows the exit code. - When the app quits (
RunEvent::Exit), the shell stops the server. Single instance stays on, so a second launch never starts a second server on the same database. - If the shell dies without quitting (a crash, a force quit,
kill -9), the server stops by itself: the shell setsFRIGEAR_DESKTOP_PARENT_WATCH=1and holds the server's stdin open, the OS closes it when the shell goes, and the server then runs Nitro'sclosehooks, closes the database and exits (on Unix also when its parent pid changes). Without that variable (nuxt dev, the binary started by hand) the server ignores stdin.
The generated src-tauri/src/lib.rs holds this code in its local_server module. Like the rest of lib.rs, it is
yours after init.
What the build changes
These changes apply to a production build only (nuxt build, which frigear-desktop build runs). nuxt dev keeps
NuxtHub's own driver, database and migrations.
- One file. It uses the Nitro
bunpreset, with public assets inlined (serveStatic: 'inline') and every dependency bundled into one chunk (noExternals,inlineDynamicImports), so.output/server/index.mjsruns on its own.bun build --compileturns it into the executable. - Database. libsql loads a native addon, and a compiled binary cannot load one. The module replaces NuxtHub's
generated
@nuxthub/dbclient with drizzle'ssqlite-proxyoverbun:sqlite. The schema stays NuxtHub's, anddb.batchworks. The client opens$DATA_DIR/app.dbwith WAL and foreign keys on. This replaces a NuxtHub internal on purpose. A unit test fails when the installed@nuxthub/corechanges it, and a build with a version the module was not checked against prints a warning. - Migrations. In production NuxtHub only migrates at build time, and the database it migrates then is the one on
the build machine. Local mode sets
hub.db.applyMigrationsDuringBuild: false. It bundles NuxtHub's collected migrations (yours and every module's) and applies the pending ones at startup. It records them in NuxtHub's_hub_migrationstable, with the same names, sonuxt dbcommands and the app agree. Each migration runs in a transaction with foreign keys off, as drizzle-kit's table rebuilds need. A failing migration is rolled back and the server exits beforeREADY.
hub.db must use the sqlite dialect.
Data folder
| File | What it is |
|---|---|
app.db (with -wal and -shm) | The database. |
secrets.json | The installation's secrets, mode 0600. |
.data/kv/ | NuxtHub KV (sign-in throttling), from hub.kv's relative default path. Not in resource mode, unless you turn hub.kv on. |
Relative paths the app or NuxtHub bake in resolve inside the data folder, because the server runs there. Deleting the
folder resets the app. Deleting only secrets.json signs every user out, and makes the data encrypted with keys
derived from NUXT_APP_SECRET unreadable (kept OAuth tokens, per-form secrets).
Secrets
On its first start the server generates the secrets the app needs into secrets.json. It then loads them into the
environment on every start:
| Env var | When | Used for |
|---|---|---|
NUXT_APP_SECRET | Always | Nuxt's appSecret: seals the session cookie (nuxt-auth-utils). Module keys, such as the one that encrypts kept OAuth tokens, are derived from it (Secrets). |
NUXT_OAUTH_SERVER_PRIVATE_KEY | With @frigear-nu/oauth-server, not in resource mode | Signs its tokens (a 2048-bit RSA key). |
An env var that is already set wins, so the shell, or you, can pass your own. The server generates the secrets
itself, so the Rust shell needs no crypto crates. An installation an older version set up also has
NUXT_AUTH_TOKENS_KEY in secrets.json, and keeps loading it, so its kept OAuth tokens stay readable.
Offline defaults
With Auth in server mode, local mode sets these defaults. Your own config wins over each of them. Resource mode gets none of them: people sign in at the issuer, which sends the emails and throttles sign-ins.
| Setting | Default | Why |
|---|---|---|
authentication.settings.verifyEmail | false | A verification email reaches nobody offline. The build warns when you turn it on. |
authentication.settings.trustRequestOrigin | true | The port changes on every start, so emailed links use the request's origin. |
authentication.settings.oauth.frigear.handoff | true when you enable the frigear provider | "Log in with frigear.nu" signs in in the system browser. See Sign in at an issuer with server auth. |
runtimeConfig.frigear.handoff.returnUrl | <appId in lowercase>:/auth/return | The deep link the browser's "Signed in" page opens to bring the app forward. NUXT_FRIGEAR_HANDOFF_RETURN_URL overrides it. |
hub.kv | true | Sign-in throttling counts attempts in KV (fs-lite, inside the data folder). Auth turns throttling off under nuxt dev, but the KV is there for your own code. NuxtHub's generated KV client imports unstorage from the app, so add it to the app's dependencies (pnpm add unstorage); the build stops with that hint otherwise. |
authentication.mode must be server, which is the default, or resource. With client the build fails: it has
no server half.
Sign in at an issuer with server auth
Auth stays in server mode: the bundled server keeps its own users and cookie sessions, and "Log in with frigear.nu" signs people in at an issuer, such as your website running OAuth Server. The sign-in happens in the system browser, so passkeys at the issuer work, and the app ships no client secret.
Which one to choose:
| Server auth with the handoff (this section) | Resource mode | |
|---|---|---|
| Session | A cookie session on the bundled server | The issuer's access token on every request |
| Permissions | All of them, sessionOnly ones included (assigning roles, managing users, API tokens) | sessionOnly permissions answer 403 session_required |
| Offline | Signed in until the session ends, with no issuer needed after sign-in | Until the access token expires; refreshing needs the issuer |
| Local accounts | Possible next to the issuer (password, passkeys on the bundled server) | None: only the issuer's accounts |
| Auth tables | Auth's tables in the local database, auth_frigear_handoffs included | None |
| Rendering | SSR on the bundled server | SPA (spa: true) |
export default defineNuxtConfig({
modules: ['@nuxthub/core', '@nuxt/ui', '@frigear-nu/users', '@frigear-nu/desktop'],
desktop: {
appId: 'nu.frigear.desk',
appName: 'Desk',
mode: 'local',
},
authentication: {
settings: {
// Enables the provider. Local mode turns the browser handoff on (`{ handoff: true }`); `{ handoff: false }` keeps
// it off.
oauth: { frigear: true },
pages: { login: true },
},
},
runtimeConfig: {
// The issuer and the public client id (`NUXT_FRIGEAR_SSO_URL`, `NUXT_FRIGEAR_SSO_CLIENT_ID`). No secret.
frigear: { sso: { url: 'https://frigear.nu', clientId: 'desk' } },
},
hub: {
db: { dialect: 'sqlite', driver: 'libsql', connection: { url: 'file:./.data/db/sqlite.db' } },
},
})
The handoff adds the auth_frigear_handoffs table: generate a migration (nuxt db generate) and commit it. The
bundled server applies it on its next start.
Register the app at the issuer as a public client, with the loopback redirect URI and no port. OAuth Server accepts
http://127.0.0.1:<any port>/auth/frigear for it, so the port picked on every start works:
export default defineNuxtConfig({
oauthServer: {
clients: [{
id: 'desk',
name: 'Desk',
// The bundled server's callback, on whatever port it picked.
redirectUris: ['http://127.0.0.1/auth/frigear'],
}],
},
})
The client needs no corsOrigins: the window only calls its own server, the browser reaches the issuer by
navigation, and the bundled server exchanges the code itself.
How it works:
- The sign-in page's frigear.nu button starts an attempt on the bundled server, which answers the issuer's authorize URL (PKCE, with a nonce) and binds the attempt to the window with an httpOnly cookie.
- Desktop opens that URL in the system browser with
@tauri-apps/plugin-opener(theauth:frigear:openhook). - The issuer sends the browser back to
http://127.0.0.1:<port>/auth/frigear. The bundled server exchanges the code and creates or links the user. The browser shows "Signed in" and opens<appId in lowercase>:/auth/return. - That deep link only brings the window to the front: it never navigates and carries nothing. Meanwhile the window polls the attempt, and once it is complete, collects its cookie session.
The full flow and its security notes are on OAuth providers.
Attempts are only accepted by a server reached on 127.0.0.1 from 127.0.0.1 (403 handoff_not_local otherwise).
The bundled server only listens there.
The handoff needs @tauri-apps/plugin-opener and @tauri-apps/plugin-deep-link (required in the manifest, so
frigear-desktop doctor reports them when they are missing). The generated capability already grants the bundled
server's pages the opener, deep-link and window-focus permissions. With deepLinks.schemes: false no scheme is
registered, so there is no return link: the window still signs in, the user switches back by hand.
@tauri-apps/plugin-openernuxt build and nuxt dev fail (nuxt prepare only warns): the sign-in would
fall back to window.open, which does nothing in a Tauri window. Install it (pnpm add @tauri-apps/plugin-opener), or
turn the handoff off with oauth: { frigear: { handoff: false } }.Sign in at a remote issuer
With Auth in resource mode, people sign in at an issuer, such as your website running OAuth Server. The bundled server keeps its own database, users and server modules, and accepts the issuer's access tokens. Use it when the desktop app belongs to accounts that already exist elsewhere, but keeps its data on the machine.
pnpm add @frigear-nu/auth @frigear-nu/oauth-resource @frigear-nu/authorization
export default defineNuxtConfig({
modules: ['@nuxthub/core', '@nuxt/ui', '@frigear-nu/oauth-resource', '@frigear-nu/authorization', '@frigear-nu/desktop'],
desktop: {
appId: 'nu.frigear.desk',
appName: 'Desk',
mode: 'local',
},
authentication: {
mode: 'resource',
client: {
issuer: 'https://frigear.nu',
clientId: 'desk',
scopes: ['openid', 'profile', 'email', 'offline_access'],
// `native.scheme` comes from `appId`: the redirect URI is `nu.frigear.desk:/auth/callback`.
},
},
// The issuer's access tokens, checked against its keys. Without a resolver the build fails.
oauthResource: {
issuer: 'https://frigear.nu',
audience: 'frigear-services',
},
routeRules: {
'/**': { authenticated: true },
},
hub: {
db: { dialect: 'sqlite', driver: 'libsql', connection: { url: 'file:./.data/db/sqlite.db' } },
},
})
@frigear-nu/oauth-resource is required: resource mode accepts only bearer
tokens, and it is the resolver that checks them. It also installs Users.
Register the app at the issuer as a public client. The redirect URI is the deep link, the same as in remote mode:
<appId in lowercase>:/auth/callback. The window calls the issuer from http://127.0.0.1:<port>, on a port picked at
every start, so the client allows the loopback IP on any port for CORS:
export default defineNuxtConfig({
oauthServer: {
accessTokenAudience: 'frigear-services',
clients: [{
id: 'desk',
name: 'Desk',
// The deep link of the desktop app.
redirectUris: ['nu.frigear.desk:/auth/callback'],
// Only accepted under `nuxt dev`: the window loads the app's dev server.
devRedirectUris: ['http://localhost:3000/auth/callback'],
// The bundled server's origin, on whatever port it picked.
corsOrigins: ['http://127.0.0.1:*'],
}],
},
})
/api/... routes of the bundled server answer 401 without a token, and the first
signed-in request creates your user in the local database.What changes compared with server auth:
- Sign-in. It happens in the system browser, and the redirect comes back as a deep link, as in
remote mode. Desktop fills in
client.native.schemefromappIdand registers the scheme. The capability already grants the server's pages the deep-link, opener and store permissions. - No sign-in pages, no cookie sessions. There is no registration, password, passkey or emailed link on the bundled server. Every request carries the access token as a bearer token.
- Session-only permissions are denied. A
sessionOnlypermission answers403 session_required, such as Authorization'sroles:assignor Users'users:manage. Give roles withauthorization.roles,defaultRolesor theauthorization:roleshook. See What a token may do. - The SPA shell. Resource mode renders on the client only, so
spadefaults totrue, andspa: falsefails the build. The bundled server still serves the pages (the SPA shell and its inlined assets) and the API. The loading page and the navigation to the server stay the same. - Not applied: the offline defaults,
secureCookie, and theNUXT_OAUTH_SERVER_PRIVATE_KEYsecret.NUXT_APP_SECRETis still generated. - The port. With
local.port: 0the origin changes on every start. OAuth Server allows it throughhttp://127.0.0.1:*; an issuer that only takes exact origins needs a fixedlocal.portand that origin instead (a fixed port fails to start when another program uses it, so pick an unusual one). The sign-in is kept in the Tauri store (@tauri-apps/plugin-store, required with port 0), sincelocalStoragefollows the origin. - Online sign-in. Signing in needs the issuer. The data and a signed-in session keep working offline until the access token expires; refreshing it needs the issuer again.
The session cookie
Local mode drops Secure from the session cookie (nuxt-auth-utils', Secure by default). WKWebView (macOS) and
WebKitGTK (Linux) refuse a Secure cookie set over http://127.0.0.1, so the session would never come back and
every sign-in would end signed out:
- WKWebView: checked on macOS 26 with a WKWebView loading
http://127.0.0.1:<port>: of aSecureand a plain cookie in one response, only the plain one was stored and sent back. WebKit tracks this as bug 232088 and bug 281149. - WebKitGTK: libsoup's cookie jar refuses to set a
Securecookie for a URI that is nothttps, and never sends one to it. It has no loopback exception. - WebView2 (Chromium): treats loopback as a secure context and is reported to accept it, but that is not checked here.
The server only listens on 127.0.0.1, so the cookie never crosses a network either way. The cookie stays HttpOnly
and SameSite=Lax. The handoff's attempt cookie is never Secure over http.
desktop.local.secureCookie: true keeps Secure, for an app that only ships on Windows. Under
frigear-desktop dev the window loads nuxt dev on http://localhost, where the same applies.
Options
Options go under desktop.local, and only apply with mode: 'local'.
| Option | Type | Default | Purpose |
|---|---|---|---|
binaryName | string | <last segment of appId>-server | The sidecar's name: src-tauri/binaries/<binaryName>-<triple> and bundle.externalBin. |
port | number | 0 | The port. 0 lets the OS pick a free one, read back from READY <port>. |
secureCookie | boolean | false | true keeps Secure on the session cookie, which WKWebView and WebKitGTK then drop. See The session cookie. Ignored in resource mode. |
dataDirName | string | data | The folder inside the app-data folder that holds the database and secrets. |
spa defaults to false in local mode, because the bundled server renders the pages. With Auth in resource mode it
defaults to true.
What the module writes
On top of the remote-mode files:
tauri.conf.json:build.frontendDistisfrigear-loading(the loading page) andbundle.externalBinis["binaries/<binaryName>"]. Tauri appends the target triple.capabilities/frigear.jsonaddsremote.urls: ["http://127.0.0.1:*"], so the server's pages get the same permissions (window controls, opener, deep links). It grants noshell:*permission: the Rust code starts the sidecar, and the pages cannot start processes.src-tauri/frigear-loading/index.html, whichsyncowns and rewrites.initalso addstauri-plugin-shelltoCargo.toml,/binaries/tosrc-tauri/.gitignore, and an emptybeforeBuildCommand, sincefrigear-desktop buildbuilds the server itself.
Prerequisites
Everything remote mode needs, plus Bun on the
build machine. Install it, or set BUN to its path. The app's users do not need Bun: the executable contains it.
Bun cross-compiles, so one machine can build the server for every target:
frigear-desktop sidecar --target x86_64-pc-windows-msvc.
Limitations
- Not tested in a real Tauri window yet. The server side is tested end to end: the compiled binary migrates,
prints
READY, registers, signs in, serves/api/meand renders signed-in pages, and keeps its secrets and sessions across restarts. The Rust shell insrc/lib.rsis not compiled in CI yet. - Webview cookies: WKWebView was checked outside Tauri, WebKitGTK from libsoup's source, WebView2 not at all. See The session cookie.
- Size. The executable is about 70 MB (27 MB gzipped) for the mobile-standalone starter. Startup takes about 0.3 s on a fresh database and 0.2 s after that, on an Apple Silicon Mac. The first start of a freshly signed binary on macOS adds 1 to 2 s for Gatekeeper.
- x86_64 and aarch64 only, on macOS, Windows and Linux. Those are the targets Bun compiles for.
- No sidecar under
dev.frigear-desktop devopens the window onnuxt dev, with NuxtHub's own database in.data/. Runfrigear-desktop sidecarand start the binary yourself to try the bundled server.
CLI
Create and update the Tauri project, run the app in a window, build installers and check your machine.
Maps
A building block for modules that need a place or a layout, such as a location picker, a plane layout editor, web and mobile viewers with live layers, and the schemas and helpers to store the values.