created hwsauth module
This commit is contained in:
27
hwsauth/logout.go
Normal file
27
hwsauth/logout.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package hwsauth
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"net/http"
|
||||
|
||||
"git.haelnorr.com/h/golib/cookies"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func (auth *Authenticator[T]) Logout(tx *sql.Tx, w http.ResponseWriter, r *http.Request) error {
|
||||
aT, rT, err := auth.getTokens(tx, r)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "auth.getTokens")
|
||||
}
|
||||
err = aT.Revoke(tx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "aT.Revoke")
|
||||
}
|
||||
err = rT.Revoke(tx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "rT.Revoke")
|
||||
}
|
||||
cookies.DeleteCookie(w, "access", "/")
|
||||
cookies.DeleteCookie(w, "refresh", "/")
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user