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');
});