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

LastVerificationSentAt is updated before than expected #3121

Closed
ErikPelli opened this issue Aug 12, 2023 · 2 comments
Closed

LastVerificationSentAt is updated before than expected #3121

ErikPelli opened this issue Aug 12, 2023 · 2 comments

Comments

@ErikPelli
Copy link

ErikPelli commented Aug 12, 2023

I use pocketbase (latest, v0.17.4) as a framework for a test project and I'm trying to rate limit the verification email send.

I actually have this simple code:

// Send verification email every 30 minutes
app.OnRecordBeforeRequestVerificationRequest().Add(func(e *core.RecordRequestVerificationEvent) error {
    lastTime := e.Record.LastVerificationSentAt()
    if !lastTime.IsZero() {
	    if time.Now().Before(lastTime.Time().Add(30 * time.Minute)) {
		    return errors.New("you must wait 30 minutes for another mail verification")
	    }
    }
    return nil
})

Actually, value of e.Record.LastVerificationSentAt() is updated before entering this function. In my mind, this function is executed before sending verification email (and it is, effectively).

Its value should be updated when sending the email (so after the execution of this OnRecordBeforeRequestVerificationRequest function).

This code should work, but actually this function always return the error, even for the verification of a new user during the sign up and, if i stop pocketbase and check sqlite, the value in the column is an empty string.
So actually the lastVerificationAt is updated in memory before this function but not persisted.

@ganigeorgiev
Copy link
Member

Hm, this was done for consistency as usually the form data are loaded in the record before the hook interceptors, but I agree in this specific case is kindof strange.

I've added it in the roadmap and will consider updating it for v0.18.0 after the ongoing JS SDK refactoring.

As a workaround, you should be able to retrieve the original LastVerificationSentAt() value by calling e.Record.OriginalCopy().LastVerificationSentAt().

@ganigeorgiev
Copy link
Member

ganigeorgiev commented Aug 12, 2023

Side-note: internally we have a similar check to the above one but it is for 2 mins, which should be OK for most applications.

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

2 participants