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
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
| Field | Example | Notes |
|---|---|---|
id | usr_01J9… | Stable. Use it to link rows to people. |
email | [email protected] | |
name | Priya Shah | |
role | viewer | The person's role on this app: viewer, editor or owner. |
workspace | acme or ws_acme | The app's workspace: its address name in the browser, its id in server code. |
Apps shared with anyone with the link
On an app shared with anyone with the link, visitors may not be signed in at all:
- In the browser,
getUser()returnsnull. - In server code,
getUser(request)returns a user withid: 'anonymous', an emptyemail, androle: '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.