Hey, I need from the users when they last logged in. About getUser i get only "timeJoined". Is this stored in the database of the core at all or do I have to store it myself via "updateUserMetadata"?
n
nkshah2
05/03/2022, 8:22 AM
Hi,
We currently dont store this information, you would have to handle that yourself
nkshah2
05/03/2022, 10:34 AM
@xpsmix I can add more information here if you like, what recipe are you using?
x
xpsmix
05/03/2022, 4:14 PM
thanks, this would be nice, I use ThirdPartyMailPassword, Sessions and userMetaData
r
rp_st
05/04/2022, 4:38 AM
hey @xpsmix
rp_st
05/04/2022, 4:44 AM
You can make your own session verification middleware like this:
Copy code
ts
import { SessionRequest } from "../../framework/express"
import UserMetadata from "../../recipe/usermetadata";
function customVerifySession(options: Session.VerifySessionOptions) {
return (req: SessionRequest, res, next) => {
verifySession(options)(req, res, (err) => {
if (err) {
return next(err);
}
if (req.session !== undefined) {
let userId = req.session.getUserId();
// we do this asynchronously...
UserMetadata.updateUserMetadata(userId, {
timeActive: Date.now()
});
}
next();
})
}
}
rp_st
05/04/2022, 4:45 AM
And then you can use
customVerifySession
everywhere in your APIs.
Furthermore, you might want to override the sign in / up APIs as well to do:
SuperTokens is an open source authentication solution offering features like: Different types of login: Email / password, Passwordless (OTP or Magic link based).