Skip to main content
Gate supports npx signup yourproduct login, which generates a magic link and opens your dashboard. You add one route to handle it.

How it works

  1. Developer runs npx signup yourproduct login
  2. CLI authenticates with the agent token from .env
  3. Gate opens a consent window — developer clicks Approve
  4. Gate issues a short-lived login code
  5. CLI opens your dashboard at /auth/gate?code=...
  6. Your server verifies the code with Gate and creates a session

Add the route

app.get('/auth/gate', async (req, res) => {
  const code = req.query.code;
  if (!code) return res.redirect('/login');

  // Verify with Gate
  const resp = await fetch(`https://api.usefoil.com/gate/login-sessions/consume`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ token: code }),
  });

  if (!resp.ok) return res.redirect('/login');

  const { data } = await resp.json();
  // data.gate_account_id — look up the user in your system

  // Create a session in your auth system
  const user = await findOrCreateUser(data.gate_account_id, data.account_name);
  req.session.userId = user.id;

  res.redirect('/dashboard');
});

Consume response

{
  "data": {
    "gate_account_id": "gacct_...",
    "account_name": "my-project"
  }
}
The code is one-time-use. Once consumed, it cannot be reused.

What’s next