Skip to content
Dashboard

Identity headers

Copy page
View as Markdown

Grayspar checks who a person is before a request reaches your app, and passes that answer to your app in headers. Your app can use the headers to greet someone by name, keep data per person or show an admin page to your team alone, with no login code.

Every request that passes the check arrives with these four headers:

Header Value
X-User-Email The email address the person logged in with.
X-User-Id An id for the person that never changes.
X-User-Name The person’s name, percent-encoded. Decode it before you show it.
X-User-Role owner or member for someone in your team, and viewer for everyone else who can open the project.

Grayspar first removes any header with one of these names from the incoming request, so nobody can forge them. Every X-User- header your app reads came from Grayspar.

Two kinds of request carry none of these headers, because nobody logged in: a request through an open path, and any request to a project open to anyone with the link. Treat a request without X-User-Email as anonymous.

In Python with FastAPI:

from urllib.parse import unquote
from fastapi import FastAPI, Header
app = FastAPI()
@app.get("/")
def home(x_user_name: str = Header(default=""), x_user_role: str = Header(default="")):
return {"hello": unquote(x_user_name), "role": x_user_role}

In JavaScript with Express:

app.get('/', (req, res) => {
const name = decodeURIComponent(req.get('X-User-Name') ?? '');
res.send(`Hello ${name}`);
});

In Next.js, a server component reads the headers with headers(). The headers differ on every request, so the component sits inside Suspense, and Next.js renders it for each visitor:

app/page.tsx
import { headers } from 'next/headers';
import { Suspense } from 'react';
async function Greeting() {
const name = (await headers()).get('x-user-name') ?? '';
return <h1>Hello {decodeURIComponent(name)}</h1>;
}
export default function Home() {
return (
<Suspense>
<Greeting />
</Suspense>
);
}

To show a page to your team alone, check that X-User-Role is owner or member.