Logout is the endpoint for logging out a user and thereby revoking any refresh tokens
(w http.ResponseWriter, r *http.Request)
| 9 | |
| 10 | // Logout is the endpoint for logging out a user and thereby revoking any refresh tokens |
| 11 | func (a *API) Logout(w http.ResponseWriter, r *http.Request) error { |
| 12 | ctx := r.Context() |
| 13 | instanceID := getInstanceID(ctx) |
| 14 | |
| 15 | a.clearCookieToken(ctx, w) |
| 16 | |
| 17 | u, err := getUserFromClaims(ctx, a.db) |
| 18 | if err != nil { |
| 19 | return unauthorizedError("Invalid user").WithInternalError(err) |
| 20 | } |
| 21 | |
| 22 | err = a.db.Transaction(func(tx *storage.Connection) error { |
| 23 | if terr := models.NewAuditLogEntry(tx, instanceID, u, models.LogoutAction, nil); terr != nil { |
| 24 | return terr |
| 25 | } |
| 26 | return models.Logout(tx, instanceID, u.ID) |
| 27 | }) |
| 28 | if err != nil { |
| 29 | return internalServerError("Error logging out user").WithInternalError(err) |
| 30 | } |
| 31 | |
| 32 | w.WriteHeader(http.StatusNoContent) |
| 33 | return nil |
| 34 | } |
nothing calls this directly
no test coverage detected