Finished login handling.
This commit is contained in:
parent
9986ca627d
commit
eb98a600e8
3 changed files with 64 additions and 23 deletions
|
|
@ -14,14 +14,19 @@ import (
|
|||
func LoadAuthenticatedUser(orm *ent.Client) echo.MiddlewareFunc {
|
||||
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
if userID, err := auth.GetUserID(c); err != nil {
|
||||
if userID, err := auth.GetUserID(c); err == nil {
|
||||
u, err := orm.User.Query().
|
||||
Where(user.ID(userID)).
|
||||
First(c.Request().Context())
|
||||
|
||||
if err == nil {
|
||||
switch err.(type) {
|
||||
case *ent.NotFoundError:
|
||||
c.Logger().Debug("auth user not found: %d", userID)
|
||||
case nil:
|
||||
c.Set(context.AuthenticatedUserKey, u)
|
||||
c.Logger().Info("auth user loaded in to context: %d", userID)
|
||||
default:
|
||||
c.Logger().Errorf("error querying for authenticated user: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue