You've already forked pocketbase
mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-12-01 01:16:08 +02:00
otp changes - added sentTo field, allow e.Record to be nil when requesting OTP, etc.
This commit is contained in:
@@ -1361,6 +1361,9 @@ type App interface {
|
||||
// OnRecordRequestOTPRequest hook is triggered on each Record
|
||||
// request OTP API request.
|
||||
//
|
||||
// [RecordCreateOTPRequestEvent.Record] could be nil if no matching identity is found, allowing
|
||||
// you to manually create or locate a different Record model (by reassigning [RecordCreateOTPRequestEvent.Record]).
|
||||
//
|
||||
// If the optional "tags" list (Collection ids or names) is specified,
|
||||
// then all event handlers registered via the created hook will be
|
||||
// triggered and called only if their event data origin matches the tags.
|
||||
|
||||
@@ -85,6 +85,20 @@ func (m *OTP) SetRecordRef(recordId string) {
|
||||
m.Set("recordRef", recordId)
|
||||
}
|
||||
|
||||
// SentTo returns the "sentTo" record field value.
|
||||
//
|
||||
// It could be any string value (email, phone, message app id, etc.)
|
||||
// and usually is used as part of the auth flow to update the verified
|
||||
// user state in case for example the sentTo value matches with the user record email.
|
||||
func (m *OTP) SentTo() string {
|
||||
return m.GetString("sentTo")
|
||||
}
|
||||
|
||||
// SetSentTo updates the "sentTo" record field value.
|
||||
func (m *OTP) SetSentTo(val string) {
|
||||
m.Set("sentTo", val)
|
||||
}
|
||||
|
||||
// Created returns the "created" record field value.
|
||||
func (m *OTP) Created() types.DateTime {
|
||||
return m.GetDateTime("created")
|
||||
|
||||
@@ -85,6 +85,30 @@ func TestOTPCollectionRef(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestOTPSentTo(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
app, _ := tests.NewTestApp()
|
||||
defer app.Cleanup()
|
||||
|
||||
otp := core.NewOTP(app)
|
||||
|
||||
testValues := []string{"test_1", "test2", ""}
|
||||
for i, testValue := range testValues {
|
||||
t.Run(fmt.Sprintf("%d_%q", i, testValue), func(t *testing.T) {
|
||||
otp.SetSentTo(testValue)
|
||||
|
||||
if v := otp.SentTo(); v != testValue {
|
||||
t.Fatalf("Expected getter %q, got %q", testValue, v)
|
||||
}
|
||||
|
||||
if v := otp.GetString("sentTo"); v != testValue {
|
||||
t.Fatalf("Expected field value %q, got %q", testValue, v)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestOTPCreated(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user