MCPcopy
hub / github.com/pocketbase/pocketbase / DeleteExpiredOTPs

Method DeleteExpiredOTPs

core/otp_query.go:85–117  ·  view source on GitHub ↗

DeleteExpiredOTPs deletes the expired OTPs for all auth collections.

()

Source from the content-addressed store, hash-verified

83
84// DeleteExpiredOTPs deletes the expired OTPs for all auth collections.
85func (app *BaseApp) DeleteExpiredOTPs() error {
86 authCollections, err := app.FindAllCollections(CollectionTypeAuth)
87 if err != nil {
88 return err
89 }
90
91 // note: perform even if OTP is disabled to ensure that there are no dangling old records
92 for _, collection := range authCollections {
93 minValidDate, err := types.ParseDateTime(time.Now().Add(-1 * collection.OTP.DurationTime()))
94 if err != nil {
95 return err
96 }
97
98 items := []*Record{}
99
100 err = app.RecordQuery(CollectionNameOTPs).
101 AndWhere(dbx.HashExp{"collectionRef": collection.Id}).
102 AndWhere(dbx.NewExp("[[created]] < {:date}", dbx.Params{"date": minValidDate})).
103 All(&items)
104 if err != nil {
105 return err
106 }
107
108 for _, item := range items {
109 err = app.Delete(item)
110 if err != nil {
111 return err
112 }
113 }
114 }
115
116 return nil
117}

Callers 1

registerOTPHooksMethod · 0.95

Calls 6

FindAllCollectionsMethod · 0.95
RecordQueryMethod · 0.95
DeleteMethod · 0.95
ParseDateTimeFunction · 0.92
AddMethod · 0.45
DurationTimeMethod · 0.45

Tested by

no test coverage detected