Hello world! I am an Android Dev currently working...
# server
g
Hello world! I am an Android Dev currently working on my first backend with Kotlin. I am still figuring things out in the backend world. I am working on the OTP feature for verification of emails during authentication. Please, I have two questions: 1. What library/plugin could I use for sending the OTP email? 2. What db/cache with TTL would you recommend for handling the OTP seamlessly in Kotlin?
d
There’s a lot of ways to solve this problem. However, as an example, you could use one of the many SaaS offerings for sending emails such as SendGrid. That way you won’t really be sending an email directly, but instead using a REST API to do it. If you are using a traditional random number based OTP, then yes you’ll need a form of persistence, to associate the OTP to a user and probably an expiry timestamp. An alternative stateless approach would be to encode the user Id, and expiry and whatever else makes sense into a JSON object and then encode it using JWS/JWE. You can then include the encoded value into the email as a URL link to your server. The server, upon receiving the link can verify the signature and decrypt the value. Take a look at Nimbus JOSE for this.
👍 1
g
Sorry for late response. I've been away. Thanks for the help. It worked. I also found MailTrap for development. It's working now and I think the stateless approach should be great for the reset password email which will require a url with encoded data to be use by the server for verification/identification of the user... Thank you so much. My learning is going well. I just think the deployment could be tricky for me. I tried Google Cloud but for some reason the redis instance host in GCP is not reachable saying the host is unresolved. Maybe I'm missing something in the setup but I'd try again.
👍 1
d
You can use redis
g
@Daisukikancolle Thank you. I did use redis hosted locally on my PC. It worked perfectly. I tried deploying to Google Cloud Platform (GCP) and created a redis instance on GCP but the redis host is not working saying host cannot be resolved. I think I did not set up the redis instance rightly. I'd share the error log here when I open the project later today.