lowered the default mfa duration and reorganized internal record pre/post handling
This commit is contained in:
@@ -137,4 +137,42 @@ func (app *BaseApp) registerExternalAuthHooks() {
|
||||
},
|
||||
Priority: 99,
|
||||
})
|
||||
|
||||
// delete all pre-existing external auths on verified upgrade
|
||||
app.OnRecordUpdateExecute().Bind(&hook.Handler[*RecordEvent]{
|
||||
Func: func(e *RecordEvent) error {
|
||||
if !e.Record.Collection().IsAuth() {
|
||||
return e.Next()
|
||||
}
|
||||
|
||||
hasUpgradedVerified := !e.Record.Original().IsNew() && !e.Record.Original().Verified() && e.Record.Verified()
|
||||
|
||||
if !hasUpgradedVerified {
|
||||
return e.Next()
|
||||
}
|
||||
|
||||
originalApp := e.App
|
||||
return e.App.RunInTransaction(func(txApp App) error {
|
||||
e.App = txApp
|
||||
defer func() { e.App = originalApp }()
|
||||
|
||||
externalAuths, err := txApp.FindAllExternalAuthsByRecord(e.Record)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(externalAuths) > 0 {
|
||||
// delete all pre-existing external auths
|
||||
if err := txApp.DeleteAllExternalAuthsByRecord(e.Record); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// force refresh tokens reset (if not already)
|
||||
e.Record.RefreshTokenKey()
|
||||
}
|
||||
|
||||
return e.Next()
|
||||
})
|
||||
},
|
||||
Priority: 99,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user