MCPcopy Create free account
hub / github.com/supabase/auth / Logout

Method Logout

internal/api/logout.go:21–73  ·  view source on GitHub ↗

Logout is the endpoint for logging out a user and thereby revoking any refresh tokens

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

19
20// Logout is the endpoint for logging out a user and thereby revoking any refresh tokens
21func (a *API) Logout(w http.ResponseWriter, r *http.Request) error {
22 ctx := r.Context()
23 config := a.config
24 db := a.db.WithContext(ctx)
25 scope := LogoutGlobal
26
27 if r.URL.Query() != nil {
28 switch r.URL.Query().Get("scope") {
29 case "", "global":
30 scope = LogoutGlobal
31
32 case "local":
33 scope = LogoutLocal
34
35 case "others":
36 scope = LogoutOthers
37
38 default:
39 return apierrors.NewBadRequestError(apierrors.ErrorCodeValidationFailed, "Unsupported logout scope %q", r.URL.Query().Get("scope"))
40 }
41 }
42
43 s := getSession(ctx)
44 u := getUser(ctx)
45
46 err := db.Transaction(func(tx *storage.Connection) error {
47 if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, u, models.LogoutAction, "", nil); terr != nil {
48 return terr
49 }
50
51 if s == nil {
52 logrus.Infof("user has an empty session_id claim: %s", u.ID)
53 } else {
54 switch scope {
55 case LogoutLocal:
56 return models.LogoutSession(tx, s.ID)
57
58 case LogoutOthers:
59 return models.LogoutAllExceptMe(tx, s.ID, u.ID)
60 }
61 }
62
63 // default mode, log out everywhere
64 return models.Logout(tx, u.ID)
65 })
66 if err != nil {
67 return apierrors.NewInternalServerError("Error logging out user").WithInternalError(err)
68 }
69
70 w.WriteHeader(http.StatusNoContent)
71
72 return nil
73}

Callers

nothing calls this directly

Calls 13

NewBadRequestErrorFunction · 0.92
NewAuditLogEntryFunction · 0.92
LogoutSessionFunction · 0.92
LogoutAllExceptMeFunction · 0.92
LogoutFunction · 0.92
NewInternalServerErrorFunction · 0.92
getSessionFunction · 0.85
getUserFunction · 0.85
WithContextMethod · 0.80
TransactionMethod · 0.80
GetMethod · 0.45
WithInternalErrorMethod · 0.45

Tested by

no test coverage detected