Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email cannot be sent repeatedly, if Email send error #7

Open
VineFiner opened this issue May 9, 2020 · 5 comments
Open

Email cannot be sent repeatedly, if Email send error #7

VineFiner opened this issue May 9, 2020 · 5 comments

Comments

@VineFiner
Copy link

  
import Fluent

struct CreateEmailToken: Migration {
    func prepare(on database: Database) -> EventLoopFuture<Void> {
        return database.schema("user_email_tokens")
            .id()
            .field("user_id", .uuid, .required, .references("users", "id", onDelete: .cascade))
            .field("token", .string, .required)
            .field("expires_at", .datetime, .required)
            .unique(on: "user_id")
            .unique(on: "token")
            .create()
    }
    
    func revert(on database: Database) -> EventLoopFuture<Void> {
        return database.schema("user_email_tokens").delete()
    }
}

Should be removed .unique(on: "user_id")

@VineFiner
Copy link
Author

I think that if the authentication is successful, we should delete all tokens. Because if the verification email fails to be sent, they will never be deleted.

    func delete(_ emailToken: EmailToken) -> EventLoopFuture<Void> {
        return EmailToken.query(on: database)
            .join(User.self, on: \EmailToken.$user.$id == \User.$id)
            .delete()
    }

@madsodgaard
Copy link
Owner

madsodgaard commented May 9, 2020

Thanks for your input! I am not sure if we want multiple email tokens per user to exist, so I think the unique constraint is fine. However, all previous tokens should be deleted on POST api/auth/email-verification. I'll update the code to include to this

@VineFiner
Copy link
Author

For formal projects, it is appropriate to use Mailgun, but can I use my personal mailbox if tested locally? For example Gmail. I found two libraries.

https://github.com/sersoft-gmbh/SwiftSMTP

https://github.com/Mikroservices/Smtp

@madsodgaard
Copy link
Owner

Currently, the example does not have the abstraction for email functionality, PR's are welcome though. Mailgun has a pretty good free tier for testing in my opinion, but you are of course more than welcome to use whatever provider you find fitting.

@jhoughjr
Copy link
Contributor

jhoughjr commented May 9, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants