When a function has auth_level: "user" or an LLM service uses user_pays billing, the app needs signed-in users. There are two kinds, and the app's sign-in mode picks which (gipity project auth gipity|app|both):
- Gipity accounts (
gipity, the default): people sign in with Gipity and grant the app access. One identity across every Gipity app, anduser_paysservices can bill their own credits. Right for your own tools, internal tools, and AI apps where users should pay for their AI use. - App users (
app): people sign in to this app only with Google, Discord, Apple, a 6-digit email code, or (games) Steam or a guest device. The app owns them: no Gipity account, no consent screen, your branding. Right for anything you put in front of the public. See "App users" below.
Ask once when you add sign-in: is it for you, or for the public? The choice is sticky (moving existing users from one kind to the other is a migration), so don't flip it casually later. Both kinds use the same client code (Gipity.auth), and functions see both as ctx.auth.userGuid.
The auth_level gate runs at the platform, before your handler. An auth_level: "user" (or "member") function called without a signed-in user is rejected with 401 LOGIN_REQUIRED before your code executes - ctx.auth is only ever populated inside the handler, so a signed-out caller never reaches it. Two consequences: (1) don't write a if (!ctx.auth?.userGuid) return { error: 'Sign in required' } guard for the unauthenticated case - it's dead code the platform already handles (inside the handler you can assume ctx.auth.userGuid is set). (2) A test that calls the function logged-out must assert the rejection (ctx.fn.call throws / the call 401s), not a returned error string - use ctx.fn.callAs(ctx.users.alice, ...) to exercise the signed-in path (the harness provides ctx.users.alice, bob and owner; an invented id fails with "Unknown or unavailable test user"). Reserve in-handler checks for finer authorization (e.g. "is this row mine?"), which the gate can't express.
Personal-data apps need auth even when nothing is paid. If the request implies user-private data - "my receipts", a personal vault, private notes, anything storing a user's own uploads or records - default to per-user scoping: gate writes behind sign-in and key every row to ctx.auth.userGuid (the stable external id - not the internal numeric userId; see "Using auth" in app-development), then filter listings to that user. A "my X" app that's readable and deletable by anyone with the URL is a privacy hole. If you intentionally ship a public or shared version instead, say so explicitly in your summary so the user can decide (see "Personal data defaults to per-user scoping" in web-app-basics).
Client code: the sign-in button
Web apps sign people in with the Gipity client SDK: Gipity.auth.signIn() on a click (it opens the popup synchronously and drives login and consent), Gipity.auth.user() to read who is signed in, Gipity.auth.signOut(). The SDK setup, popup vs redirect, verifying sign-in with page inspect --auth, sign-out, and the low-level REST flow (app token, auth/status, common mistakes) are in app-auth-client. Load it before writing sign-in code.
App users: sign-in without a Gipity account
With gipity project auth app, people sign in to this app only (Google, Discord, Apple, an email code; Steam or a guest device for games) and the app owns them. Gipity.auth.signIn() / user() / signOut() work unchanged; functions get ctx.auth.identity = { provider, id, email }. Providers and your own credentials, account linking, the user_created / user_deleted hooks, managing users with gipity project users, and the native-client endpoints are in app-users.
Private pages: only signed-in people can load the app
Sign-in in the app's code hides data, but the HTML, JS and images are still public files. To keep the whole site private (every page and asset, also on a custom domain), add an access: block to gipity.yaml:
access:
mode: app-users # or members: you and project members, signed in with Gipity
emails: ["@acme.com"] # optional allowlist
A visitor without access gets the sign-in page (the app's own one for app-users, Sign in with Gipity for members) and lands back on the page they opened. Your client code doesn't change: the visitor is already signed in when the app loads, so Gipity.auth.user() returns them. Details, per-environment settings and limits are in deploy.
API keys for scripts and agents
Sessions are for people. A script, cron job, device, or agent authenticates with a project API key (gipity key create "laptop-script" --role editor, sent as X-Api-Key or Authorization: Bearer). Never build your own api_keys table. Keys can be scoped to named functions, tables, files access and source IPs. Everything about them, including what ctx.auth looks like for a key: app-api-keys.
Error Codes
- Function calls: an
auth: user/memberfunction called signed out returns LOGIN_REQUIRED (401) with no URL. A user signed in to Gipity who hasn't granted this app identity consent gets CONSENT_REQUIRED (403) witherror.consentUrl(a public function sees them as anonymous). Either way, callGipity.auth.signIn(), or send the user to theloginUrlfromauth/status. - App services under
user_paysreturn URLs: LOGIN_REQUIRED (401) witherror.loginUrlwhen no user is signed in, and CONSENT_REQUIRED (403) witherror.consentUrlwhen the user hasn't granted the AI scope.
Append &return=<app_url> to redirect URLs so users return to the app after auth. The return URL must be on a Gipity-hosted domain (app.gipity.ai, dev.gipity.ai, gipity.ai) or one of the app's custom domains.
Customizing the login page (auth_branding)
The login and consent pages are server-rendered by Gipity - your app only sends the user there - so you can't style them with your own CSS. By default they show your project name, Gipity orange, and the Gipity wordmark. To match your app, add an auth_branding: block to gipity.yaml and redeploy; gipity deploy syncs it to your project:
auth_branding:
app_name: Lilyboxd
primary_color: "#fea60b" # quote it - a bare # is a YAML comment
logo_url: https://media.gipity.ai/.../logo.png # https; replaces the wordmark
tagline: Your film diary
Scope: auth_branding styles the sign-in pages (Sign in with Gipity, and an app-user app's own sign-in page and code emails) - it does not theme your app's own UI (that's your own CSS). All fields optional; omitted ones use Gipity defaults. Full field rules and validation are in deploy ("auth_branding"). It's stored on the project (not passed in the login URL) on purpose: the login page is a trust surface where the user decides whether to grant access, so its identity must come from the registered project, not from request params an attacker could spoof.
Never let a signed-out user lose work at an auth wall (UX)
The one rule: when an action requires sign-in (auth_level: "user", user_pays, or "save your own X"), a signed-out user must never type work into a form and then lose it at Save. That dead-end - fill the form, click Save, get blocked, work gone - is the actual defect. When you ask them to sign in is a product call with two legitimate patterns; dropping their work is never one of them.
Decide what to render from the auth state you already fetched on load (Gipity.auth.user() / auth/status).
Don't - let them fill the form, then block at submit and drop the work:
form.addEventListener('submit', async (e) => {
e.preventDefault();
const user = await Gipity.auth.user();
if (!user) { alert('Please sign in to save'); return; } // work already typed, now blocked and lost
await Gipity.fn('add_recipe', { title: titleInput.value });
});
Pick one of these instead:
Pattern A - gate up front. Simplest, and right when the form is cheap to defer (nothing lost by waiting). Show a "Sign in to add your own" CTA in place of the create form for signed-out users:
const me = await Gipity.auth.user();
createForm.hidden = !me; // signed in: show the form
signinGate.hidden = !!me; // signed out: show the CTA instead (<gipity-signin> / "Sign in to add your own")
Pattern B - let them work, then preserve it through sign-in. Higher conversion - the user is invested by the time you ask (the "try it, then save" funnel Figma/Canva/CodePen use). The cost is you must persist the in-progress work across sign-in and replay the submit, so nothing is lost:
form.addEventListener('submit', async (e) => {
e.preventDefault();
const draft = { title: titleInput.value };
let user = await Gipity.auth.user();
if (!user) {
sessionStorage.setItem('pendingRecipe', JSON.stringify(draft)); // stash before sign-in
user = await Gipity.auth.signIn(); // popup; work is safe
if (!user) return; // cancelled - draft still on screen
}
await Gipity.fn('add_recipe', draft);
});
// On load, restore any stashed draft so a redirect-based sign-in doesn't lose it:
const pending = sessionStorage.getItem('pendingRecipe');
if (pending) { titleInput.value = JSON.parse(pending).title; sessionStorage.removeItem('pendingRecipe'); }
Choose A for low-investment forms or when you want a clean signed-out state; choose B when the work itself is the hook and you want the funnel. Either is fine - silently losing the user's work is not.