2023-10-11 13:24:44 -04:00
|
|
|
export default eventHandler(async (ev) => {
|
|
|
|
if (ev.context.currentUser) {
|
|
|
|
let log = ev.context.currentUser.ipLog;
|
2023-12-29 20:53:29 -05:00
|
|
|
if (ev.context.clientAddress !== undefined && !/127\.0\.0\.1|localhost|::1/.test(ev.context.clientAddress)) {
|
2023-10-11 13:24:44 -04:00
|
|
|
let found = log.findIndex((a) => a.ip === ev.context.clientAddress);
|
|
|
|
if (found !== -1) {
|
|
|
|
ev.context.currentUser.ipLog[found].lastAccess = new Date();
|
|
|
|
} else {
|
|
|
|
ev.context.currentUser.ipLog.push({
|
|
|
|
ip: ev.context.clientAddress!,
|
|
|
|
lastAccess: new Date(),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
await ev.context.currentUser.save();
|
|
|
|
}
|
|
|
|
});
|