This repository has been archived on 2022-08-26. You can view files and clone it, but cannot push or open issues or pull requests.
gosocial/pkg/session/current_user.go

20 lines
396 B
Go
Raw Normal View History

package session
import (
"errors"
"net/http"
"git.kirsle.net/apps/gosocial/pkg/models"
)
// CurrentUser returns the current logged in user via session cookie.
func CurrentUser(r *http.Request) (*models.User, error) {
sess := Get(r)
if sess.LoggedIn {
// Load the associated user ID.
return models.GetUser(sess.UserID)
}
return nil, errors.New("request session is not logged in")
}