I am trying to implement expiration to the activation link I send to the user's email when they register a new account, the link should expires after 24 hours if the user doesn't click on it. Up until this point I am able to send the link to the user's email upon registration, the link looks like this 'http://localhost:3000/auth/activate/${verificationKey}', everything works smoothly. But like I said, I want the link to expires after 24 hours and I just don't have any idea of how to go about this.From what I've gathered so far I think one way to do this would be to delete the verificationKey value from my User entity/model after 24 hours, then if the verificationKey value is falsy I need to send another link to the user. Now my question is, how do I check if a value (in this case user.verification_key) has been generated for over 24 hours?This is the relevant code to register a new user:const user = new User();user.username = username;user.password = await bcrypt.hash(password, salt);user.is_verified = false;user.verification_key = cryptoRandomString({length: 10,type: 'url-safe',});Some people have suggested using Redis for this, which I don't know anything about other than it's a in-memory store, and while I'm ok reading more about this tool, I would like to know if there are other ways to do this. I don't know if by installing Redis I would need extra configuration for the server when I host my app, I'd like to avoid that.Technologies I am using: Nestjs (Nodejs framework), typeorm, postgres.Let me know if you guys need more code/details. Any help is greatly appreciated and thanks in advance.
Submitted July 15, 2019 at 12:27AM by gilbertrh
No comments:
Post a Comment