Skip to content

Users and your app's own data

Why an auth user holds only identity and sessions, where your app keeps profiles and roles, and how several apps share one sign-in.

Applies to EngineCloud
View as Markdown
On this page
  1. Identity here, everything else in your tables
  2. Roll-in: the first visit
  3. Several apps, one sign-in

Identity here, everything else in your tables

sypnia_auth.users answers one question: who is this? It does not know your app’s plans, teams, roles or settings, on purpose. Keep those in your own tables, keyed by the user’s id:

SQL
create table public.members (
  user_id uuid primary key references sypnia_auth.users(id) on delete cascade,
  display_name text,
  role text not null default 'member',      -- your app's role, not a database role
  created_at timestamptz not null default now()
);

Your app grows its own model freely, and the same identity can be used by several apps without one app’s data leaking into another’s.

Roll-in: the first visit

When a signed-in person opens your app for the first time, create their row there. Make it idempotent, so it can run on every visit:

SQL
insert into public.members (user_id, display_name)
values (auth.uid(), auth.jwt() -> 'user_metadata' ->> 'name')
on conflict (user_id) do nothing;

If you write your app as use cases (Sypnorm, with Cases), this is a use case of its own, JoinApp, and your onboarding follows it. No second sign-up, no second password.

Several apps, one sign-in

Apps on the same domain (shop.example.com, admin.example.com) can share one session:

  1. Turn on cross-subdomain sessions for the project and set the parent domain (.example.com). After a sign-in, the engine sets the refresh token in an HttpOnly, Secure, SameSite=Lax cookie on that domain, plus a harmless hint cookie the apps can read.
  2. Each app, when it starts, calls refresh with credentials: 'include' and a CSRF header (the double-submit cookie the engine sets). If the cookie is there, it gets an access token without showing a sign-in screen.
  3. Each app keeps the access token in memory and its own server verifies it with the project’s JWKS.
  4. Signing out with scope: 'global' clears the cookie for every app.

Each app keeps its own sign-in and sign-up screens, so it also works alone; when the session already exists, the person goes straight to the app.

  1. Identity here, everything else in your tables
  2. Roll-in: the first visit
  3. Several apps, one sign-in

    Search pages, sections and terms