36 lines
864 B
Go
36 lines
864 B
Go
|
package api
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
|
||
|
"forge.cadoles.com/Cadoles/emissary/internal/auth"
|
||
|
"forge.cadoles.com/Cadoles/emissary/internal/datastore"
|
||
|
"github.com/pkg/errors"
|
||
|
"gitlab.com/wpetit/goweb/api"
|
||
|
"gitlab.com/wpetit/goweb/logger"
|
||
|
)
|
||
|
|
||
|
func (m *Mount) getSession(w http.ResponseWriter, r *http.Request) {
|
||
|
user, ok := assertRequestUser(w, r)
|
||
|
if !ok {
|
||
|
return
|
||
|
}
|
||
|
|
||
|
ctx := r.Context()
|
||
|
|
||
|
tenant, err := m.tenantRepo.Get(ctx, user.Tenant())
|
||
|
if err != nil && !errors.Is(err, datastore.ErrNotFound) {
|
||
|
err = errors.WithStack(err)
|
||
|
logger.Error(ctx, "could not retrieve user tenant", logger.CapturedE(err))
|
||
|
api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil)
|
||
|
}
|
||
|
|
||
|
api.DataResponse(w, http.StatusOK, struct {
|
||
|
User auth.User `json:"user"`
|
||
|
Tenant *datastore.Tenant `json:"tenant"`
|
||
|
}{
|
||
|
User: user,
|
||
|
Tenant: tenant,
|
||
|
})
|
||
|
}
|