feat: initial commit
This commit is contained in:
@ -1,11 +1,12 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"encoding/gob"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
|
||||
"forge.cadoles.com/wpetit/clearcase/internal/core/model"
|
||||
"github.com/gorilla/sessions"
|
||||
"github.com/markbates/goth"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@ -14,7 +15,11 @@ const tenantIDAttr = "t"
|
||||
|
||||
var errSessionNotFound = errors.New("session not found")
|
||||
|
||||
func (h *Handler) storeSessionUser(w http.ResponseWriter, r *http.Request, user *goth.User) error {
|
||||
func init() {
|
||||
gob.Register(&model.User{})
|
||||
}
|
||||
|
||||
func (h *Handler) storeSessionUser(w http.ResponseWriter, r *http.Request, user *model.User) error {
|
||||
sess, err := h.getSession(r)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
@ -29,13 +34,13 @@ func (h *Handler) storeSessionUser(w http.ResponseWriter, r *http.Request, user
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *Handler) retrieveSessionUser(r *http.Request) (*goth.User, error) {
|
||||
func (h *Handler) retrieveSessionUser(r *http.Request) (*model.User, error) {
|
||||
sess, err := h.getSession(r)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
user, ok := sess.Values[userAttr].(*goth.User)
|
||||
user, ok := sess.Values[userAttr].(*model.User)
|
||||
if !ok {
|
||||
return nil, errors.WithStack(errSessionNotFound)
|
||||
}
|
||||
|
Reference in New Issue
Block a user