2021-12-31 08:58:00 +00:00
|
|
|
package resolvers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/authorizerdev/authorizer/server/constants"
|
|
|
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
|
|
|
"github.com/authorizerdev/authorizer/server/utils"
|
|
|
|
)
|
|
|
|
|
2022-01-09 13:10:30 +00:00
|
|
|
func AdminSession(ctx context.Context) (*model.Response, error) {
|
2021-12-31 08:58:00 +00:00
|
|
|
gc, err := utils.GinContextFromContext(ctx)
|
2022-01-09 13:10:30 +00:00
|
|
|
var res *model.Response
|
2021-12-31 08:58:00 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if !utils.IsSuperAdmin(gc) {
|
|
|
|
return res, fmt.Errorf("unauthorized")
|
|
|
|
}
|
|
|
|
|
|
|
|
hashedKey, err := utils.HashPassword(constants.EnvData.ADMIN_SECRET)
|
|
|
|
if err != nil {
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
utils.SetAdminCookie(gc, hashedKey)
|
|
|
|
|
2022-01-09 13:10:30 +00:00
|
|
|
res = &model.Response{
|
2022-01-09 12:32:16 +00:00
|
|
|
Message: "admin logged in successfully",
|
2021-12-31 08:58:00 +00:00
|
|
|
}
|
|
|
|
return res, nil
|
|
|
|
}
|