[admin] easier impersonation for debugging

This commit is contained in:
Andrea Vos 2022-10-02 09:23:19 +02:00
parent 476f44da44
commit 71b552bf49
2 changed files with 17 additions and 1 deletions

View File

@ -116,6 +116,10 @@
pronouns.page/u/{{user.username}} pronouns.page/u/{{user.username}}
</span> </span>
</a> </a>
<a v-if="$isGranted('*')" href="#"
class="list-group-item list-group-item-action list-group-item-hoverable small"
@click.prevent="impersonate()"><Icon v="user-secret"/> Impersonate
</a>
</div> </div>
</div> </div>
@ -274,6 +278,13 @@
return bestKey >= 0 ? best[bestKey].slice(0, 3) : []; return bestKey >= 0 ? best[bestKey].slice(0, 3) : [];
}, },
async impersonate() {
const { token } = await this.$axios.$get(`/admin/impersonate/${encodeURIComponent(this.username)}`);
this.$cookies.set('impersonator', this.$cookies.get('token'));
this.$cookies.set('token', token);
await this.$router.push('/' + this.config.user.route);
setTimeout(() => window.location.reload(), 500);
},
}, },
head() { head() {
return head({ return head({

View File

@ -612,7 +612,12 @@ router.get('/admin/impersonate/:email', handleErrorAsync(async (req, res) => {
return res.status(401).json({error: 'Unauthorised'}); return res.status(401).json({error: 'Unauthorised'});
} }
return res.json({token: await issueAuthentication(req.db, {email: req.params.email})}); let email = req.params.email;
if (!email.includes('@')) {
email = (await req.db.get(SQL`SELECT email FROM users WHERE usernameNorm = ${normalise(email)}`)).email;
}
return res.json({token: await issueAuthentication(req.db, {email: email})});
})); }));
export default router; export default router;