Build features

The signed-in user

Every request has already been signed in. Read who it is.

The Inhaus gateway checks every request before it reaches your app: the person is signed in with their company account and has a role on the app. So your app never builds a login page, and always knows who is using it.

In the browser

import { getUser } from '@inhaus/sdk';

const user = await getUser();
// { id: 'usr_01J9…', email: '[email protected]', name: 'Priya Shah', role: 'editor', workspace: 'acme' }

In server code

worker.ts
import { getUser } from '@inhaus/sdk';

export default {
  async fetch(request: Request, env: Env) {
    const user = getUser(request);
    if (user?.role === 'viewer' && request.method !== 'GET') {
      return new Response('Only editors can change this', { status: 403 });
    }
    // ...
  },
};

What you get

FieldExampleNotes
idusr_01J9…Stable. Use it to link rows to people.
email[email protected]
namePriya Shah
roleviewerThe person's role on this app: viewer, editor or owner.
workspaceacme or ws_acmeThe app's workspace: its address name in the browser, its id in server code.

On an app shared with anyone with the link, visitors may not be signed in at all:

  • In the browser, getUser() returns null.
  • In server code, getUser(request) returns a user with id: 'anonymous', an empty email, and role: 'viewer'.

Check for these before trusting the identity.

Common uses

  • Fill in "submitted by" automatically on a form.
  • Show each salesperson only their own deals.
  • Let viewers read and editors change.

See the full getUser reference.