Desktop

Local mode

Ship the whole Nuxt app, server modules included, inside the desktop app. It runs offline on a sqlite database in the user's app-data folder.

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.

nuxt.config.ts
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
What you should see: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

  1. The shell starts the sidecar with PORT (desktop.local.port, default 0), HOST=127.0.0.1 and DATA_DIR. The data folder is <app-data folder>/<dataDirName>, for example ~/Library/Application Support/nu.frigear.desk/data on macOS. The window shows a small loading page meanwhile.
  2. 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.1 as the host.
  3. It applies the pending migrations. Requests wait until they are done.
  4. Once it listens and the migrations are applied, it prints exactly READY <port> on stdout. With port 0 the OS picks a free port, so the port in that line is the only reliable one.
  5. The shell reads that line and navigates the main window to http://127.0.0.1:<port>/. If the server exits before it is ready, the loading page shows the exit code.
  6. 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.
  7. If the shell dies without quitting (a crash, a force quit, kill -9), the server stops by itself: the shell sets FRIGEAR_DESKTOP_PARENT_WATCH=1 and holds the server's stdin open, the OS closes it when the shell goes, and the server then runs Nitro's close hooks, 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 bun preset, with public assets inlined (serveStatic: 'inline') and every dependency bundled into one chunk (noExternals, inlineDynamicImports), so .output/server/index.mjs runs on its own. bun build --compile turns it into the executable.
  • Database. libsql loads a native addon, and a compiled binary cannot load one. The module replaces NuxtHub's generated @nuxthub/db client with drizzle's sqlite-proxy over bun:sqlite. The schema stays NuxtHub's, and db.batch works. The client opens $DATA_DIR/app.db with WAL and foreign keys on. This replaces a NuxtHub internal on purpose. A unit test fails when the installed @nuxthub/core changes 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_migrations table, with the same names, so nuxt db commands 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 before READY.

hub.db must use the sqlite dialect.

Data folder

FileWhat it is
app.db (with -wal and -shm)The database.
secrets.jsonThe 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 varWhenUsed for
NUXT_APP_SECRETAlwaysNuxt'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_KEYWith @frigear-nu/oauth-server, not in resource modeSigns 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.

SettingDefaultWhy
authentication.settings.verifyEmailfalseA verification email reaches nobody offline. The build warns when you turn it on.
authentication.settings.trustRequestOrigintrueThe port changes on every start, so emailed links use the request's origin.
authentication.settings.oauth.frigear.handofftrue 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/returnThe deep link the browser's "Signed in" page opens to bring the app forward. NUXT_FRIGEAR_HANDOFF_RETURN_URL overrides it.
hub.kvtrueSign-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
SessionA cookie session on the bundled serverThe issuer's access token on every request
PermissionsAll of them, sessionOnly ones included (assigning roles, managing users, API tokens)sessionOnly permissions answer 403 session_required
OfflineSigned in until the session ends, with no issuer needed after sign-inUntil the access token expires; refreshing needs the issuer
Local accountsPossible next to the issuer (password, passkeys on the bundled server)None: only the issuer's accounts
Auth tablesAuth's tables in the local database, auth_frigear_handoffs includedNone
RenderingSSR on the bundled serverSPA (spa: true)
nuxt.config.ts
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:

nuxt.config.ts (issuer)
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:

  1. 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.
  2. Desktop opens that URL in the system browser with @tauri-apps/plugin-opener (the auth:frigear:open hook).
  3. 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.
  4. 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.

What you should see: "Log in with frigear.nu" opens the system browser. After signing in there, the browser says "Signed in", the app comes to the front, and the window is signed in.

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.

Without @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 } }.
Tested end to end against the compiled server and a stand-in issuer (PKCE checked, no secret sent), not yet in a real Tauri window, with a passkey at frigear.nu, or with the deep link opening the installed app.

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
nuxt.config.ts
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:

nuxt.config.ts (issuer)
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:*'],
    }],
  },
})
What you should see: the app opens on the sign-in page. Signing in opens the system browser, and the deep link brings you back signed in. /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.scheme from appId and 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 sessionOnly permission answers 403 session_required, such as Authorization's roles:assign or Users' users:manage. Give roles with authorization.roles, defaultRoles or the authorization:roles hook. See What a token may do.
  • The SPA shell. Resource mode renders on the client only, so spa defaults to true, and spa: false fails 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 the NUXT_OAUTH_SERVER_PRIVATE_KEY secret. NUXT_APP_SECRET is still generated.
  • The port. With local.port: 0 the origin changes on every start. OAuth Server allows it through http://127.0.0.1:*; an issuer that only takes exact origins needs a fixed local.port and 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), since localStorage follows 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.

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 a Secure and 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 Secure cookie for a URI that is not https, 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'.

OptionTypeDefaultPurpose
binaryNamestring<last segment of appId>-serverThe sidecar's name: src-tauri/binaries/<binaryName>-<triple> and bundle.externalBin.
portnumber0The port. 0 lets the OS pick a free one, read back from READY <port>.
secureCookiebooleanfalsetrue keeps Secure on the session cookie, which WKWebView and WebKitGTK then drop. See The session cookie. Ignored in resource mode.
dataDirNamestringdataThe 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.frontendDist is frigear-loading (the loading page) and bundle.externalBin is ["binaries/<binaryName>"]. Tauri appends the target triple.
  • capabilities/frigear.json adds remote.urls: ["http://127.0.0.1:*"], so the server's pages get the same permissions (window controls, opener, deep links). It grants no shell:* permission: the Rust code starts the sidecar, and the pages cannot start processes.
  • src-tauri/frigear-loading/index.html, which sync owns and rewrites.
  • init also adds tauri-plugin-shell to Cargo.toml, /binaries/ to src-tauri/.gitignore, and an empty beforeBuildCommand, since frigear-desktop build builds 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/me and renders signed-in pages, and keeps its secrets and sessions across restarts. The Rust shell in src/lib.rs is 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 dev opens the window on nuxt dev, with NuxtHub's own database in .data/. Run frigear-desktop sidecar and start the binary yourself to try the bundled server.
Copyright © 2026