MCPcopy
hub / github.com/pocketbase/pocketbase / recordAuthRefresh

Function recordAuthRefresh

apis/record_auth_refresh.go:9–35  ·  view source on GitHub ↗
(e *core.RequestEvent)

Source from the content-addressed store, hash-verified

7)
8
9func recordAuthRefresh(e *core.RequestEvent) error {
10 record := e.Auth
11 if record == nil {
12 return e.NotFoundError("Missing auth record context.", nil)
13 }
14
15 event := new(core.RecordAuthRefreshRequestEvent)
16 event.RequestEvent = e
17 event.Collection = record.Collection()
18 event.Record = record
19
20 return e.App.OnRecordAuthRefreshRequest().Trigger(event, func(e *core.RecordAuthRefreshRequestEvent) error {
21 token := getAuthTokenFromRequest(e.RequestEvent)
22
23 // skip token renewal if the token's payload doesn't explicitly allow it (e.g. impersonate tokens)
24 claims, _ := security.ParseUnverifiedJWT(token) //
25 if v, ok := claims[core.TokenClaimRefreshable]; ok && cast.ToBool(v) {
26 var tokenErr error
27 token, tokenErr = e.Record.NewAuthToken()
28 if tokenErr != nil {
29 return e.InternalServerError("Failed to refresh auth token.", tokenErr)
30 }
31 }
32
33 return recordAuthResponse(e.RequestEvent, e.Record, token, "", nil)
34 })
35}

Callers

nothing calls this directly

Calls 9

ParseUnverifiedJWTFunction · 0.92
getAuthTokenFromRequestFunction · 0.85
NotFoundErrorMethod · 0.80
CollectionMethod · 0.80
TriggerMethod · 0.80
NewAuthTokenMethod · 0.80
InternalServerErrorMethod · 0.80
recordAuthResponseFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…