fix: include missing files for tenant impersonation feature
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m7s
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m7s
- Added backend impersonate endpoint. - Added frontend impersonate button and functions. - Fixed build failure by including missing exported functions in dataService.ts.
This commit is contained in:
@@ -217,6 +217,30 @@ apiRouter.post('/auth/login', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// God Mode (Impersonate Tenant)
|
||||
apiRouter.post('/impersonate/:tenantId', requireRole(['super_admin']), async (req, res) => {
|
||||
try {
|
||||
// Buscar o primeiro admin (ou qualquer usuário) do tenant para assumir a identidade
|
||||
const [users] = await pool.query("SELECT * FROM users WHERE tenant_id = ? AND role = 'admin' LIMIT 1", [req.params.tenantId]);
|
||||
|
||||
if (users.length === 0) {
|
||||
return res.status(404).json({ error: 'Nenhum administrador encontrado nesta organização para assumir a identidade.' });
|
||||
}
|
||||
|
||||
const user = users[0];
|
||||
|
||||
if (user.status !== 'active') {
|
||||
return res.status(403).json({ error: 'A conta do admin desta organização está inativa.' });
|
||||
}
|
||||
|
||||
// Gerar um token JWT como se fôssemos o admin do tenant
|
||||
const token = jwt.sign({ id: user.id, tenant_id: user.tenant_id, role: user.role, team_id: user.team_id, slug: user.slug }, JWT_SECRET, { expiresIn: '2h' });
|
||||
res.json({ token, user: { id: user.id, name: user.name, email: user.email, role: user.role, tenant_id: user.tenant_id, team_id: user.team_id, slug: user.slug } });
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Forgot Password
|
||||
apiRouter.post('/auth/forgot-password', async (req, res) => {
|
||||
const { email } = req.body;
|
||||
|
||||
Reference in New Issue
Block a user