Docs
← Back to site

Signing users in to the client portal

1 min readUpdated November 11, 2026

An Analytics button in your app can open your user’s client portal, already signed in.

app/api/analytics/route.ts
import { stats } from '@/lib/stats';

export async function GET() {
  const user = await currentUser(); // your own sign-in
  // Safe to repeat: the same email again only updates the name or role.
  // invite: false, or each call would email a set-password link (the default is true).
  await stats.users.add(user.id, { email: user.email, name: user.name, invite: false });
  const { url } = await stats.users.loginLink(user.id, user.email, { site: website.id });
  return Response.redirect(url); // works once, within 5 minutes; opens that site's page
}
  • People with two-step sign-in get the sign-in page instead (signs_in: false in the answer).
  • Each new link replaces the last one for that person.
  • Roles: admin (the default) or viewer. users.list(ref) and users.remove(ref, email) manage the rest.

What your users see there is in the Client portal docs.

Was this helpful?