Auth0 Home Blog Docs

Api/v2/logs End point API

auth0
management-api
login

#1

Hi,

  1. Can we retrieve the last_login field from api/v2/logs ?
    2.Can we quire the last_login related logs ?
  2. any other option to get the last_login details?

#2

Hi,
please go through the link,


#3

Hi,
I have added last login property in Rule as follows,
user.user_metadata = user.user_metadata || {};
// update the user_metadata that will be part of the response
user.user_metadata.lastLogin = user.user_metadata.lastLogin || {};
let fDate = dateFormat(new Date(user.user_metadata.lastLogin), “yyyy-mm-dd”);
let sDate = dateFormat(new Date(), “yyyy-mm-dd”);

let firstDate = new Date(fDate),
secondDate = new Date(sDate),
timeDifference = Math.abs(secondDate.getTime() - firstDate.getTime());
let differentDays = Math.ceil(timeDifference / (1000 * 3600 * 24));
if(differentDays === 0)
{
user.user_metadata.lastLogin = new Date();
// persist the user_metadata update
auth0.users.updateUserMetadata(user.user_id, user.user_metadata)
.then(function(){
callback(null, user, context);
})
.catch(function(err){
callback(err);
});
}
else
{
return callback(new UnauthorizedError(user.email +’: User account has been deactivated’));
}
callback(null, user, context);

after that we can retrieve that data through Api as mentioned in following link

under the topic
" Retrieve User Metadata"