App SDK
getUser
Who is using the app right now.
In the browser
getUser(): Promise<InhausUser | null>Asks the gateway who is signed in, through GET /__inhaus/me on the app's own address.
import { getUser } from '@inhaus/sdk';
const user = await getUser();
if (user) document.querySelector('#who').textContent = user.email;Returns null when nobody is signed in or the person has no access. Throws on any other error.
In server code
getUser(request: Request): InhausUser | nullReads the x-inhaus-user header the gateway adds to every request. The gateway removes any x-inhaus-* header sent from outside first, so your app can trust it.
import { getUser } from '@inhaus/sdk';
export default {
async fetch(request: Request) {
const user = getUser(request);
return Response.json({ hello: user?.name });
},
};Returns null when the header is missing or has expired.
InhausUser
idstringThe person's id, for example usr_01J9…. Stable: use it to link rows to people. anonymous for visitors who are not signed in on an app shared with anyone with the link.
emailstringTheir email address. Empty for anonymous.
namestringTheir name.
rolestringTheir role on this app: owner, editor or viewer.
workspacestringThe app's workspace: its address name (acme) in the browser, its id (ws_acme) in server code.
Verifying the header yourself
The header is a signed token. If you want to check the signature rather than trust the gateway, the public key is in env.INHAUS_GATEWAY_PUBLIC_KEY.