mirror of https://github.com/go-sonic/sonic.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
601 B
Go
26 lines
601 B
Go
package impl
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/go-sonic/sonic/consts"
|
|
"github.com/go-sonic/sonic/model/entity"
|
|
"github.com/go-sonic/sonic/util/xerr"
|
|
)
|
|
|
|
func GetAuthorizedUser(ctx context.Context) (*entity.User, bool) {
|
|
user, ok := ctx.Value(consts.AuthorizedUser).(*entity.User)
|
|
if !ok {
|
|
return nil, false
|
|
}
|
|
return user, true
|
|
}
|
|
|
|
func MustGetAuthorizedUser(ctx context.Context) (*entity.User, error) {
|
|
user, ok := ctx.Value(consts.AuthorizedUser).(*entity.User)
|
|
if !ok || user == nil {
|
|
return nil, xerr.WithStatus(nil, xerr.StatusForbidden).WithMsg("Not logged in")
|
|
}
|
|
return user, nil
|
|
}
|