1
0
mirror of https://github.com/pocketbase/pocketbase.git synced 2025-11-24 15:14:30 +02:00

check after hook errors

This commit is contained in:
Gani Georgiev
2023-05-29 21:50:07 +03:00
parent 45b73e3dfb
commit 729f9f142e
9 changed files with 153 additions and 221 deletions

View File

@@ -57,7 +57,13 @@ func RequestData(c echo.Context) *models.RequestData {
return result
}
func RecordAuthResponse(app core.App, c echo.Context, authRecord *models.Record, meta any) error {
func RecordAuthResponse(
app core.App,
c echo.Context,
authRecord *models.Record,
meta any,
finalizers ...func(token string) error,
) error {
token, tokenErr := tokens.NewRecordAuthToken(app, authRecord)
if tokenErr != nil {
return NewBadRequestError("Failed to create auth token.", tokenErr)
@@ -100,6 +106,12 @@ func RecordAuthResponse(app core.App, c echo.Context, authRecord *models.Record,
result["meta"] = e.Meta
}
for _, f := range finalizers {
if err := f(e.Token); err != nil {
return err
}
}
return e.HttpContext.JSON(http.StatusOK, result)
})
}