-
Notifications
You must be signed in to change notification settings - Fork 297
/
Copy pathlogout.go
34 lines (27 loc) · 856 Bytes
/
logout.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package api
import (
"net/http"
"github.com/netlify/gotrue/models"
"github.com/netlify/gotrue/storage"
)
// Logout is the endpoint for logging out a user and thereby revoking any refresh tokens
func (a *API) Logout(w http.ResponseWriter, r *http.Request) error {
ctx := r.Context()
instanceID := getInstanceID(ctx)
a.clearCookieToken(ctx, w)
u, err := getUserFromClaims(ctx, a.db)
if err != nil {
return unauthorizedError("Invalid user").WithInternalError(err)
}
err = a.db.Transaction(func(tx *storage.Connection) error {
if terr := models.NewAuditLogEntry(tx, instanceID, u, models.LogoutAction, nil); terr != nil {
return terr
}
return models.Logout(tx, instanceID, u.ID)
})
if err != nil {
return internalServerError("Error logging out user").WithInternalError(err)
}
w.WriteHeader(http.StatusNoContent)
return nil
}